ec.cgp
Class Evaluator

java.lang.Object
  extended by ec.cgp.Evaluator

public class Evaluator
extends java.lang.Object

Interprets the program encoded by an individual's genome, and evaluates the results of the program with the given inputs.

Author:
David Oranchak, doranchak@gmail.com, http://oranchak.com

Field Summary
(package private) static boolean DEBUG
           
(package private) static int evals
          counter to track number of node evaluations performed.
static java.util.List<java.util.Map<java.lang.Integer,java.lang.String>> expressionMap
          maps String representations of node sub-expressions to their node numbers.
static Functions functions
          functions are loaded during setup.
static java.util.List<java.util.Map<java.lang.Integer,java.lang.Object>> nodeMap
          maps node evaluations to their node numbers.
 
Constructor Summary
Evaluator()
           
 
Method Summary
static void add(boolean expression, java.lang.StringBuffer sb, java.lang.String msg)
          Appends the given string to the given expression.
static void debug(java.lang.String msg)
           
private static java.lang.Object evalNode(int threadNum, boolean expression, java.lang.Object[] inputs, java.lang.StringBuffer expr, java.lang.Object genome, int nodeNum, VectorSpeciesCGP s)
          Computes the result of evaluating the given node.
static java.lang.Object[] evaluate(ec.EvolutionState state, int threadNum, java.lang.Object[] inputs, VectorIndividualCGP ind)
          Evaluate the genome against the given inputs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

static boolean DEBUG

evals

static int evals
counter to track number of node evaluations performed.


nodeMap

public static java.util.List<java.util.Map<java.lang.Integer,java.lang.Object>> nodeMap
maps node evaluations to their node numbers. used to avoid re-processing nodes unnecessarily.


expressionMap

public static java.util.List<java.util.Map<java.lang.Integer,java.lang.String>> expressionMap
maps String representations of node sub-expressions to their node numbers. used to avoid re-processing nodes repeatedly.


functions

public static Functions functions
functions are loaded during setup.

Constructor Detail

Evaluator

public Evaluator()
Method Detail

evaluate

public static java.lang.Object[] evaluate(ec.EvolutionState state,
                                          int threadNum,
                                          java.lang.Object[] inputs,
                                          VectorIndividualCGP ind)
Evaluate the genome against the given inputs. If ind.expression is null, a string representation of the genome is computed and stored there.

Parameters:
inputs - inputs used to evaluate genome
ind - the current individual
Returns:
array of computed outputs from our Cartesian genetic program

evalNode

private static java.lang.Object evalNode(int threadNum,
                                         boolean expression,
                                         java.lang.Object[] inputs,
                                         java.lang.StringBuffer expr,
                                         java.lang.Object genome,
                                         int nodeNum,
                                         VectorSpeciesCGP s)
Computes the result of evaluating the given node.

Parameters:
threadNum - The current thread number.
expression - If true, compute the string representation of the sub-expression represented by this node.
inputs - The input values for this evaluation.
expr - Storage for the String-representation of the entire expression.
genome - The current genome.
nodeNum - The node number we are evaluating.
s - The CGP species
Returns:
The result of evaluation. TODO: factor out all the float-vs-int checks to speed up evaluation.

add

public static void add(boolean expression,
                       java.lang.StringBuffer sb,
                       java.lang.String msg)
Appends the given string to the given expression.

Parameters:
expression - If true, append; otherwise, ignore.
sb - The target expression.
msg - The snippet to append to the target.

debug

public static void debug(java.lang.String msg)