
freak.core.fitness.AbstractStaticMultiObjectiveFitnessFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of freak-core Show documentation
Show all versions of freak-core Show documentation
Core library of the Free Evolutionary Algorithm Toolkit
/*
* This file is part of FrEAK. For licensing and copyright information
* please see the file COPYING in the root directory of this
* distribution or contact .
*/
package freak.core.fitness;
import freak.core.control.ScheduleInterface;
import freak.core.population.Genotype;
import freak.core.population.Individual;
import freak.core.population.IndividualList;
/**
* This class can be used as abstract superclass of all multi objective fitness
* functions which determine the fitness of an individual independently from the
* other individuals in the population and independently from the age of the
* individual. For these fitness functions the fitness value of an individual
* can be cached since it doesn't depend on the current environment.
*
* @author Heiko
*/
public abstract class AbstractStaticMultiObjectiveFitnessFunction extends AbstractMultiObjectiveFitnessFunction {
/**
* Constructs a new AbstractStaticMultiObjectiveFitnessFunction
* with a link back to the current schedule.
*
* @param schedule a link back to the current schedule.
*/
public AbstractStaticMultiObjectiveFitnessFunction(ScheduleInterface schedule) {
super(schedule);
}
/**
* This method implements the use of a cache for fitness values.
*/
public final double[] evaluate(Individual individual, IndividualList list) {
// First, check whether the fitness value is cached.
Double[] d = individual.getLatestKnownFitnessValue();
if (!(d == null)) {
int bound = d.length;
double[] result = new double[bound];
for (int i = 0; i < bound; i++) {
result[i] = d[i].doubleValue();
}
return result;
}
double[] fitness = evaluate(individual.getPhenotype());
int bound = fitness.length;
Double[] cache = new Double[bound];
for (int i = 0; i < bound; i++) {
cache[i] = new Double(fitness[i]);
}
individual.setLatestKnownFitnessValue(cache);
return fitness;
}
/**
* This method must be overriden by subclasses. It must determine the
* fitness value of the given individual independently from the its age.
* @param genotype the individual whose fitness is to be evaluated.
* @return the fitness value of the given individual.
*/
abstract protected double[] evaluate(Genotype genotype);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy