Skip to content

Commit 605b6b2

Browse files
author
Julian Blank
committed
Loop-wise Algorithm Execution and Checkpoints
1 parent 43979da commit 605b6b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+957
-197
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**/.DS_Store
22
**/.vscode
33
**/.mp4
4+
**/.npy
45

56

67
# Byte-compiled / optimized / DLL files

benchmark/benchmark_nsga3.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ def get_setup(n_obj):
191191
},
192192

193193

194-
195194
}
196195

197196

pymoo/algorithms/ctaea.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from scipy.spatial.distance import cdist, pdist, squareform
55

66
from pymoo.algorithms.genetic_algorithm import GeneticAlgorithm
7+
from pymoo.docs import parse_doc_string
78
from pymoo.factory import get_decomposition
89
from pymoo.model.individual import Individual
910
from pymoo.model.population import Population
@@ -89,17 +90,16 @@ def __init__(self,
8990
display=MultiObjectiveDisplay(),
9091
**kwargs):
9192
"""
93+
CTAEA
9294
9395
Parameters
9496
----------
95-
9697
ref_dirs : {ref_dirs}
9798
sampling : {sampling}
9899
selection : {selection}
99100
crossover : {crossover}
100101
mutation : {mutation}
101102
eliminate_duplicates : {eliminate_duplicates}
102-
103103
"""
104104

105105
self.ref_dirs = ref_dirs
@@ -194,7 +194,7 @@ def __init__(self, ref_dirs):
194194
self._decomposition = get_decomposition('asf')
195195
self._calc_perpendicular_distance = load_function("calc_perpendicular_distance")
196196

197-
def do(self, problem, pop, da, n_survive, **kwargs):
197+
def do(self, _, pop, da, n_survive, **kwargs):
198198
# Offspring are last of merged population
199199
off = pop[-n_survive:]
200200
# Update ideal point
@@ -322,3 +322,6 @@ def _updateDA(self, pop, Hd, n_survive):
322322
break
323323
itr += 1
324324
return Hd[S]
325+
326+
327+
parse_doc_string(CTAEA.__init__)

pymoo/algorithms/moead.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def __init__(self,
2525
**kwargs):
2626
"""
2727
28+
MOEAD Algorithm.
29+
2830
Parameters
2931
----------
3032
ref_dirs

pymoo/algorithms/nsga2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class RankAndCrowdingSurvival(Survival):
121121

122122
def __init__(self) -> None:
123123
super().__init__(filter_infeasible=True)
124+
self.nds = NonDominatedSorting()
124125

125126
def _do(self, problem, pop, n_survive, D=None, **kwargs):
126127

@@ -131,7 +132,7 @@ def _do(self, problem, pop, n_survive, D=None, **kwargs):
131132
survivors = []
132133

133134
# do the non-dominated sorting until splitting front
134-
fronts = NonDominatedSorting().do(F, n_stop_if_ranked=n_survive)
135+
fronts = self.nds.do(F, n_stop_if_ranked=n_survive)
135136

136137
for k, front in enumerate(fronts):
137138

pymoo/algorithms/nsga3.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,16 @@ def __init__(self,
7171

7272
self.ref_dirs = ref_dirs
7373

74-
if pop_size is None:
75-
pop_size = len(ref_dirs)
74+
# in case of R-NSGA-3 they will be None - otherwise this will be executed
75+
if self.ref_dirs is not None:
76+
77+
if pop_size is None:
78+
pop_size = len(self.ref_dirs)
79+
80+
if pop_size < len(self.ref_dirs):
81+
print(f"WARNING: pop_size={pop_size} is less than the number of reference directions ref_dirs={len(self.ref_dirs)}.\n"
82+
"This might cause unwanted behavior of the algorithm. \nPlease make sure pop_size is equal or larger "
83+
"than the number of reference directions. ")
7684

7785
kwargs['individual'] = Individual(rank=np.inf, niche=-1, dist_to_niche=np.inf)
7886

pymoo/algorithms/so_cmaes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ def __init__(self,
363363
self.parallelize = parallelize
364364
self.al = None
365365

366-
def initialize(self, problem, seed=None, **kwargs):
367-
super().initialize(problem, **kwargs)
366+
def setup(self, problem, seed=None, **kwargs):
367+
super().setup(problem, **kwargs)
368368
self.n_gen = 0
369369

370370
xl = problem.xl.tolist() if problem.xl is not None else None
@@ -438,7 +438,7 @@ def _next(self):
438438
X = np.atleast_2d(X)
439439

440440
# evaluate the population
441-
self.pop = Population().new("X", X)
441+
self.pop = Population.new("X", X)
442442
self.evaluator.eval(self.problem, self.pop, algorithm=self)
443443

444444
# set infeasible individual's objective values to np.nan - then CMAES can handle it

pymoo/algorithms/so_de.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pymoo.operators.crossover.biased_crossover import BiasedCrossover
88
from pymoo.operators.crossover.differental_evolution_crossover import DifferentialEvolutionCrossover
99
from pymoo.operators.crossover.exponential_crossover import ExponentialCrossover
10-
from pymoo.operators.repair.bounds_back_repair import BoundsBackRepair
10+
from pymoo.operators.repair.bounce_back import BounceBackOutOfBoundsRepair
1111
from pymoo.operators.sampling.latin_hypercube_sampling import LatinHypercubeSampling
1212
from pymoo.operators.selection.random_selection import RandomSelection
1313
from pymoo.util.display import SingleObjectiveDisplay
@@ -120,7 +120,7 @@ def _next(self):
120120
self.off = mutation.do(self.problem, _pop, _P, algorithm=self)[:len(self.pop)]
121121

122122
# bounds back if something is out of bounds
123-
self.off = BoundsBackRepair().do(self.problem, self.off)
123+
self.off = BounceBackOutOfBoundsRepair().do(self.problem, self.off)
124124

125125
# evaluate the results
126126
self.evaluator.eval(self.problem, self.off, algorithm=self)

pymoo/algorithms/so_direct.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def __init__(self,
3838
self.penalty = penalty
3939
self.n_max_candidates = n_max_candidates
4040

41-
def initialize(self, problem, **kwargs):
42-
super().initialize(problem, **kwargs)
41+
def setup(self, problem, **kwargs):
42+
super().setup(problem, **kwargs)
4343

4444
xl, xu = problem.bounds()
4545
X = denormalize(0.5 * np.ones(problem.n_var), xl, xu)

pymoo/algorithms/so_gradient_descent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pymoo.model.algorithm import Algorithm
44
from pymoo.model.population import Population
5-
from pymoo.operators.repair.out_of_bounds_repair import repair_out_of_bounds
5+
from pymoo.operators.repair.to_bound import set_to_bounds_if_outside_by_problem
66
from pymoo.util.display import SingleObjectiveDisplay
77
from pymoo.util.termination.default import SingleObjectiveDefaultTermination
88

@@ -60,7 +60,7 @@ def _next(self):
6060

6161
# make the step and check out of bounds for X
6262
self.apply()
63-
self.X = repair_out_of_bounds(self.problem, self.X)
63+
self.X = set_to_bounds_if_outside_by_problem(self.problem, self.X)
6464

6565
# set the population object for automatic print
6666
self.pop = Population(len(self.X)).set("X", self.X, "F", self.F,

0 commit comments

Comments
 (0)