anthill.genie.impl
Class GeneticExperimentImpl

java.lang.Object
  |
  +--anthill.genie.impl.GeneticExperimentImpl
All Implemented Interfaces:
Clearable, Experiment, GeneticExperiment

public class GeneticExperimentImpl
extends java.lang.Object
implements GeneticExperiment

Class ExperimentImpl is a simple implementation of Experiment. It is constituted by a set of scenarios, on which the fitness is computed as the average fitness as computed in each scenario.

Version:
$Revision$
Author:
Alberto Montresor

Field Summary
protected  boolean computed
          Boolean flag; true if the fitness has been already computed
protected  Factory factory
          Factory used to instantiate objects
protected  int iterations
          Number of times a scenario is evaluated
static java.lang.String ROUND_NUMBER
          The identifier of the counter used in a Stats object to count the number of repetitions of the scenario evaluation in a experiment.
protected  int scenarioVersion
          Version identifier of the scenario; when init params change, the version increase
 
Constructor Summary
GeneticExperimentImpl(Factory factory, int iterations)
          Instantiates a new experiment by creating the specified number of scenarios through the specified scenario factory.
 
Method Summary
 void addGeneticCode(GeneticCode code)
          Set the genetic code to be evaluated.
 void clear()
          Restores the object to its initial state.
 Stats[] evaluate()
          Execute the experiment, i.e. evaluate the fitness of the genetic code on each of the scenarios contained in this experimnt.
 double getFitness()
          Returns the evaluated fitness.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROUND_NUMBER

public static final java.lang.String ROUND_NUMBER
The identifier of the counter used in a Stats object to count the number of repetitions of the scenario evaluation in a experiment.

factory

protected Factory factory
Factory used to instantiate objects

iterations

protected int iterations
Number of times a scenario is evaluated

scenarioVersion

protected int scenarioVersion
Version identifier of the scenario; when init params change, the version increase

computed

protected boolean computed
Boolean flag; true if the fitness has been already computed
Constructor Detail

GeneticExperimentImpl

public GeneticExperimentImpl(Factory factory,
                             int iterations)
Instantiates a new experiment by creating the specified number of scenarios through the specified scenario factory.
Method Detail

addGeneticCode

public void addGeneticCode(GeneticCode code)
Set the genetic code to be evaluated. In this basic implementation, only one genetic code can be present in the Nest network at a time. If this method is called more than once, the values is substituted with the new values.
Specified by:
addGeneticCode in interface GeneticExperiment

evaluate

public Stats[] evaluate()
Execute the experiment, i.e. evaluate the fitness of the genetic code on each of the scenarios contained in this experimnt. The fitness of the genetic code for this experiment is obtained by the sum of the fitness values obtained by evaluating them on the scenarios.
Specified by:
evaluate in interface Experiment
Throws:
IllegalStateException - if no genetic code is present

getFitness

public double getFitness()
Returns the evaluated fitness.
Specified by:
getFitness in interface GeneticExperiment
Throws:
IllegalStateException - if the fitness value has not been computed yet.

clear

public void clear()
Restores the object to its initial state. Method clear() is invoked on all scenarios included in this experiment. The genetic code to be evaluated and the computed fitness are restored to their initial state.
Specified by:
clear in interface Clearable