From 56d314e062b58c38f5526dc86e9d7a14703fa999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E9=A3=9E?= Date: Thu, 13 Feb 2020 09:47:03 +0800 Subject: [PATCH] bug (GA): int mode, set `has_constraint = True` #37 --- sko/GA.py | 4 ++++ 1 file changed, 4 insertions(+) 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)