-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathAlgorithm.py
168 lines (137 loc) · 5.65 KB
/
PathAlgorithm.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
159
160
161
162
163
164
165
166
167
168
from typing import Any
from PathSampling import *
from PathMutation import *
from PathCrossover import *
from PathRepair import PathRepair
from pymoo.core.repair import NoRepair
from PathProblem import *
from pymoo.operators.crossover.nox import NoCrossover
from PathCrossover import PathCrossover
# from pymoo.operators.crossover. import pmx
from pymoo.operators.mutation.nom import NoMutation
from PathMutation import PathMutation
from pymoo.core.duplicate import NoDuplicateElimination
from PathDuplicateElimination import PathDuplicateElimination
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.algorithms.moo.ctaea import CTAEA
from pymoo.util.ref_dirs import get_reference_directions
from pymoo.constraints.as_obj import ConstraintsAsObjective
from pymoo.algorithms.moo.moead import MOEAD
from pymoo.constraints.eps import AdaptiveEpsilonConstraintHandling
from pymoo.algorithms.moo.nsga3 import NSGA3
from pymoo.algorithms.moo.unsga3 import UNSGA3
# from pymoo.algorithms.moo.age import AGEMOEA
from pymoo.algorithms.moo.sms import SMSEMOA
from pymoo.algorithms.soo.nonconvex.ga import GA
from pymoo.algorithms.soo.nonconvex.pso import PSO
# from pymoo.termination.default import PathTermination
from PathOptimizationModel import *
from PathInput import *
from main import scenario, pop_size, path_eliminate_duplicates, path_sampling, path_mutation, path_crossover, path_repair
# path_eliminate_duplicates = NoDuplicateElimination()
# pop_size = pop_size
# path_sampling = PathSampling()
# path_mutation = PathMutation()
# path_crossover = PathCrossover()
# path_repair = PathRepair()
# path_termination = PathTermination(
# # xtol=1e-8,
# # cvtol=0, # 1e-6,
# ftol=0.01, #0.0025,
# # period=30,
# # n_max_gen=10000,
# # n_max_evals=100000
# )
# pop_size = 100
algorithm_dict = {
'PSO': PSO(
pop_size=pop_size,
sampling=path_sampling,
# mutation=path_mutation,
# crossover=path_crossover,
# eliminate_duplicates=path_eliminate_duplicates,
# repair=path_repair
),
'GA': GA(
pop_size=pop_size,
sampling=path_sampling,
mutation=path_mutation,
crossover=path_crossover,
eliminate_duplicates=path_eliminate_duplicates,
repair=path_repair
),
'NSGA2' : NSGA2(
pop_size=pop_size,
sampling=path_sampling,
mutation=path_mutation,
crossover=path_crossover,
eliminate_duplicates=path_eliminate_duplicates,
repair=path_repair,
),
'MOEAD' : MOEAD(
ref_dirs=get_reference_directions("das-dennis", len(model['F']), n_partitions=12),
# pop_size=len(get_reference_directions("das-dennis", len(model['F']), n_partitions=12)),
n_neighbors=15, # 5
prob_neighbor_mating=0.7, # 0.3
sampling=path_sampling,
mutation=path_mutation,
crossover=path_crossover,
# eliminate_duplicates=path_eliminate_duplicates,
repair=path_repair
),
'NSGA3' : NSGA3(
ref_dirs=get_reference_directions("das-dennis", len(model['F']), n_partitions=12),
# pop_size=len(get_reference_directions("das-dennis", len(model['F']), n_partitions=12)),
pop_size=pop_size,
n_neighbors=15,
prob_neighbor_mating=0.7,
sampling=path_sampling,
mutation=path_mutation,
crossover=path_crossover,
eliminate_duplicates=path_eliminate_duplicates,
repair=path_repair,
# termination=path_termination
),
'USNGA3' : UNSGA3(
ref_dirs=np.array([[0.7, 0.9, 0.2, 0], [0.5, 0.7, 0.4, 0], [0.8, 0.9, 0.4, 0]]),
# pop_size=pop_size,
pop_size = len(np.array([[0.7, 0.9, 0.2, 0], [0.5, 0.7, 0.4, 0], [0.8, 0.9, 0.4, 0]])),
sampling=PathSampling(),
mutation=path_mutation,
crossover=path_crossover,
eliminate_duplicates=path_eliminate_duplicates,
# repair=path_repair
),
# 'AGEMOEAD' : AGEMOEA(
# pop_size=126,
# sampling=PathSampling(),
# mutation=path_mutation,
# crossover=path_crossover,
# eliminate_duplicates=path_eliminate_duplicates,
# repair=path_repair
# ),
'SMSEMOA' : SMSEMOA(
pop_size=pop_size,
sampling=PathSampling(),
mutation=path_mutation,
crossover=path_crossover,
eliminate_duplicates=path_eliminate_duplicates,
# repair=path_repair
)
}
class PathAlgorithm(object):
def __init__(self, algorithm) -> None:
self.algorithm = algorithm
def __call__(self, *args: Any, **kwds: Any) -> Any:
print("-->", self.algorithm)
if self.algorithm == 'NSGA3':
# print(len(algorithm_dict['NSGA3'].ref_dirs))
return algorithm_dict['NSGA3']
elif self.algorithm == 'MOEAD':
return algorithm_dict['MOEAD']
elif self.algorithm == 'NSGA2':
return algorithm_dict['NSGA2']
elif self.algorithm == 'GA':
return algorithm_dict['GA']
# test = PathAlgorithm('NSGA2')()
# print(test)