Skip to content

Commit

Permalink
Fix prob_bin behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepmccombs committed Dec 21, 2024
1 parent 78993ee commit 10d3801
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pymoo/operators/crossover/sbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def cross_sbx(X, xl, xu, eta, prob_var, prob_bin, eps=1.0e-14):
cross[:, xl == xu] = False

# assign y1 the smaller and y2 the larger value
y1 = np.min(X, axis=0)[cross]
y2 = np.max(X, axis=0)[cross]
p1_low = X[0] < X[1]
y1, y2 = np.where(p1_low[None, ...], X, X[::-1])[:, cross]

# mask all the values that should be crossovered
_xl = np.repeat(xl[None, :], n_matings, axis=0)[cross]
Expand Down Expand Up @@ -61,10 +61,8 @@ def calc_betaq(beta):
c2 = 0.5 * ((y1 + y2) + betaq * delta)

# with the given probability either assign the value from the first or second parent
b = np.random.random(len(prob_bin)) < prob_bin
tmp = np.copy(c1[b])
c1[b] = c2[b]
c2[b] = tmp
b = (np.random.random(len(prob_bin)) < prob_bin) == p1_low[cross]
c1, c2 = np.where(b[None, ...], [c1, c2], [c2, c1])

# first copy the unmodified parents
Q = np.copy(X)
Expand Down

0 comments on commit 10d3801

Please sign in to comment.