-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUGFIX: Exception when no feasible solution was found
- Loading branch information
Julian Blank
committed
Oct 4, 2019
1 parent
d6f35c9
commit 6d8cb13
Showing
6 changed files
with
110 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from pymoo.algorithms.nsga2 import NSGA2 | ||
from pymoo.factory import get_problem | ||
from pymoo.optimize import minimize | ||
from pymoo.visualization.scatter import Scatter | ||
|
||
|
||
def my_callback(algorithm): | ||
disp = algorithm.func_display_attrs(algorithm.problem, algorithm.evaluator, algorithm, algorithm.pf) | ||
print("My Custom Output: ", end='') | ||
algorithm._display(disp) | ||
|
||
|
||
problem = get_problem("zdt2") | ||
|
||
algorithm = NSGA2(pop_size=100, elimate_duplicates=True, callback=my_callback) | ||
|
||
res = minimize(problem, | ||
algorithm, | ||
('n_gen', 200), | ||
seed=1, | ||
verbose=False) | ||
|
||
plot = Scatter() | ||
plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7) | ||
plot.add(res.F, color="red") | ||
plot.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pymoo.algorithms.genetic_algorithm import GeneticAlgorithm | ||
|
||
|
||
class MemeticAlgorithm(GeneticAlgorithm): | ||
|
||
def _next(self): | ||
# do the mating using the current population | ||
self.off = self._mating(self.pop) | ||
|
||
################################################################ | ||
# Add a local optimization here | ||
################################################################ | ||
|
||
# evaluate the offspring | ||
self.evaluator.eval(self.problem, self.off, algorithm=self) | ||
|
||
# merge the offsprings with the current population | ||
self.pop = self.pop.merge(self.off) | ||
|
||
# the do survival selection | ||
self.pop = self.survival.do(self.problem, self.pop, self.pop_size, algorithm=self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.