Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the format of 0 arity function terminal #643

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions deap/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,25 @@ 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
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):
Expand Down Expand Up @@ -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.
Expand Down