package org.dgpf.gp.netautomaton.fitness;
import org.dgpf.gp.automaton.base.Program;
import org.dgpf.gp.netautomaton.base.NetContext;
import org.dgpf.gp.netautomaton.base.NetSupport;
import org.dgpf.search.api.FitnessData;
import org.dgpf.search.api.FitnessFunction;
import org.dgpf.search.api.SearchContext;
/**
* The code size pressure fitness function is used to prevent programs from
* performing too many transmissions.
*
* @author Thomas Weise
*/
public class TransmissionPressure extends FitnessFunction<Program,
FitnessData<Program>>
{
/**
* The globally shared instance of the transmission pressure fitness function.
*/
public static final FitnessFunction<Program, FitnessData<Program>>
DEFAULT_INSTANCE = new TransmissionPressure(-1);
/**
* Create a new transmission pressure fitness function.
*
* @param p_precision The precision of this fitness function. This is the
* count of levels to be used for the calculation.
* If this parameter is <= 0.0d, the full precision
* available will be used.
*/
private TransmissionPressure(final double p_precision)
{
super(-1, p_precision);
}
/**
* This method is called when a simulation has come to an end.
* You must use this method to store a fitness value into the fitness
* record <code>p_fitness</code>. Use <code>set_fitness</code> for this.
* @param p_fitness The fitness data record that was used in this
* simulation.
* @param p_context The context that has driven the simulation.
* @see FitnessData#set_fitness(double)
*/
@Override
protected final void end_simulation(
final FitnessData<Program> p_fitness,
final SearchContext<Program> p_context)
{
NetSupport l_support;
double l_a;
l_support = ((NetContext)p_context).get_net_support();
l_a = l_support.get_transmission_count();
if(l_a > 0)
{
p_fitness.set_fitness(1.0d /
(l_a * (1 + l_support.get_collission_count())));
}
else
{
p_fitness.set_fitness(0.0d);
}
}
/**
* Returns a human readable name of this fitness function.
* @return A human readable name of this fitness function.
*/
@Override
public final String toString ()
{
return "transmissions";
}
}