Example Code
Example 1: Using ScientificGrammar
try
{
AmibaFactory<Double> factory = new ScientificFactory();
EvolutionEngine<Double> engine = new EvolutionEngine<Double>(
new File("AmibaConfig.xml"), factory);
// evolve
Population<Double> evolvedPopulation = engine.evolve();
//the result can also be obtained at an intermediate stage
EvolutionResult<Double> result = evolvedPopulation.getEvolutionResult();
List<FitnessCase<Double>> testCases = new DoubleFitnessCaseLoader()
.load("test/data/TestSet.xml");
System.out.println("Test fitness : "
+ result.getBestIndividual().evaluateFitness(testCases));
List<Double> calculated = result.getBestIndividual().useOn(testCases);
for (int i = 0; i < calculated.size(); i++)
{
System.out.println("Expected : " + testCases.get(i).getValue() + " Calculated : "
+ calculated.get(i));
}
result.save(new FileOutputStream(new File("result")));
}
catch (AmibaException e)
{
e.printStackTrace();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
Example 2: