anthill.genie.impl
Class GeneticExperimentImpl
java.lang.Object
|
+--anthill.antsim.impl.ExperimentImpl
|
+--anthill.genie.impl.GeneticExperimentImpl
- All Implemented Interfaces:
- Clearable, Experiment, GeneticExperiment
- public class GeneticExperimentImpl
- extends ExperimentImpl
- 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.
Field Summary |
protected boolean |
computed
Boolean flag; true if the fitness has been already computed |
Constructor Summary |
GeneticExperimentImpl(Factory factory,
int size)
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 |
computed
protected boolean computed
- Boolean flag; true if the fitness has been already computed
GeneticExperimentImpl
public GeneticExperimentImpl(Factory factory,
int size)
- Instantiates a new experiment by creating the specified
number of scenarios through the specified scenario factory.
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
- Overrides:
evaluate
in class ExperimentImpl
- 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
- Overrides:
clear
in class ExperimentImpl