Skip to content

Commit

Permalink
Merge pull request #94 from cyrilpic/modact
Browse files Browse the repository at this point in the history
Add wrapper to MODAct problems
  • Loading branch information
blankjul authored Sep 6, 2020
2 parents b547371 + 287a63b commit 2514acb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions pymoo/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def get_problem_options():
('dascmop7', DASCMOP7),
('dascmop8', DASCMOP8),
('dascmop9', DASCMOP9),
('modact', MODAct),
('mw1', MW1),
('mw2', MW2),
('mw3', MW3),
Expand Down
1 change: 1 addition & 0 deletions pymoo/problems/multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pymoo.problems.multi.ctp import *
from pymoo.problems.multi.dascmop import *
from pymoo.problems.multi.kursawe import *
from pymoo.problems.multi.modact import *
from pymoo.problems.multi.mw import *
from pymoo.problems.multi.osy import *
from pymoo.problems.multi.tnk import *
Expand Down
60 changes: 60 additions & 0 deletions pymoo/problems/multi/modact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os

import numpy as np

from pymoo.model.problem import Problem
from pymoo.problems.util import load_pareto_front_from_file


class MODAct(Problem):
"""Multi-Objective Design of Actuators
MODAct is a framework for real-world constrained multi-objective optimization.
Refer to the python package https://github.com/epfl-lamd/modact from requirements.
Best-known Pareto fronts must be downloaded from here: https://doi.org/10.5281/zenodo.3824302
Parameters
----------
function: str or modact.problems
The name of the benchmark problem to use either as a string or the
problem object instance. Example values: cs1, cs3, ct2, ct4, cts3
References:
----------
C. Picard and J. Schiffmann, “Realistic Constrained Multi-Objective Optimization Benchmark Problems from Design,”
IEEE Transactions on Evolutionary Computation, pp. 1–1, 2020.
"""
def __init__(self, function, **kwargs):
import modact.problems as pb

if isinstance(function, pb.Problem):
self.fct = function
else:
self.fct = pb.get_problem(function)
lb, ub = self.fct.bounds()
n_var = len(lb)
n_obj = len(self.fct.weights)
n_constr = len(self.fct.c_weights)
xl = lb
xu = ub

self.weights = np.array(self.fct.weights)
self.c_weights = np.array(self.fct.c_weights)

super().__init__(n_var=n_var, n_obj=n_obj, n_constr=n_constr, xl=xl,
xu=xu, elementwise_evaluation=True, type_var=np.double,
**kwargs)

def _evaluate(self, x, out, *args, **kwargs):
f, g = self.fct(x)
out["F"] = np.array(f)*-1*self.weights
out["G"] = np.array(g)*self.c_weights

def _calc_pareto_front(self, *args, **kwargs):
"""Loads the corresponding PF if it exists"""
fname = f"{self.fct.name}_PF.dat"
F = load_pareto_front_from_file(os.path.join("modact", fname))
if F is not None:
return F*self.weights*-1

0 comments on commit 2514acb

Please sign in to comment.