The Python operator¶
class PyOperator¶
-
class
PyOperator
¶ An operator that calls a user-defined function when it is applied to a population (pre- or post-mating) or offsprings (during- mating). The function can have have parameters
pop
when the operator is applied pre- or post-mating,pop, off, dad, mom
when the operator is applied during-mating. An optional parameter can be passed if parameter param is given. In the during-mating case, parameterspop
,dad
andmom
can be ignored if offspringOnly is set toTrue
.-
PyOperator
(func, param=None, begin=0, end=-1, step=1, at=[], reps=ALL_AVAIL, subPops=ALL_AVAIL, infoFields=[])¶ Create a pure-Python operator that calls a user-defined function when it is applied. If this operator is applied before or after mating, your function should have form
func(pop)
orfunc(pop, param)
wherepop
is the population to which the operator is applied,param
is the value specified in parameter param.param
will be ignored if your function only accepts one parameter. Althernatively, the function should have formfunc(ind)
with optional parameterspop
andparam
. In this case, the function will be called for all individuals, or individuals in subpopulations subPops. Individuals for which the function returnsFalse
will be removed from the population. This operator can therefore perform similar functions as operatorDiscardIf
.If this operator is applied during mating, your function should accept parameters
pop
,off
(orind
),dad
,mom
andparam
wherepop
is the parental population, andoff
orind
,dad
, andmom
are offspring and their parents for each mating event, andparam
is an optional parameter. If subPops are provided, only offspring in specified (virtual) subpopulations are acceptable.This operator does not support parameters output, and infoFields. If certain output is needed, it should be handled in the user defined function func. Because the status of files used by other operators through parameter output is undetermined during evolution, they should not be open or closed in this Python operator.
-