Skip to content

Commit

Permalink
bug (GA): int mode, set has_constraint = True #37
Browse files Browse the repository at this point in the history
  • Loading branch information
guofei9987 committed Feb 13, 2020
1 parent d159fa0 commit 56d314e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sko/GA.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,17 @@ def __init__(self, func, n_dim,
Lind_raw = np.log2((self.ub - self.lb) / self.precision + 1)
self.Lind = np.ceil(Lind_raw).astype(int)

# if precision is integer:
# if Lind_raw is integer, which means the number of all possible value is 2**n, no need to modify
# if Lind_raw is decimal, modify: make the ub bigger and add a constraint_ueq
int_mode = (self.precision % 1 == 0) & (Lind_raw % 1 != 0)
# int_mode is an array of True/False. If True, variable is int constraint and need more code to deal with
for i in range(self.n_dim):
if int_mode[i]:
self.constraint_ueq.append(
lambda x: x[i] - self.ub[i]
)
self.has_constraint = True
self.ub[i] = self.lb[i] + np.exp2(self.Lind[i]) - 1

self.len_chrom = sum(self.Lind)
Expand Down

0 comments on commit 56d314e

Please sign in to comment.