-
Notifications
You must be signed in to change notification settings - Fork 5
/
MODEstart.m
178 lines (155 loc) · 6.86 KB
/
MODEstart.m
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
function MODEstart(filename,pathname)
% Copyright 2014
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%% Overall Description
% This code implements a basic multi-objective optimization algorithm based
% on Diferential Evolution (DE) algorithm:
%
% Storn, R., Price, K., 1997. Differential evolution: A simple and
% efficient heuristic for global optimization over continuous spaces.
% Journal of Global Optimization 11, 341 – 359.
%
% When one objective is optimized, the standard DE runs; if two or more
% objectives are optimized, the greedy selection step in DE algorithm is
% performed using a dominance relation.
%%
if nargin()<2
manual_dataSet;
dataSet.currentpathname = [cd '\'];
dataSet.currentfilename = 'mot_0.fem';
[bounds, objs, geo, per, mat]=data0(dataSet);
dataSet.RQ = buildDefaultRQ(bounds);
else
if ~strcmp(filename(end-3),'.')
filename = [filename '.mat'];
end
if ~isequal(pathname(end),'\')
pathname=[pathname '\'];
end
load([pathname filename]);
dataSet = back_compatibility(dataSet,geo,per,1);
% If you want load an existing machine and perform an optimization,
% please write here the initialization of Optimization data (see
% section "Optimization data" in manual_dataSet.m or edit the dataSet
% of the existing machine.
end
clc
[bounds, objs, geo, per,mat] = data0(dataSet);
dat.geo0=geo;
dat.per=per;
dat.mat=mat;
save('dataSet','dataSet');
%%%%%%%%%% FEMM fitness handle %%%%%%%%%%%%%%%%%%%%%%%%%%
eval_type = 'MO_OA'; % you can choose between "MO_OA" and "MO_GA"
% "MO_GA" use multi-objective algorithm from matlab ga toolbox
% "MO_OA" use multi-objective de algorithm
FitnessFunction = @(x)FEMMfitness(x,geo,per,mat,eval_type);
FitnessFunction = @(x)FEMMfitness(x,geo,per,mat,eval_type);
% FitnessFunction = @(x)FEMMfitness(x,geo,per,eval_type);
%FitnessFunction = @(x)zdtTestFunctions(x,1);
%bounds = [zeros(10,1) ones(10,1)];
%bounds = [0 1;-5*ones(9,1) 5*ones(9,1)]; ZDT4
dat.CostProblem = FitnessFunction; % Cost function instance
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Variables regarding the optimization algorithm
% For guidelines for the parameter tuning see:
%
% Storn, R., Price, K., 1997. Differential evolution: A simple and
% efficient heuristic for global optimization over continuous spaces.
% Journal of Global Optimization 11, 341 – 359.
%
% Das, S., Suganthan, P. N., 2010. Differential evolution: A survey of the
% state-of-the-art. IEEE Transactions on Evolutionary Computation. Vol 15,
% 4 - 31.
NOBJ = sum(objs(:,2)); % Number of objectives
XPOP = dataSet.XPop; % Population size
Esc = 0.75; % Scaling factor
Pm= 0.2; % Croosover Probability
NVAR = size(bounds,1); % Number of decision variables
MAXGEN = dataSet.MaxGen; % Generation bound
MAXFUNEVALS = 20000*NVAR*NOBJ; % Function evaluations bound
%% Variables regarding the optimization problem
switch eval_type
case 'MO_OA'
dat.FieldD = bounds; % Initialization
dat.Initial = bounds; % Optimization bounds (see data0.m)
dat.NOBJ = NOBJ;
dat.NRES = 0; % Number of constraints
dat.NVAR = NVAR;
dat.mop = str2func('evaluateF'); % Cost function
dat.eval_type = eval_type;
dat.XPOP = XPOP;
dat.Esc = Esc;
dat.Pm = Pm;
dat.fl = 0.1;
dat.fu = 0.9;
dat.tau1= 0.1;
dat.tau2= 0.1;
dat.InitialPop=[]; % Initial population (if any)
dat.MAXGEN = MAXGEN;
dat.MAXFUNEVALS = MAXFUNEVALS;
dat.SaveResults='yes'; % Write 'yes' if you want to
% save your results after the
% optimization process;
% otherwise, write 'no';
% Initialization (don't modify)
dat.CounterGEN=0;
dat.CounterFES=0;
% Run the algorithm.
OUT=MODE2(dat,dataSet);
case 'MO_GA' %'MO_GA' use multi-objective algorithm from matlab ga toolbox
A = []; b = [];
Aeq = []; beq = [];
lb = bounds(:,1);
ub = bounds(:,2);
numberOfVariables = NVAR;
% Adding Visualization
options = gaoptimset('PlotFcns',@gaplotpareto);
%
options = gaoptimset(options,'DistanceMeasureFcn',{@distancecrowding,'genotype'});
options = gaoptimset(options,'ParetoFraction',0.4);
% popolazione
options = gaoptimset(options,'PopulationSize',XPOP);%200
%
options = gaoptimset(options,'PopInitRange',[lb';ub']);
options = gaoptimset(options,'TolFun',0.0001,'StallGenLimit',1000);
% generazioni
options = gaoptimset(options,'TimeLimit',MAXFUNEVALS,'Generations',MAXGEN); %100
options = gaoptimset(options,'UseParallel','always');
options = gaoptimset(options,'Display','diagnose');
% Run the algorithm.
[x,fval,exitFlag,output,population,scores] = gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
fprintf('The number of points on the Pareto front was: %d\n', size(x,1));
OUT.eval_type = eval_type;
OUT.PSet = x;
OUT.PFront = fval;
OUT.Xpop = population;
OUT.Jpop = scores;
OUT.Param = output;
% salvataggi
thisfilepath = fileparts(which('data0.m'));
filename=fullfile(thisfilepath,'results',['OUT_' datestr(now,30)]);
save(filename,'OUT','geo0','per');
saveas(gcf,filename);
Pareto_Fvals = OUT.PFront;
Pareto_front = OUT.PSet;
disp('PostProcessing of current optimization result...')
% evalParetoFront(filename,'data0.m')
end
%% matlabpool close
%
%% Release and bug report:
%
% November 2012: Initial release
% October 2016: Second release