forked from anyoptimization/pymoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix anyoptimization#207: Added DE tests and fixed another selection i…
…ssue.
- Loading branch information
Showing
3 changed files
with
49 additions
and
21 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,25 @@ | ||
import pytest | ||
|
||
from pymoo.algorithms.soo.nonconvex.de import DE | ||
from pymoo.factory import get_problem | ||
from pymoo.operators.sampling.lhs import LHS | ||
from pymoo.optimize import minimize | ||
|
||
|
||
@pytest.mark.parametrize('selection', ["rand", "best", "rand-to-best", "current-to-rand", "current-to-best", "current-to-pbest"]) | ||
@pytest.mark.parametrize('crossover', ["bin", "exp"]) | ||
def test_de(selection, crossover): | ||
problem = get_problem("ackley", n_var=10) | ||
|
||
algorithm = DE( | ||
pop_size=100, | ||
sampling=LHS(), | ||
variant=f"DE/{selection}/1/{crossover}") | ||
|
||
ret = minimize(problem, | ||
algorithm, | ||
('n_gen', 20), | ||
seed=1, | ||
verbose=True) | ||
|
||
assert len(ret.opt) > 0 |
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
from pymoo.algorithms.moo.nsga2 import NSGA2 | ||
from pymoo.algorithms.soo.nonconvex.de import DE | ||
from pymoo.factory import get_problem | ||
from pymoo.operators.sampling.lhs import LHS | ||
from pymoo.optimize import minimize | ||
from pymoo.visualization.scatter import Scatter | ||
|
||
problem = get_problem("zdt1") | ||
problem = get_problem("ackley", n_var=10) | ||
|
||
algorithm = NSGA2(pop_size=100) | ||
algorithm = DE( | ||
pop_size=100, | ||
sampling=LHS(), | ||
variant='DE/current-to-pbest/1/bin') | ||
|
||
res = minimize(problem, | ||
algorithm, | ||
('n_gen', 200), | ||
seed=1, | ||
verbose=True) | ||
algorithm, | ||
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() |