function [f_best_return,x_star_best_return,is_viable,neval] = ...
MGALT_MBH_function(BOD,CONST,OPT,OPT_algo,VAR,x0,num_mig,count_MBH,loop)
% FORM: [f_best_return,x_star_best_return,is_viable,neval] = ...
% MGALT_MBH_function(BOD,CONST,OPT,OPT_algo,VAR,x0,num_mig,count_MBH,loop)
%
% |-----------------------------------------------------------------------
% |
% | NOTES:
% | -This function is the actual implimentation of the MBH algorithm.
% | The algorithm had to be broken into a function because it would
% | not be feasible to fit into "MGALT_MBH" due to organization
% |
% | -A user who would like solutions where ALL of the transfer
% | trajectories are feasible needs to chenge the comment under
% | section 3.0 and 4.3 from "any(feasible)" to "all(feasible)". The
% | rational for having any was explained in the accompanying thesis,
% | as the randomness could potentially alows MBH to find a solution
% | where both transfers are considered feasible. As on now, it will
% | accept a solution where any transfer is feasible
% |
% |-----------------------------------------------------------------------
% |
% | INPUTS:
% | -BOD (1,1) [struct] [unitless]
% | A struct containing information pertaining to the planetary
% | bodies. Contains list of bodies, launch windows and ToF, and
% | planetary R/V/JD vectors. This struct has dynamic fields and
% | will adapt to contain only the necesary information
% | -CONST (1,1) [struct] [unitless]
% | A struct containing constants used in the calcs. Contains
% | values for AU, TU, Sun (rad/mu/rp) and (rad/mu/rp/SOI/per)
% | for any bodies used in the optimization scheme. This is a
% | dynamic struct and will adapt to contain only the necesary
% | information
% | -OPT (1,1) [struct] [unitless]
% | A struct containing constants user options. Contains the save
% | folder, ToF values, and more structs containing informaiton
% | for the island model, cost parameters, weighting parameters,
% | and all of the islands used in the optimization process
% | -OPT_algo (1,1) [struct] [unitless]
% | MBH option parameters. For a full explination of these
% | parameters, see
% | "Algorithms/Algorithm_Parameters/parametersMBH.m"
% | -VAR (1,1) [struct] [unitless]
% | A struct containing the variable limits
% | -x0 (1,Nvar) [float] [unitless]
% | The initial population which will be evaluated by the solver
% | -num_mig (1,1) [int] [unitless]
% | The current migration number
% | -count_MBH (1,1) [int] [unitless]
% | The current MBH island number
% | -loop (1,1) [int] [unitless]
% | The current loop number
% | This is if the function is solving an initial set of members
% | or a secondary set of members generated from MGALT_MBH_cluster
% |
% |-----------------------------------------------------------------------
% |
% | OUTPUTS:
% | -f_best (1,Nvar) [float] [unitless]
% | The respective cost of each member in 'x0'
% | -member_final (1,Nvar) [float] [unitless]
% | The new perturbed member consisting of the original member and
% | the perturbations added to it
% | -is_viable (1,1) [boolean] [unitless]
% | The new perturbed member consisting of the original member and
% | the perturbations added to it
% | -nfeval (1,1) [int] [unitless]
% | The current number of iterations for this MBH object
% |
% |-----------------------------------------------------------------------
% |
% | MISC:
% |
% |-----------------------------------------------------------------------
%% Initialize
% Number of iterations
num_iter_global = size(x0,1); % Number of iterations for the outer loop
% Preallocate Cost Parameters
f = zeros(num_iter_global,1);
f_best_return = zeros(num_iter_global,1);
x_star_best_return = zeros(num_iter_global,size(x0,2));
is_viable = zeros(num_iter_global,1);
% Perallocate the plot_vars struct. Need to run 1 execution to get field
% names
[~,vars] = feval(OPT.solver,x0(1,:),BOD,CONST,OPT,VAR);
name = fieldnames(vars);
for i0 = 1:length(name)
plot_vars(num_iter_global).(name{i0}) = [];
end
%% feval
if OPT.parallel
% Function Handle
fh = str2func(string(OPT.solver)); % https://www.mathworks.com/help/matlab/ref/str2func.html
% Display info
ll_par = fprintf('\n Parallel Processing \n');
ll_RAM = fprintf(2,' Watch CPU/RAM usage \n\n');
% Chunks to break parallel into to prevent a lot of RAM usage at once
chunk_nums = 1000; % Set by Malloy, uses ~2.0GB of RAM per pass
chunk_whole = floor(num_iter_global/chunk_nums);
chunk_rems = mod(num_iter_global,chunk_nums);
% Run through all searches minus mod
for chunk_iter = 1:chunk_whole
% Preallocate temp vars
f_temp = zeros(chunk_nums,1);
for i0 = 1:length(name)
plot_vars_temp(chunk_nums).(name{i0}) = [];
end
data_temp(1:chunk_nums) = parallel.FevalFuture;
% Display info
ll_loop1 = fprintf(' Search: %1.0f-%1.0f / %1.0f\n',((chunk_iter-1)*chunk_nums+1),(chunk_iter*chunk_nums),num_iter_global);
ll_loop2 = fprintf(' Search: %1.0f\n',(chunk_iter-1)*chunk_nums+1);
% Perform parfeval on chunk n
for chunk_num = 1:chunk_nums
% Search Display
fprintf(repmat('\b',1,ll_loop2))
ll_loop2 = fprintf(' Search: %1.0f\n',((chunk_iter-1)*chunk_nums)+chunk_num);
data_temp(chunk_num) = parfeval(OPT.ppool,fh,2,x0(((chunk_iter-1)*chunk_nums)+chunk_num,:),BOD,CONST,OPT,VAR);
end
fprintf(repmat('\b',1,ll_loop2))
% Collect results for chunk n
ll_collect = fprintf('\n ---Collecting results from parpool---\n');
for chunk_num = 1:chunk_nums
[index,cost,plt_vars] = fetchNext(data_temp);
f_temp(index) = cost;
plot_vars_temp(index) = plt_vars;
end
% Save the collected results into the total struct
f( ((chunk_iter-1)*chunk_nums+1):(chunk_iter*chunk_nums) ) = f_temp;
plot_vars( ((chunk_iter-1)*chunk_nums+1):(chunk_iter*chunk_nums) ) = plot_vars_temp;
% Clear display
fprintf(repmat('\b',1,ll_collect))
fprintf(repmat('\b',1,ll_loop1))
clear f_temp plot_vars_temp data_temp
end
% Run through all remaining values
if logical(chunk_rems)
% Preallocate temp vars
clear f_temp plot_vars_temp data_temp
f_temp = zeros(chunk_rems,1);
for i0 = 1:length(name)
plot_vars_temp(chunk_rems).(name{i0}) = [];
end
data_temp(1:chunk_rems) = parallel.FevalFuture;
% Display info
ll_loop1 = fprintf(' Search: %1.0f-%1.0f / %1.0f\n',(chunk_whole*chunk_nums+1),(chunk_whole*chunk_nums+chunk_rems),num_iter_global);
ll_loop2 = fprintf(' Search: %1.0f\n',(chunk_whole*chunk_nums+1));
% Perform parfeval on remainder
for chunk_rem = 1:chunk_rems
% Search Display
fprintf(repmat('\b',1,ll_loop2))
ll_loop2 = fprintf(' Search: %1.0f\n',(chunk_whole*chunk_nums+chunk_rem));
data_temp(chunk_rem) = parfeval(OPT.ppool,fh,2,x0((chunk_whole*chunk_nums+chunk_rem),:),BOD,CONST,OPT,VAR);
end
fprintf(repmat('\b',1,ll_loop2))
% Collect
没有合适的资源?快使用搜索试试~ 我知道了~
多重力辅助低推力(MGALT)版本的航天器轨道优化套件(STOpS)附matlab代码.zip
共155个文件
mat:136个
m:19个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 117 浏览量
2024-01-26
21:23:45
上传
评论
收藏 9.13MB ZIP 举报
温馨提示
1.程序语言为matlab,程序可出预测效果图,迭代优化图,相关分析图,运行环境matlab2020b及以上。 2.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 3.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 4.作者介绍:某大厂资深算法工程师,从事Matlab算法仿真工作10年;擅长智能优化算法、神经网络预测、信号处理、元胞自动机等多种领域的算法仿真实验,更多仿真源码、数据集定制私信+。
资源推荐
资源详情
资源评论
收起资源包目录
多重力辅助低推力(MGALT)版本的航天器轨道优化套件(STOpS)附matlab代码.zip (155个子文件)
MGALT_MBH_function.m 11KB
MGALT_DE_nextGeneration.m 11KB
MGALT_MBH_isFeasible.m 11KB
parametersGA.m 8KB
MGALT_GA_mating.m 7KB
parametersMBH.m 7KB
MGALT_GA_nextGeneration.m 7KB
MGALT_MBH.m 7KB
parametersDE.m 7KB
MGALT_DE.m 6KB
MGALT_PSO.m 6KB
MGALT_GA_selection.m 6KB
MGALT_GA.m 6KB
MGALT_MBH_basin.m 6KB
parametersPSO.m 5KB
MGALT_DE_Target.m 5KB
MGALT_MBH_randomize.m 4KB
MGALT_PSO_nextGeneration.m 4KB
MGALT_MBH_cluster.m 4KB
Mars_1972.mat 72KB
Mars_1980.mat 72KB
Mars_1976.mat 72KB
Mars_1982.mat 72KB
Mars_1978.mat 72KB
Mars_1974.mat 72KB
Mars_1971.mat 72KB
Mars_1983.mat 72KB
Mars_1977.mat 72KB
Mars_1979.mat 72KB
Mars_1975.mat 72KB
Mars_1981.mat 72KB
Mars_1973.mat 72KB
Mars_1970.mat 72KB
Jupiter_1988.mat 71KB
Jupiter_2000.mat 71KB
Jupiter_1976.mat 71KB
Jupiter_2012.mat 71KB
Jupiter_2024.mat 71KB
Jupiter_2006.mat 71KB
Jupiter_2018.mat 71KB
Jupiter_2030.mat 71KB
Jupiter_1994.mat 71KB
Jupiter_2003.mat 71KB
Jupiter_2015.mat 71KB
Jupiter_1982.mat 71KB
Jupiter_1991.mat 71KB
Earth_2004.mat 71KB
Earth_2028.mat 71KB
Earth_1984.mat 71KB
Jupiter_2027.mat 71KB
Jupiter_2021.mat 71KB
Jupiter_2009.mat 71KB
Earth_2025.mat 71KB
Earth_1996.mat 71KB
Earth_1992.mat 71KB
Earth_2020.mat 71KB
Earth_2024.mat 71KB
Earth_2026.mat 71KB
Jupiter_1979.mat 71KB
Jupiter_1971.mat 71KB
Earth_1972.mat 71KB
Earth_2007.mat 71KB
Earth_2014.mat 71KB
Jupiter_1997.mat 71KB
Earth_2029.mat 71KB
Earth_1976.mat 71KB
Earth_2021.mat 71KB
Earth_2030.mat 71KB
Earth_1974.mat 71KB
Earth_1978.mat 71KB
Earth_1975.mat 71KB
Earth_1970.mat 71KB
Earth_2027.mat 71KB
Earth_2017.mat 71KB
Earth_2016.mat 71KB
Earth_1973.mat 71KB
Earth_2000.mat 71KB
Earth_1971.mat 71KB
Earth_2018.mat 71KB
Earth_1977.mat 71KB
Earth_1985.mat 71KB
Jupiter_1970.mat 71KB
Jupiter_1974.mat 71KB
Earth_2022.mat 71KB
Earth_1980.mat 71KB
Earth_1991.mat 71KB
Earth_2023.mat 71KB
Jupiter_1985.mat 71KB
Earth_2012.mat 71KB
Earth_1979.mat 71KB
Earth_2005.mat 71KB
Earth_2001.mat 71KB
Earth_2006.mat 71KB
Earth_2019.mat 71KB
Earth_2015.mat 71KB
Earth_2008.mat 71KB
Earth_1993.mat 70KB
Earth_2013.mat 70KB
Earth_1983.mat 70KB
Earth_1988.mat 70KB
共 155 条
- 1
- 2
资源评论
matlab科研助手
- 粉丝: 1w+
- 资源: 1994
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功