Skip to content

Commit

Permalink
Termination Criterion and LoopwiseAlgorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
blankjul committed Apr 29, 2022
1 parent e9113f4 commit e82f75b
Show file tree
Hide file tree
Showing 27 changed files with 401 additions and 793 deletions.
291 changes: 0 additions & 291 deletions pymoo/algorithms/soo/nonconvex/de_bak.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ def __init__(self, *args) -> None:
super().__init__()
self.terminations = args

def _do_continue(self, algorithm):
for term in self.terminations:
if not term.do_continue(algorithm):
return False
return True
def _update(self, algorithm):
return min([termination.update(algorithm) for termination in self.terminations])
38 changes: 38 additions & 0 deletions pymoo/termination/cv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pymoo.core.termination import Termination
from pymoo.util.termination.delta import DeltaToleranceTermination


class ConstraintViolationTermination(DeltaToleranceTermination):

def __init__(self, tol=1e-6, **kwargs):
super().__init__(tol, **kwargs)

def _update(self, algorithm):
if algorithm.problem.has_constraints():
return super()._update(algorithm)
else:
return 1.0

def _delta(self, prev, current):
return max(0, prev - current)

def _data(self, algorithm):
return algorithm.opt.get("CV").min()


class UntilFeasibleTermination(Termination):

def __init__(self) -> None:
super().__init__()
self.initial_cv = None

def _update(self, algorithm):
cv = algorithm.opt.get("CV").min()

if self.initial_cv is None:
if cv <= 0:
self.initial_cv = 1e-32
else:
self.initial_cv = cv

return 1 - cv / self.initial_cv
40 changes: 40 additions & 0 deletions pymoo/termination/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pymoo.core.termination import Termination
from pymoo.util.termination.cv import ConstraintViolationTermination
from pymoo.util.termination.ftol import SingleObjectiveSpaceTermination, MultiObjectiveSpaceTermination
from pymoo.util.termination.robust import RobustTermination
from pymoo.util.termination.xtol import DesignSpaceTermination


class DefaultTermination(Termination):

def __init__(self, x, cv, f) -> None:
super().__init__()
self.x = x
self.cv = cv
self.f = f

def _update(self, algorithm):
cv = self.cv.update(algorithm)
x = self.x.update(algorithm)
f = self.f.update(algorithm)
return min(cv, max(x, f))


class DefaultSingleObjectiveTermination(DefaultTermination):

def __init__(self) -> None:
x = RobustTermination(DesignSpaceTermination(1e-8), 30)
cv = RobustTermination(ConstraintViolationTermination(1e-8), 50)
f = RobustTermination(SingleObjectiveSpaceTermination(1e-6), 30)
super().__init__(x, cv, f)


class DefaultMultiObjectiveTermination(DefaultTermination):

def __init__(self, n_skip=5) -> None:
x = RobustTermination(DesignSpaceTermination(1e-8, n_skip=n_skip), 30)
cv = RobustTermination(ConstraintViolationTermination(1e-8, n_skip=n_skip), 50)
f = RobustTermination(MultiObjectiveSpaceTermination(0.0025, n_skip=n_skip), 50)
super().__init__(x, cv, f)


Loading

0 comments on commit e82f75b

Please sign in to comment.