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.
Termination Criterion and LoopwiseAlgorithm
- Loading branch information
Showing
27 changed files
with
401 additions
and
793 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,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 |
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,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) | ||
|
||
|
Oops, something went wrong.