I'm trying to write a genetic program in Python using DEAP and have several zero argument functions as terminals. I want to be able to combine them using, for example, an if_then_else primitive but this primitive keeps trying to call my other int type terminals. I want to strongly type the pset to avoid this but DEAP won't allow me to use None type arguments when adding strongly typed primitives, what can I do?
This is the code defining the pset I have so far
def progn(*args):
for arg in args:
arg()
def prog2(out1, out2):
return partial(progn,out1,out2)
def prog3(out1, out2, out3):
return partial(progn,out1,out2,out3)
def if_then_else(condition, out1, out2):
out1() if condition() else out2()
pset = gp.PrimitiveSetTyped("main", [None, int, bool], None)
pset.addPrimitive(if_wall_ahead, [None, None], None)
pset.addPrimitive(prog2, [None, None], None)
pset.addPrimitive(prog3, [None, None, None], None)
pset.addPrimitive(compare, [int,int], bool)
pset.addPrimitive(operator.and_, [bool, bool], bool)
pset.addPrimitive(operator.or_, [bool, bool], bool)
pset.addPrimitive(operator.not_, [bool], bool)
pset.addTerminal(player.changeDirectionRight, None)
pset.addTerminal(player.changeDirectionUp, None)
pset.addTerminal(player.changeDirectionLeft, None)
pset.addTerminal(player.changeDirectionDown, None)
pset.addTerminal(player.h_target_distance, int)
pset.addTerminal(player.v_target_distance, int)
pset.addEphemeralConstant("rand", random.randint(0,20), int)