From d76d93f4d1b41a65cb805a3aa579075472bd4151 Mon Sep 17 00:00:00 2001 From: micros-uav Date: Sat, 19 Aug 2023 21:07:21 +0800 Subject: [PATCH] update --- .../setting_parameters_1.m | 26 ------- .../setting_parameters_2.m | 26 ------- .../setting_parameters_3.m | 26 ------- .../setting_parameters_4.m | 26 ------- .../setting_parameters_5.m | 26 ------- .../setting_parameters_6.m | 26 ------- .../setting_parameters_7.m | 26 ------- .../setting_parameters_8.m | 26 ------- .../combine_modules/setting_parameters.m | 4 +- .../combine_modules/setting_parameters_1.m | 26 ------- .../combine_modules/setting_parameters_2.m | 26 ------- .../user_evaluation_module_average.m | 9 ++- .../user_evaluation_module_one.m | 9 ++- .../user_swarm_module_generate_desire.m | 9 ++- .../utils/read_parameter_xml.m | 68 ++++++++++++------- 15 files changed, 64 insertions(+), 295 deletions(-) delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_1.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_2.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_3.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_4.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_5.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_6.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_7.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_8.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters_1.m delete mode 100644 matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters_2.m diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_1.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_1.m deleted file mode 100644 index ae911cc..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_1.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_1() -%SETTING_PARAMETERS_1 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_2.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_2.m deleted file mode 100644 index af823be..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_2.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_2() -%SETTING_PARAMETERS_2 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_3.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_3.m deleted file mode 100644 index c19993d..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_3.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_3() -%SETTING_PARAMETERS_3 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_4.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_4.m deleted file mode 100644 index 33316fb..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_4.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_4() -%SETTING_PARAMETERS_4 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_5.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_5.m deleted file mode 100644 index 00dcf3d..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_5.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_5() -%SETTING_PARAMETERS_5 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_6.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_6.m deleted file mode 100644 index b510742..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_6.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_6() -%SETTING_PARAMETERS_6 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_7.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_7.m deleted file mode 100644 index 213af92..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_7.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_7() -%SETTING_PARAMETERS_7 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_8.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_8.m deleted file mode 100644 index 6d30d66..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/params_for_parallel/setting_parameters_8.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_8() -%SETTING_PARAMETERS_8 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters.m index 8cb095f..0c1e9a2 100644 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters.m +++ b/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters.m @@ -19,8 +19,8 @@ activate_save_states = 0.000000000000; time_interval_save = 1.000000000000; motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; +swarm_algorithm_type = ['u', 's', 'e', 'r', '_', 's', 'w', 'a', 'r', 'm']; +evaluation_metric_type = ['u', 's', 'e', 'r', '_', 'e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n']; end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters_1.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters_1.m deleted file mode 100644 index ae911cc..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters_1.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_1() -%SETTING_PARAMETERS_1 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters_2.m b/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters_2.m deleted file mode 100644 index af823be..0000000 --- a/matlab_simulink_ws/Prototype_Simulator/combine_modules/setting_parameters_2.m +++ /dev/null @@ -1,26 +0,0 @@ -function [number,... -time_max,... -sample_time_motion,... -sample_time_control_upper,... -sample_time_control_bottom,... -activate_save_states,... -time_interval_save,... -motion_model_type,... -swarm_algorithm_type,... -evaluation_metric_type] = setting_parameters_2() -%SETTING_PARAMETERS_2 -% Automatically generated by read_parameter_xml.m -% Every time read_parameter_xml.m is run, this function will be generated -number = 10.000000000000; -time_max = 100.000000000000; -sample_time_motion = 0.100000000000; -sample_time_control_upper = 0.100000000000; -sample_time_control_bottom = 0.100000000000; -activate_save_states = 0.000000000000; -time_interval_save = 1.000000000000; -motion_model_type = 0.000000000000; -swarm_algorithm_type = ['V', 'a', 's', 'a', 'r', 'h', 'e', 'l', 'y', 'i']; -evaluation_metric_type = ['e', 'v', 'a', 'l', 'u', 'a', 't', 'i', 'o', 'n', '_', '0']; - - -end \ No newline at end of file diff --git a/matlab_simulink_ws/Prototype_Simulator/lower_layers/evaluation_module/user_evaluation_module/user_evaluation_module_average.m b/matlab_simulink_ws/Prototype_Simulator/lower_layers/evaluation_module/user_evaluation_module/user_evaluation_module_average.m index 167bcb6..853a4fa 100644 --- a/matlab_simulink_ws/Prototype_Simulator/lower_layers/evaluation_module/user_evaluation_module/user_evaluation_module_average.m +++ b/matlab_simulink_ws/Prototype_Simulator/lower_layers/evaluation_module/user_evaluation_module/user_evaluation_module_average.m @@ -8,9 +8,12 @@ % get parameters by user_evaluation_module_parameters() % The following operations are for multi-core parallel computing. -file_name_param = 'user_evaluation_module_parameters'; -[~,str_core] = get_multi_core_value(); -fun_params = str2func([file_name_param, str_core]); +persistent fun_params +if isempty(fun_params) + file_name_param = 'user_evaluation_module_parameters'; + [~,str_core] = get_multi_core_value(); + fun_params = str2func(strcat(file_name_param,str_core)); +end [v_flock] = fun_params(); % diff --git a/matlab_simulink_ws/Prototype_Simulator/lower_layers/evaluation_module/user_evaluation_module/user_evaluation_module_one.m b/matlab_simulink_ws/Prototype_Simulator/lower_layers/evaluation_module/user_evaluation_module/user_evaluation_module_one.m index e231dd4..d70cfab 100644 --- a/matlab_simulink_ws/Prototype_Simulator/lower_layers/evaluation_module/user_evaluation_module/user_evaluation_module_one.m +++ b/matlab_simulink_ws/Prototype_Simulator/lower_layers/evaluation_module/user_evaluation_module/user_evaluation_module_one.m @@ -8,9 +8,12 @@ % get parameters by user_evaluation_module_parameters() % The following operations are for multi-core parallel computing. -file_name_param = 'user_evaluation_module_parameters'; -[~,str_core] = get_multi_core_value(); -fun_params = str2func([file_name_param, str_core]); +persistent fun_params +if isempty(fun_params) + file_name_param = 'user_evaluation_module_parameters'; + [~,str_core] = get_multi_core_value(); + fun_params = str2func([file_name_param,str_core]); +end [v_flock] = fun_params(); % diff --git a/matlab_simulink_ws/Prototype_Simulator/lower_layers/swarm_module/user_swarm_module/user_swarm_module_generate_desire.m b/matlab_simulink_ws/Prototype_Simulator/lower_layers/swarm_module/user_swarm_module/user_swarm_module_generate_desire.m index bc9180b..1b029f1 100644 --- a/matlab_simulink_ws/Prototype_Simulator/lower_layers/swarm_module/user_swarm_module/user_swarm_module_generate_desire.m +++ b/matlab_simulink_ws/Prototype_Simulator/lower_layers/swarm_module/user_swarm_module/user_swarm_module_generate_desire.m @@ -18,9 +18,12 @@ % get parameters by user_swarm_module_parameters() % The following operations are for multi-core parallel computing. -file_name_param = 'user_swarm_module_parameters'; -[~,str_core] = get_multi_core_value(); -fun_params = str2func([file_name_param, str_core]); +persistent fun_params +if isempty(fun_params) + file_name_param = 'user_swarm_module_parameters'; + [~,str_core] = get_multi_core_value(); + fun_params = str2func([file_name_param,str_core]); +end [r_com] = fun_params(); diff --git a/matlab_simulink_ws/Prototype_Simulator/utils/read_parameter_xml.m b/matlab_simulink_ws/Prototype_Simulator/utils/read_parameter_xml.m index 08f3416..28d9855 100644 --- a/matlab_simulink_ws/Prototype_Simulator/utils/read_parameter_xml.m +++ b/matlab_simulink_ws/Prototype_Simulator/utils/read_parameter_xml.m @@ -1,4 +1,4 @@ -function [map3d_faces, map3d_struct, model_stls, params, position0, param_simulink] = read_parameter_xml(file_name,ps_mofify) +function [map3d_faces, map3d_struct, model_stls, params, position0, param_simulink] = read_parameter_xml(file_name_xml,ps_mofify) %READ_PARAMETER_XML Summary of this function goes here % Detailed explanation goes here @@ -6,25 +6,20 @@ % if nargin < 1 - file_name = "parameters.xml"; + file_name_xml = "parameters.xml"; ps_mofify = struct("param_name_s",[],"param_value_s",[]); elseif nargin < 2 ps_mofify = struct("param_name_s",[],"param_value_s",[]); end -if isempty(file_name) - file_name = "parameters.xml"; +if isempty(file_name_xml) + file_name_xml = "parameters.xml"; end -% Get the creation time of the xml file -xml_file = dir(file_name); -ctime_xml = datenum(xml_file.date); -% - % translate xml to struct % first_name = "CoFlyers"; -param_xml = parseXML(file_name); +param_xml = parseXML(file_name_xml); [CoFlyers, param_string] = parseXML2(param_xml, first_name); % modify params @@ -99,7 +94,7 @@ end end % error("xml error"); - error(strcat("%s file error.\n",str_error),file_name); + error(strcat("%s file error.\n",str_error),file_name_xml); end %%% @@ -123,18 +118,30 @@ temp = fieldnames(CoFlyers.map); CoFlyers.map = rmfield(CoFlyers.map,temp(ind_models)); [map3d_faces, map3d_struct] = generate_map3d_from_struct(map3d_struct_0, model_stls); - init_map = true; +% init_map = true; end % CoFlyers = rmfield(CoFlyers, "map"); position0 = CoFlyers.position__; CoFlyers = rmfield(CoFlyers, "position__"); param_simulink = CoFlyers.simulink; CoFlyers = rmfield(CoFlyers, "simulink"); - - %========================Remove XXX__ params================%%% CoFlyers = remove_XXX__(CoFlyers); params = CoFlyers; + +%% +% Get the creation time of the xml file +xml_file = dir(file_name_xml); +ctime_xml = datenum(xml_file.date); +% Get the creation time of the "setting_parameters.m" file +oth_file = dir("combine_modules/setting_parameters.m"); +ctime_oth = datenum(oth_file.date); +if ctime_xml < ctime_oth && isempty(ps_mofify.param_name_s) + disp('The XML file has not been changed, so the module files will not be updated. (read_parameter_xml.m)'); + return +end + +%% %%%======================Write params to file=================%%% %%% path_here = mfilename('fullpath'); @@ -193,6 +200,7 @@ ind_subswarm = cellfun(@(x)isstruct(CoFlyers.swarm.(x)),field_names_swarm); field_names_swarm = field_names_swarm(ind_subswarm); write_swarm_module_generate_desire(dir_name_sm, file_name_sm, field_names_swarm, ctime_xml); +clear(strcat(file_name_sm,".m")); %%% Write each function of subswarm model %%% for ii = 1:length(field_names_swarm) dir_name_ssm = strcat(path_here,"../lower_layers/swarm_module/",... @@ -200,6 +208,7 @@ file_name_ssm = strcat(field_names_swarm{ii},"_module_generate_desire"); [values, values_name] = get_values_and_names(CoFlyers.('swarm').(field_names_swarm{ii})); write_subswarm_for_file(dir_name_ssm, file_name_ssm, field_names_swarm{ii}, values, values_name); + clear(strcat(file_name_ssm,".m")); end %% Write evaluation module %%% Write evaluation_module_one.m %%% @@ -209,7 +218,7 @@ ind_subeva = cellfun(@(x)isstruct(CoFlyers.evaluation.(x)),field_names_eva); field_names_eva = field_names_eva(ind_subeva); write_evaluation_module_one(dir_name_em, file_name_em, field_names_eva, ctime_xml); - +clear(strcat(file_name_em,".m")); %%% %%% dir_name_em = strcat(path_here,"../lower_layers/evaluation_module"); file_name_em = "evaluation_module_average"; @@ -225,9 +234,11 @@ file_name_sem = strcat(field_names_eva{ii},"_module_one"); [values, values_name] = get_values_and_names(CoFlyers.('evaluation').(field_names_eva{ii})); write_subevaluation_one_for_file(dir_name_sem, file_name_sem, field_names_eva{ii}, values, values_name); + clear(strcat(file_name_sem,".m")); file_name_sem = strcat(field_names_eva{ii},"_module_average"); [values, values_name] = get_values_and_names(CoFlyers.('evaluation').(field_names_eva{ii})); write_subevaluation_average_for_file(dir_name_sem, file_name_sem, field_names_eva{ii}, values, values_name); + clear(strcat(file_name_sem,".m")); end @@ -495,9 +506,12 @@ function write_subswarm_for_file(dir_name, file_name, subswarm_name, values, val fprintf(file_id,'%% get parameters by %s_module_parameters()\n',subswarm_name); fprintf(file_id,'\n'); fprintf(file_id,'%% The following operations are for multi-core parallel computing.\n'); - fprintf(file_id,'file_name_param = "%s_module_parameters";\n',subswarm_name); - fprintf(file_id,'[~,str_core] = get_multi_core_value();\n'); - fprintf(file_id,'fun_params = str2func(strcat(file_name_param,str_core));\n'); + fprintf(file_id,'persistent fun_params\n'); + fprintf(file_id,'if isempty(fun_params)\n'); + fprintf(file_id,"\tfile_name_param = '%s_module_parameters';\n",subswarm_name); + fprintf(file_id,'\t[~,str_core] = get_multi_core_value();\n'); + fprintf(file_id,'\tfun_params = str2func([file_name_param,str_core]);\n'); + fprintf(file_id,'end\n'); fprintf(file_id,'\n'); fprintf(file_id,'['); for i = 1:length(values_name) @@ -625,9 +639,12 @@ function write_subevaluation_one_for_file(dir_name, file_name, subeva_name, valu fprintf(file_id,'%% get parameters by %s_module_parameters()\n',subeva_name); fprintf(file_id,'\n'); fprintf(file_id,'%% The following operations are for multi-core parallel computing.\n'); - fprintf(file_id,'file_name_param = "%s_module_parameters";\n',subeva_name); - fprintf(file_id,'[~,str_core] = get_multi_core_value();\n'); - fprintf(file_id,'fun_params = str2func(strcat(file_name_param,str_core));\n'); + fprintf(file_id,'persistent fun_params\n'); + fprintf(file_id,'if isempty(fun_params)\n'); + fprintf(file_id,"\tfile_name_param = '%s_module_parameters';\n",subeva_name); + fprintf(file_id,'\t[~,str_core] = get_multi_core_value();\n'); + fprintf(file_id,'\tfun_params = str2func([file_name_param,str_core]);\n'); + fprintf(file_id,'end\n'); fprintf(file_id,'['); for i = 1:length(values_name) fprintf(file_id,'%s', values_name(i)); @@ -670,9 +687,12 @@ function write_subevaluation_average_for_file(dir_name, file_name, subeva_name, fprintf(file_id,'%% get parameters by %s_module_parameters()\n',subeva_name); fprintf(file_id,'\n'); fprintf(file_id,'%% The following operations are for multi-core parallel computing.\n'); - fprintf(file_id,'file_name_param = "%s_module_parameters";\n',subeva_name); - fprintf(file_id,'[~,str_core] = get_multi_core_value();\n'); - fprintf(file_id,'fun_params = str2func(strcat(file_name_param,str_core));\n'); + fprintf(file_id,'persistent fun_params\n'); + fprintf(file_id,'if isempty(fun_params)\n'); + fprintf(file_id,"\tfile_name_param = '%s_module_parameters';\n",subeva_name); + fprintf(file_id,'\t[~,str_core] = get_multi_core_value();\n'); + fprintf(file_id,'\tfun_params = str2func(strcat(file_name_param,str_core));\n'); + fprintf(file_id,'end\n'); fprintf(file_id,'['); for i = 1:length(values_name) fprintf(file_id,'%s', values_name(i));