A Program has a lisp expression associated with it which dictates its
behavior and therefore fitness.
Methods
|
|
|
|
__init__
|
__init__ (
self,
env,
interpreter,
lisp="()",
)
Create a Program
You must provide a Charlemagne environment and optionally an initial
lisp expression.
|
|
_makeProgram
|
_makeProgram ( self, lisp )
Factory method for instantiating programs
This can be overridden in subclasses to create Program subclasses.
|
|
_resetStats
|
_resetStats ( self )
|
|
adjustedFitness
|
adjustedFitness ( self )
Calculate the adjusted fitness
Note the program needs to have been evaluated by a ProgramEvaluator for
this to work. The adjusted fitness is based on the rawfitness of the
lisp expression.
|
|
contextSensitiveCrossover
|
contextSensitiveCrossover ( self, mate )
Perform a crossover operation with another program
|
|
contextSensitiveCrossoverAt
|
contextSensitiveCrossoverAt (
self,
mate,
branch,
)
Perform a context sensitive crossover
Perform a crossover operation with another program at specified points
on the program trees.
|
|
crossover
|
crossover ( self, mate )
Perform a crossover operation with another program
|
|
crossoverAt
|
crossoverAt (
self,
mate,
branch1,
branch2,
)
Perform a crossover operation with another program at specified points on
the program trees
|
|
flatCount
|
flatCount ( self )
Return the number of possible program branches in the lisp expression
|
|
getDepth
|
getDepth ( self )
Returns the depth of the lisp expression
Note the program needs to have been evaluated by a ProgramEvaluator
for this to be set. The Program does not evaluate its own depth.
|
|
getHits
|
getHits ( self )
Get the hits statistic
Note the program needs to have been evaluated by a ProgramEvaluator
for this to be set. The Program does not evaluate its own hits.
|
|
getLisp
|
getLisp ( self )
Retrieve the lisp source of the program
|
|
getRawFitness
|
getRawFitness ( self )
Returns the raw fitness of the program
Note the program needs to have been evaluated by a ProgramEvaluator
for this to be set. The Program does not evaluate its own fitness.
|
|
mutant
|
mutant ( self )
Perform a mutation on the program
|
|
randomize
|
randomize ( self, depth )
Randomize the Program's lisp expression
|
|
replaceConstantSynthesisTokens
|
replaceConstantSynthesisTokens ( self )
Synthesize constants for all CONSTANT-SYNTHESIS token terminals
The terminal CONSTANT-SYNTHESIS is a keyword which is replaced with a
random constant.
|
|
replica
|
replica ( self )
Replicate the program
|
|
save
|
save ( self, file )
Save the program to file
Saves the lisp expression as one line in the provided open file.
|
|
saveStats
|
saveStats ( self, file )
Save the stats
Saves the stats for this program to the provided open file.
|
|
setDepth
|
setDepth ( self, depth )
Set the depth of the program
Note: this is setting the depth statistic for the program, not altering
the lisp expression in any way. Normally a FitnessEvaluator should be
doing this.
|
|
setHits
|
setHits ( self, hits )
Set the hits statistic
Note: this is setting the hits statistic for the program, not altering
the lisp expression in any way. Normally a FitnessEvaluator should be
doing this.
|
|
setLisp
|
setLisp ( self, lisp )
Set the lisp source of the program
|
|
setRawFitness
|
setRawFitness ( self, rawfitness )
Set the raw fitness of the program
Normally a FitnessEvaluator should be doing this.
|
|
show
|
show ( self )
Abstract method for displaying the program
Implement this in subclasses to provide custom display formats.
|