Class NegativeIntegerCostFitnessFunction<T extends Copyable<T>>
 java.lang.Object

 org.cicirello.search.evo.NegativeIntegerCostFitnessFunction<T>

 Type Parameters:
T
 The type of object under optimization.
 All Implemented Interfaces:
FitnessFunction<T>
,FitnessFunction.Integer<T>
public final class NegativeIntegerCostFitnessFunction<T extends Copyable<T>> extends Object implements FitnessFunction.Integer<T>
This class provides a convenient mechanism for transforming optimization cost values to fitness values. Most of the algorithms in the library require a cost function to minimize through a class that implements either
OptimizationProblem
orIntegerCostOptimizationProblem
. However, the evolutionary algorithms in the library require a fitness function such that higher fitness implies better solution. Furthermore, some selection operators further assume that fitness values are positive, such asFitnessProportionalSelection
andStochasticUniversalSampling
.This class transforms the cost of solution s to fitness with the following transformation: fitness(s) = cost(s), where cost(s) refers to the
IntegerCostOptimizationProblem.cost(T)
method.Because this transformation produces negative fitness values, it is not compatible with all selection operators. However, many of the selection operators in the library work even with negative fitness values, such as any selection operator that uses only relative fitness values. For example,
TournamentSelection
and other selection operators that only care if one fitness is higher or lower than another will work fine with negative fitness values.Incompatible Selection Operators: The library does include some selection operators that require positive fitness values. Thus, the NegativeIntegerCostFitnessFunction is incompatible with such selection operators, which include the following:
FitnessProportionalSelection
,StochasticUniversalSampling
,BiasedFitnessProportionalSelection
, andBiasedStochasticUniversalSampling
. The behavior of these selection operators that select population members with probabilities that are proportional to their fitness is undefined for negative fitnesses.


Nested Class Summary

Nested classes/interfaces inherited from interface org.cicirello.search.evo.FitnessFunction
FitnessFunction.Double<T extends Copyable<T>>, FitnessFunction.Integer<T extends Copyable<T>>


Constructor Summary
Constructors Constructor Description NegativeIntegerCostFitnessFunction(IntegerCostOptimizationProblem<T> problem)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = cost(s).

Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
fitness(T candidate)
Computes the fitness of a candidate solution to a problem, for use by genetic algorithms and other evolutionary algorithms.IntegerCostOptimizationProblem<T>
getProblem()
Gets a reference to the problem that this fitness function is for.



Constructor Detail

NegativeIntegerCostFitnessFunction
public NegativeIntegerCostFitnessFunction(IntegerCostOptimizationProblem<T> problem)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = cost(s). Parameters:
problem
 The optimization problem.


Method Detail

fitness
public int fitness(T candidate)
Description copied from interface:FitnessFunction.Integer
Computes the fitness of a candidate solution to a problem, for use by genetic algorithms and other evolutionary algorithms. Specified by:
fitness
in interfaceFitnessFunction.Integer<T extends Copyable<T>>
 Parameters:
candidate
 The solution whose fitness is to be evaluated. Returns:
 the fitness of candidate

getProblem
public IntegerCostOptimizationProblem<T> getProblem()
Description copied from interface:FitnessFunction
Gets a reference to the problem that this fitness function is for. Specified by:
getProblem
in interfaceFitnessFunction<T extends Copyable<T>>
 Returns:
 a reference to the problem.

