diff --git a/sko/GA.py b/sko/GA.py index b3c3904..1e91e59 100644 --- a/sko/GA.py +++ b/sko/GA.py @@ -148,6 +148,9 @@ 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): @@ -155,6 +158,7 @@ def __init__(self, func, n_dim, 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)