-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCodeMode.m
More file actions
164 lines (162 loc) · 8.71 KB
/
Copy pathCodeMode.m
File metadata and controls
164 lines (162 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
%*********************************EDOLAB ver 2.00*********************************
%
% Authors: Mai Peng and Danial Yazdani
% e-mails: pengmai1998@gmail.com
% danial.yazdani@gmail.com
% Last Edited: Nov 22, 2025
%
% ------------
% Reference:
% ------------
%
% Title: "EDOLAB: An Open-Source Platform for Education and Experimentation with Evolutionary Dynamic Optimization Algorithms"
% ArXiv: arxiv.org/abs/2308.12644
% Note: reference information will be completed after acceptance of the paper
%
% ------------
% Notification:
% ------------
%
% This function is used to run EDOLAB without GUI
%
% --------
% License:
% --------
% This program is to be used under the terms of the GNU General Public License
% (http://www.gnu.org/copyleft/gpl.html).
% e-mail: danial DOT yazdani AT gmail DOT com
% Copyright notice: (c) 2023 Danial Yazdani
%*********************************************************************************
clear all;close all;clc;
%% Add the full path of EDOLAB folder and its subfolders into MATLAB's work space
nowPath = mfilename('fullpath');
projectPath = nowPath(1:max(strfind(nowPath,'\'))-1);
allPaths = genpath(projectPath);
pathsToAdd = regexprep(allPaths, '[^;]*OctaveVersion[^;]*;?', '');
addpath(pathsToAdd);
%% ********Selecting Algorithm & Benchmark********
AlgorithmName = 'ACFPSO'; %Please input the name of algorithm (EADO) you want to run here (names are case sensitive).
% The list of algorithms (EADOs) and some of their details can be found in Table 1 of the EDOLAB's paper.
% The current version of EDOLAB includes the following algorithms (EADOs):
% 'ACFPSO' , 'AMPDE' , 'AMPPSO' , 'AmQSO' , 'AMSO' , 'CDE' , 'CESO', 'CPSO' , 'CPSOR'
% 'DSPSO' , 'DynDE' , 'DynPopDE' , 'FTMPSO' , 'HmSO' , 'IDSPSO' , 'ImQSO' , 'mCMAES'
% 'mDE' , 'mjDE' , 'mPSO' , 'mQSO' , 'psfNBC' , 'RPSO' , 'SPSO_AP_AD' ,
% 'TMIPSO', 'DPCPSO', 'APCPSO'
BenchmarkName = 'GMPB'; %Please input the name of benchmark you want to use here (names are case sensitive).
% The current version of EDOLAB includes the following benchmark generators: 'MPB' , 'GDBG' , 'GMPB' , 'FPs'
%% Get the algorithm and benchmark lists
AlgorithmsFloder = dir([projectPath,'\Algorithm']);
AlgorithmsList = repmat("",length(AlgorithmsFloder)-2,1);
for i = 3:length(AlgorithmsFloder)
AlgorithmsList(i-2,1) = AlgorithmsFloder(i).name;
end
BenchmarksFloder = dir([projectPath,'\Benchmark']);
BenchmarksList = repmat("",length(BenchmarksFloder)-5,1);
BenchmarksCount = 0;
for i = 3:length(BenchmarksFloder)
if(isempty(strfind(BenchmarksFloder(i).name,'.m')))
BenchmarksCount = BenchmarksCount + 1;
BenchmarksList(BenchmarksCount,1) = BenchmarksFloder(i).name;
end
end
if(~ismember(AlgorithmName,AlgorithmsList))
error("No Such Algorithm in EDOLAB");
elseif(~ismember(BenchmarkName,BenchmarksList))
error("No Such Benchmark in EDOLAB");
end
%% ********Algorithm parameters, Benchmark parameters and Run number********
% Configuration workflow (for Code Mode users):
% 1) Default parameter definitions (do not require JSON):
% - Algorithm settings: Algorithm/<AlgorithmName>/getAlgConfigurableParameters_<AlgorithmName>.m
% - Problem settings: Benchmark/<BenchmarkName>/getProConfigurableParameters_<BenchmarkName>.m
% In these files, all configurable parameters are defined as:
% ConfigurableParameters.<ParamName>.value
%
% To discover available parameter names, either:
% - Open the corresponding getAlgConfigurableParameters_*.m / getProConfigurableParameters_*.m
% files and inspect the fields of ConfigurableParameters; or
% - In MATLAB Command Window, run:
% tmpAlg = getAlgConfigurableParameters(AlgorithmName);
% fieldnames(tmpAlg)
% tmpPro = getProConfigurableParameters(BenchmarkName);
% fieldnames(tmpPro)
% then use these field names below.
%
% 2) Quick override in CodeMode.m (for fast experiments):
% First load the default configuration:
ConfigurableAlgParameters = getAlgConfigurableParameters(AlgorithmName);
ConfigurableProParameters = getProConfigurableParameters(BenchmarkName);
% Then optionally override any parameter *for this run only* by assigning:
% ConfigurableAlgParameters.<ParamName>.value = <new value>;
% ConfigurableProParameters.<ParamName>.value = <new value>;
% For example (uncomment and adjust as needed):
% % Algorithm (ACFPSO) example:
% % ConfigurableAlgParameters.PopulationSize.value = 20;
% % ConfigurableAlgParameters.c1.value = 1.8;
% % ConfigurableAlgParameters.c2.value = 1.6;
% %
% % Benchmark (GMPB) example:
% % ConfigurableProParameters.Dimension.value = 10;
% % ConfigurableProParameters.ChangeFrequency.value = 2000;
% % ConfigurableProParameters.PeakNumber.value = 5;
%
% Changes here do not modify GUI or JSON files; they only affect the current CodeMode run.
Dimension = ConfigurableProParameters.Dimension.value;
RunNumber = 1; %It should be set to 31 in Experimentation module, and must be set to 2 for using Education module.
%% ********Figures and Outputs********
GeneratingExcelFile = 1; %Set to 1 (only for using the Experimentation module) to save the output statistics in an Excel file (in the Results folder), 0 otherwise.
OutputFig = 1; %Set to 1 (only for using the Experimentation module) to draw offline error over time and current error plot, 0 otherwise.
VisualizationOverOptimization = 0; %Set to 1 for using the Education module, 0 otherwise. This must be set to 0 if the user intends to use the Experimentation module.
%If VisualizationOverOptimization is set to 1, it means that EDOLAB enters its Education module.
%To enter the Education module, RunNumber must be set to 1, Dimension must be set to 2, and no excel file or output figure is generated.
%If the user does not intend to use the Education module, she or he must set VisualizationOverOptimization to 0.
%EDOLAB changes the aforementioned parameters based on the requirements of the Education module if VisualizationOverOptimization is set to 1.
if VisualizationOverOptimization==1%Forcing the right values for the following parameters when using the Education module.
if Dimension~=2 || RunNumber~=1 || GeneratingExcelFile~=0 || OutputFig~= 0
warning('By setting VisualizationOverOptimization to 1, you have chosen to use the Education module of EDOLAB; therefore, run number and dimension are set to 1 and 2, respectively. The output figure and Excel file are disabled.');
end
ConfigurableProParameters.Dimension.value = 2;
RunNumber = 1;
GeneratingExcelFile = 0;
OutputFig = 0;
end
%% Running the chosen algorithm (EDOA) on the chosen benchmark
main_EDO = str2func(['main_',AlgorithmName]);
ProgressInfo = struct('IsParallel', false);
[Problem,Results,CurrentError,VisualizationInfo,Iteration] = main_EDO(VisualizationOverOptimization, RunNumber, BenchmarkName, ConfigurableProParameters, ConfigurableAlgParameters, ProgressInfo);
%% Output
close;clc;
fields = fieldnames(Results);
for i = 1:numel(fields)
name = fields{i};
if strcmp(name, 'T_r')
continue; % Runtime is reported separately below
end
info = Results.(name);
if isfield(info, 'mean') && isfield(info, 'median') && isfield(info, 'StdErr')
disp([name, ' ==> Mean = ', num2str(info.mean), ', Median = ', num2str(info.median), ', Standard Error = ', num2str(info.StdErr)]);
end
end
% Runtime report (not used as a comparison indicator)
if isfield(Results, 'T_r')
T_r = Results.T_r;
disp('Runtime (T_r):');
disp([' Mean = ', num2str(T_r.mean)]);
disp([' Median = ', num2str(T_r.median)]);
disp([' StdErr = ', num2str(T_r.StdErr)]);
if isfield(T_r, 'AllResults')
disp([' All runs (s): ', num2str(T_r.AllResults)]);
end
end
% Generating an Excel file containing output statistics (only for the Experimentation module)
if GeneratingExcelFile==1
OutputDetailResultsToExcel(AlgorithmName, ConfigurableAlgParameters, BenchmarkName, ConfigurableProParameters, Results, [projectPath,'\Results\TaskDetailResults']);
end
% Generating an output figure containing offline error and current error plots (only for the Experimentation module)
if OutputFig==1
OutputPlot(CurrentError,RunNumber,Results.E_o,Results.E_bbc,AlgorithmName);
end
% Generating over-time figures for Education module
if (VisualizationOverOptimization==1)
OutputEducationalFigures(Iteration,ConfigurableProParameters.PeakNumber.value,VisualizationInfo,CurrentError,Problem);
end