Open dancincn121 opened 4 years ago
I think what you are looking for is the arity.
I think what you are looking for is the arity.
i use pset = gp.PrimitiveSet("MAIN", arity=2) pset.renameArguments(ARG0=3) pset.renameArguments(ARG1=5) then a = toolbox.individual() returns mul(3*5)
what should i do if i want the result to become 15?
I follow the example about arithmetic expression:
---------------------code------------------- import operator
from deap import base from deap import creator from deap import gp from deap import tools
pset = gp.PrimitiveSet("MAIN", arity=1) pset.addPrimitive(operator.add, 2) pset.addPrimitive(operator.sub, 2) pset.addPrimitive(operator.mul, 2)
creator.create("FitnessMin", base.Fitness, weights=(-1.0,)) creator.create("Individual", gp.PrimitiveTree, fitness=creator.FitnessMin, pset=pset)
toolbox = base.Toolbox() toolbox.register("expr", gp.genHalfAndHalf, pset=pset, min=1, max=2) toolbox.register("individual", tools.initIterate, creator.Individual, toolbox.expr) ------------------------code end-------------------------
then the toolbox.individual returns mul(ARG0,ARG0) How can I use other variables to instead ARG0 (for example: to return the result of 3*5)?