-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestBase.py
158 lines (126 loc) · 8.47 KB
/
TestBase.py
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
import numpy as np
import NSGAII
import Solution as sl
import SPEAII
import NSPSO
import Problem
import ParetoUtil as pu
import NSPSOMM
import JmetalIndicators as ind
import TestUtil as tu
def main():
problemlist = [Problem.UF1(),Problem.UF2(),Problem.UF3(),Problem.UF4(), Problem.ZDT1(), Problem.ZDT2(), Problem.ZDT3(), Problem.ZDT4()]
populationSizelist = [12, 40, 60, 100, 1000]
generationCountlist = [50, 100, 500, 1000]
mutationRate = 0.2
corssoverRate = 0.7
initSolution = None
markerAlpha = .3
# Resultplot("",True,problem,initSolution)
for populationSize in populationSizelist:
for generationCount in generationCountlist:
for problem in problemlist:
locations = []
locationsinDecision = []
Fitness = []
GD = []
IGD = []
EI = []
HV = []
Delta = []
locations.append((problem.perfect_pareto_front(),"","-","",1))
prefectFront = problem.perfect_pareto_front()
FitnessInd = ind.FitnessValue(prefectFront)
GDInd = ind.GenerationalDistance(prefectFront)
IGDInd= ind.InvertedGenerationalDistance(prefectFront)
EIInd= ind.EpsilonIndicator(prefectFront)
HVInd= ind.HyperVolume(reference_point=[1, 1])
plotTitle = "Population Size %d, Generation Count %d, Function %s" % (
populationSize,
generationCount,
type(problem).__name__,
)
initSolution = sl.solution.CreatePopulation(populationSize, problem)
temp = SPEAII.SPEAII(
problem, popSize=populationSize, eliteSize=populationSize).Evolve(
generationCount, initSolution, mutationRate, corssoverRate,False,FitnessInd, GDInd, IGDInd,EIInd, HVInd)
locations.append((pu.GetPopulationLocations(temp[0]),"SPEAII","","1",markerAlpha))
locationsinDecision.append((pu.GetPopulationDecisionLocations(temp[0]),"SPEAII","","1",markerAlpha))
Fitness.append((temp[1][:,[0,1]],"SPEAII","-","",markerAlpha))
GD.append((temp[1][:,[0,2]],"SPEAII","-","",markerAlpha))
IGD.append((temp[1][:,[0,3]],"SPEAII","-","",markerAlpha))
EI.append((temp[1][:,[0,4]],"SPEAII","-","",markerAlpha))
HV.append((temp[1][:,[0,5]],"SPEAII","-","",markerAlpha))
Delta.append((temp[1][:,[0,6]],"SPEAII","-","",markerAlpha))
temp = SPEAII.SPEAII(
problem, popSize=populationSize, eliteSize=populationSize).Evolve(
generationCount, initSolution, mutationRate, corssoverRate,True,FitnessInd, GDInd, IGDInd,EIInd, HVInd)
locations.append((pu.GetPopulationLocations(temp[0]),"SPEAII-MM","","2",markerAlpha))
locationsinDecision.append((pu.GetPopulationDecisionLocations(temp[0]),"SPEAII-MM","","1",markerAlpha))
Fitness.append((temp[1][:,[0,1]],"SPEAII-MM","-","",markerAlpha))
GD.append((temp[1][:,[0,2]],"SPEAII-MM","-","",markerAlpha))
IGD.append((temp[1][:,[0,3]],"SPEAII-MM","-","",markerAlpha))
EI.append((temp[1][:,[0,4]],"SPEAII-MM","-","",markerAlpha))
HV.append((temp[1][:,[0,5]],"SPEAII-MM","-","",markerAlpha))
Delta.append((temp[1][:,[0,6]],"SPEAII-MM","-","",markerAlpha))
temp = NSGAII.NSGAII(
problem, popSize=populationSize).Evolve(
generationCount, initSolution, mutationRate, corssoverRate,False,FitnessInd, GDInd, IGDInd,EIInd, HVInd)
locations.append((pu.GetPopulationLocations(temp[0]),"NSGAII","","x",markerAlpha))
locationsinDecision.append((pu.GetPopulationDecisionLocations(temp[0]),"NSGAII","","1",markerAlpha))
Fitness.append((temp[1][:,[0,1]],"NSGAII","-","",markerAlpha))
GD.append((temp[1][:,[0,2]],"NSGAII","-","",markerAlpha))
IGD.append((temp[1][:,[0,3]],"NSGAII","-","",markerAlpha))
EI.append((temp[1][:,[0,4]],"NSGAII","-","",markerAlpha))
HV.append((temp[1][:,[0,5]],"NSGAII","-","",markerAlpha))
Delta.append((temp[1][:,[0,6]],"NSGAII","-","",markerAlpha))
temp = NSGAII.NSGAII(
problem, popSize=populationSize).Evolve(
generationCount, initSolution, mutationRate, corssoverRate,True,FitnessInd, GDInd, IGDInd,EIInd, HVInd)
locations.append((pu.GetPopulationLocations(temp[0]),"NSGAII-MM","",".",markerAlpha))
locationsinDecision.append((pu.GetPopulationDecisionLocations(temp[0]),"NSGAII-MM","","1",markerAlpha))
Fitness.append((temp[1][:,[0,1]],"NSGAII-MM","-","",markerAlpha))
GD.append((temp[1][:,[0,2]],"NSGAII-MM","-","",markerAlpha))
IGD.append((temp[1][:,[0,3]],"NSGAII-MM","-","",markerAlpha))
EI.append((temp[1][:,[0,4]],"NSGAII-MM","-","",markerAlpha))
HV.append((temp[1][:,[0,5]],"NSGAII-MM","-","",markerAlpha))
Delta.append((temp[1][:,[0,6]],"NSGAII-MM","-","",markerAlpha))
temp = NSPSO.NSPSO(
problem, popSize=populationSize
).Evolve(generationCount, initSolution,FitnessInd, GDInd, IGDInd,EIInd, HVInd)
locations.append((pu.GetPopulationLocations(temp[0]),"NSPSO","",".",markerAlpha))
locationsinDecision.append((pu.GetPopulationDecisionLocations(temp[0]),"NSPSO","","1",markerAlpha))
Fitness.append((temp[1][:,[0,1]],"NSPSO","-","",markerAlpha))
GD.append((temp[1][:,[0,2]],"NSPSO","-","",markerAlpha))
IGD.append((temp[1][:,[0,3]],"NSPSO","-","",markerAlpha))
EI.append((temp[1][:,[0,4]],"NSPSO","-","",markerAlpha))
HV.append((temp[1][:,[0,5]],"NSPSO","-","",markerAlpha))
Delta.append((temp[1][:,[0,6]],"NSPSO","-","",markerAlpha))
temp = NSPSOMM.NSPSOMM(
problem, popSize=populationSize
).Evolve(generationCount, initSolution,FitnessInd, GDInd, IGDInd,EIInd, HVInd)
locations.append((pu.GetPopulationLocations(temp[0]),"NSPSO-MM","","*",markerAlpha))
locationsinDecision.append((pu.GetPopulationDecisionLocations(temp[0]),"NSPSO-MM","","1",markerAlpha))
Fitness.append((temp[1][:,[0,1]],"NSPSO-MM","-","",markerAlpha))
GD.append((temp[1][:,[0,2]],"NSPSO-MM","-","",markerAlpha))
IGD.append((temp[1][:,[0,3]],"NSPSO-MM","-","",markerAlpha))
EI.append((temp[1][:,[0,4]],"NSPSO-MM","-","",markerAlpha))
HV.append((temp[1][:,[0,5]],"NSPSO-MM","-","",markerAlpha))
Delta.append((temp[1][:,[0,6]],"NSPSO-MM","-","",markerAlpha))
tu.saveAsText(plotTitle,FitnessInd.get_short_name(),Fitness)
tu.saveAsText(plotTitle,GDInd.get_short_name(),GD)
tu.saveAsText(plotTitle,IGDInd.get_short_name(),IGD)
tu.saveAsText(plotTitle,EIInd.get_short_name(),EI)
tu.saveAsText(plotTitle,HVInd.get_short_name(),HV)
tu.saveAsText(plotTitle,"Delta",Delta)
tu.saveAsText(plotTitle,"Locations",locations)
tu.saveAsText(plotTitle,"LocationsInDecision",locationsinDecision)
tu.Resultplot(plotTitle + " " + FitnessInd.get_short_name() , False, Fitness)
tu.Resultplot(plotTitle + " " + GDInd.get_short_name() , False, GD)
tu.Resultplot(plotTitle + " " + IGDInd.get_short_name() , False, IGD)
tu.Resultplot(plotTitle + " " + EIInd.get_short_name() , False, EI)
tu.Resultplot(plotTitle + " " + HVInd.get_short_name() , False, HV)
tu.Resultplot(plotTitle + " " + "Delta" , False, Delta)
tu.Resultplot(plotTitle, False, locations)
if __name__ == "__main__":
main()