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.
Add example for AGE-MOEA-II with constrained problems
- Loading branch information
1 parent
f6aaf16
commit ff63e28
Showing
1 changed file
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from pymoo.indicators.igd import IGD | ||
from pymoo.util.ref_dirs import get_reference_directions | ||
from pymoo.algorithms.moo.age2 import AGEMOEA2 | ||
from pymoo.optimize import minimize | ||
|
||
from pymoo.problems.many import C1DTLZ1, DC1DTLZ1, DC1DTLZ3, DC2DTLZ1, DC2DTLZ3, DC3DTLZ1, DC3DTLZ3, C1DTLZ3, \ | ||
C2DTLZ2, C3DTLZ1, C3DTLZ4 | ||
import ray | ||
import numpy as np | ||
|
||
benchmark_algorithms = [ | ||
AGEMOEA2(), | ||
] | ||
|
||
benchmark_problems = [ | ||
C1DTLZ1, DC1DTLZ1, DC1DTLZ3, DC2DTLZ1, DC2DTLZ3, DC3DTLZ1, DC3DTLZ3, C1DTLZ3, C2DTLZ2, C3DTLZ1, C3DTLZ4 | ||
] | ||
|
||
|
||
def run_benchmark(problem_class, algorithm): | ||
# Instantiate the problem | ||
problem = problem_class() | ||
|
||
res = minimize( | ||
problem, | ||
algorithm, | ||
pop_size=100, | ||
verbose=True, | ||
seed=1, | ||
termination=('n_gen', 2000) | ||
) | ||
|
||
# Step 4: Generate the reference points | ||
ref_dirs = get_reference_directions("uniform", problem.n_obj, n_points=528) | ||
|
||
# Obtain the true Pareto front (for synthetic problems) | ||
pareto_front = problem.pareto_front(ref_dirs) | ||
|
||
# Calculate IGD | ||
if res.F is None: | ||
igd = np.Infinity | ||
else: | ||
igd = IGD(pareto_front)(res.F) | ||
|
||
result = { | ||
"problem": problem, | ||
"algorithm": algorithm, | ||
"result": res, | ||
"igd": igd | ||
} | ||
|
||
return result | ||
|
||
|
||
tasks = [] | ||
for problem in benchmark_problems: | ||
for algorithm in benchmark_algorithms: | ||
tasks.append(ray.remote(run_benchmark).remote(problem, algorithm)) | ||
result = ray.get(tasks) | ||
|
||
for res in result: | ||
print(f"Algorithm = {res['algorithm'].__class__.__name__}, " | ||
f"Problem = {res['problem'].__class__.__name__}, " | ||
f"IGD = {res['igd']}") |