-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateInitialEmpires.m
68 lines (44 loc) · 1.44 KB
/
CreateInitialEmpires.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
function emp=CreateInitialEmpires()
global ProblemSettings;
global ICASettings;
CostFunction=ProblemSettings.CostFunction;
nVar=ProblemSettings.nVar;
VarSize=ProblemSettings.VarSize;
VarMin=ProblemSettings.VarMin;
VarMax=ProblemSettings.VarMax;
nPop=ICASettings.nPop;
nEmp=ICASettings.nEmp;
nCol=nPop-nEmp;
alpha=ICASettings.alpha;
empty_country.Position=[];
empty_country.Cost=[];
country=repmat(empty_country,nPop,1);
for i=1:nPop
country(i).Position=unifrnd(VarMin,VarMax,VarSize);
country(i).Cost=CostFunction(country(i).Position);
end
costs=[country.Cost];
[~, SortOrder]=sort(costs);
country=country(SortOrder);
imp=country(1:nEmp);
col=country(nEmp+1:end);
empty_empire.Imp=[];
empty_empire.Col=repmat(empty_country,0,1);
empty_empire.nCol=0;
empty_empire.TotalCost=[];
emp=repmat(empty_empire,nEmp,1);
% Assign Imperialists
for k=1:nEmp
emp(k).Imp=imp(k);
end
% Assign Colonies
P=exp(-alpha*[imp.Cost]/max([imp.Cost]));
P=P/sum(P);
for j=1:nCol
k=RouletteWheelSelection(P);
emp(k).Col=[emp(k).Col
col(j)];
emp(k).nCol=emp(k).nCol+1;
end
emp=UpdateTotalCost(emp);
end