From 49623be99953493d9da699a5c52f4ce7cef5cb52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cliningbo=E2=80=9D?= <“liningbo@gmail.com”> Date: Sun, 5 Jun 2022 00:24:49 +0800 Subject: [PATCH] change the format of 0 arity function terminal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “liningbo” <“liningbo@gmail.com”> --- deap/gp.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/deap/gp.py b/deap/gp.py index 44bd8bd07..48455a8ba 100644 --- a/deap/gp.py +++ b/deap/gp.py @@ -220,7 +220,11 @@ class Terminal(object): def __init__(self, terminal, symbolic, ret): self.ret = ret self.value = terminal - self.name = str(terminal) + #self.name = str(terminal) + if callable(self.value): + self.name = self.value.__name__ + else: + self.name = str(terminal) self.conv_fct = str if symbolic else repr @property @@ -228,7 +232,13 @@ def arity(self): return 0 def format(self): - return self.conv_fct(self.value) + if callable(self.value): + return (self.name + "()") + else: + return self.conv_fct(self.value) + + #def format(self): + # return self.conv_fct(self.value) def __eq__(self, other): if type(self) is type(other): @@ -368,7 +378,7 @@ def addTerminal(self, terminal, ret_type, name=None): if name is not None: self.context[name] = terminal - terminal = name + #terminal = name symbolic = True elif terminal in (True, False): # To support True and False terminals with Python 2.