-
Notifications
You must be signed in to change notification settings - Fork 1
/
C1.m
136 lines (105 loc) · 3.37 KB
/
C1.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
% AAA1 stands for IWO_MUX 2:1
clc;
clear;
%close all;
%% Problem Definition
VarMin=0.2; % Lower Bound of Decision Variables
VarMax=2; % Upper Bound of Decision Variables
%nVar=4; % Number of Decision Variables
nVar=4;
VarSize=[1 nVar]; % Decision Variables Matrix
VarRange=[VarMin VarMax]; % Range of Decision Variables
%% IWO Parameter
MaxIt=10; % Maximum Number of Iterations
% Nweed== No
No= 2; % ( Number of initial population )
%50
Pmax=4; % Maximum number of weed population
%100
Smin=1; % Minimum Number of Seeds
Smax=10; % Maximum Number of Seeds
n=3; % Nonlinear modulation index
Initialsigma=0.3; % Initial value of standard deviation
Finalsigma=0.001; % Final value of standard deviation
%% Initialization
NFE=0;
individual.Position=[];
individual.Cost=[];
pop=repmat(individual,No,1);
for i=1:No
pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
pop(i).Cost=C2(pop(i).Position);
end
% Sort Population
Costs=[pop.Cost];
[Costs SortOrder]=sort(Costs);
pop=pop(SortOrder);
BestSol=[];
WorstCost=zeros(MaxIt+1,1);
BestCost=zeros(MaxIt+1,1);
MeanCost=zeros(MaxIt+1,1);
Sigma=zeros(MaxIt,1);
WorstCost(1)=Costs(end);
BestCost(1)=Costs(1);
nfe=zeros(MaxIt,1);
%% IWO Main Loop
for it=1:MaxIt
%Number Of seeds for each weed
Costs=[pop.Cost];
S=min(Smax,round(Smax-(Smax-Smin)*(Costs-BestCost(it))/(WorstCost(it)-BestCost(it))));
%Iteration Sigma
Sigma(it)=((((MaxIt-it)^n)/((MaxIt-1)^n))*(Initialsigma-Finalsigma))+Finalsigma;
%Reproduction
Ns=sum(S);
pop2=repmat(individual,Ns,1);
Positions=[pop.Position];
Solution=zeros(1,nVar);
number=1;
for b=1:No
for c=1:S(b)
for d=1:nVar
Seed=normrnd(pop(b).Position(d),(Sigma(it))^2);
while (Seed>VarMax) || (Seed<VarMin)
if Seed>VarMax
Seed=Seed-(Seed-VarMax);
end
if Seed<VarMin
Seed=Seed+(VarMin-Seed);
end
end
Solution(d)=Seed;
end
pop2(number).Position=Solution;
pop2(number).Cost=C2(pop2(number).Position);
number=number+1;
end
end
% Merge Populations
pop=[pop
pop2]; %#ok
% Sort Population
Costs=[pop.Cost];
[Costs SortOrder]=sort(Costs);
pop=pop(SortOrder);
% Delete Extra Individuals
pop=pop(1:Pmax);
Costs=Costs(1:Pmax);
% Save Results
BestSol=pop(1);
BestCost(it+1)=Costs(1);
WorstCost(it+1)=Costs(end);
MeanCost(it)=mean(Costs);
nfe(it)=NFE;
% Show Information
disp(['Iteration ' num2str(it) ': ' ...
'Best Cost = ' num2str(BestCost(it)) ' , ' ...
'Mean Cost = ' num2str(MeanCost(it))]);
end
%% Results
%figure;
hold on;
%plot(BestCost(1:10),'LineWidth',2);
plot(BestCost,'g','LineWidth',2);
% semilogy(BestCost,'LineWidth',2);
%xlabel('Iteration');
%ylabel('Best Fitness = Best Average Power');