This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathAlgorithm.py
150 lines (122 loc) · 4.78 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
from typing import Any
from PathSampling import *
from PathMutation import *
from PathCrossover import *
from PathRepair import *
from PathProblem import *
from pymoo.operators.crossover.nox import NoCrossover
from PathCrossover import PathCrossover
from pymoo.operators.mutation.nom import NoMutation
from pymoo.core.duplicate import NoDuplicateElimination
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
path_sampling = PathSampling()
path_mutation = PathMutation()
path_crossover = PathCrossover()
path_eliminate_duplicates = NoDuplicateElimination()
path_repair = NoRepair()
# 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
# )
algorithm_dict = {
'PSO': PSO(
pop_size=100,
sampling=path_sampling,
# mutation=path_mutation,
# crossover=path_crossover,
# eliminate_duplicates=path_eliminate_duplicates,
repair=path_repair
),
'GA': GA(
pop_size=100,
sampling=path_sampling,
mutation=path_mutation,
crossover=path_crossover,
eliminate_duplicates=path_eliminate_duplicates,
repair=path_repair
),
'NSGA2' : NSGA2(
pop_size=100,
sampling=path_sampling,
mutation=path_mutation,
crossover=path_crossover,
eliminate_duplicates=path_eliminate_duplicates,
repair=path_repair,
),
'MOEAD' : MOEAD(
# pop_size=40,
ref_dirs=get_reference_directions("das-dennis", PathProblem(PathInfo()).n_obj, n_partitions=12),
n_neighbors=15, # 5
prob_neighbor_mating=0.7, # 0.3
sampling=PathSampling(),
mutation=path_mutation,
crossover=path_crossover,
# eliminate_duplicates=path_eliminate_duplicates,
repair=path_repair
),
'NSGA3' : NSGA3(
pop_size=100,
ref_dirs=get_reference_directions("das-dennis", PathProblem(PathInfo()).n_obj, n_partitions=12),
n_neighbors=15,
prob_neighbor_mating=0.7,
sampling=PathSampling(),
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=126,
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=126,
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:
if self.algorithm == 'NSGA3':
return algorithm_dict['NSGA3']
elif self.algorithm == 'MOEAD':
return algorithm_dict['MOEAD']
else:
return algorithm_dict['NSGA2']
test = PathAlgorithm('NSGA2')()
print(test)