Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pymoo/core/crossover.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,13 @@ def do(self, problem, pop, parents=None, *args, random_state=None, **kwargs):
def _do(self, problem, X, *args, random_state=None, **kwargs):
pass

@staticmethod
def safe_bounds_do(func):
@functools.wraps(func)
def wrapped_do(self, problem, X, **kwargs):
result = func(self, problem, X, **kwargs)
if np.any(result < (problem.xl or -np.inf)) or np.any(result > (problem.xu or np.inf)):
raise ValueError("The generated solution is out of bounds.")
return result
return wrapped_do

2 changes: 2 additions & 0 deletions pymoo/operators/crossover/sbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def __init__(self,
self.prob_exch = Real(prob_exch, bounds=(0.0, 1.0), strict=(0.0, 1.0))
self.prob_bin = Real(prob_bin, bounds=(0.0, 1.0), strict=(0.0, 1.0))

@Crossover.safe_bounds_do
def _do(self, problem, X, **kwargs):
def _do(self, problem, X, *args, random_state=None, **kwargs):
_, n_matings, _ = X.shape

Expand Down
Loading