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

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

 Type Parameters:
T
 The type of object under optimization.
 All Implemented Interfaces:
FitnessFunction<T>
,FitnessFunction.Double<T>
public final class InverseCostFitnessFunction<T extends Copyable<T>> extends Object implements FitnessFunction.Double<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 to meet these requirements with the following transformation: fitness(s) = c / (c + problem.cost(s)  problem.minCost()), where c is a positive constant, which defaults to 1.0 (see constructors). The problem.cost(s) and problem.minCost() refer to the methods by those names in the
OptimizationProblem
andIntegerCostOptimizationProblem
classes. Note that the adjustment by problem.minCost() ensures that fitness will be positive even if costs can be negative.Note that the problem's implementation of minCost must return a finite lower bound for the cost function (which is assumed to be correct), otherwise the constructors of this class will throw an
IllegalArgumentException
.


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 InverseCostFitnessFunction(IntegerCostOptimizationProblem<T> problem)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = 1.0 / (1.0 + problem.cost(s)  problem.minCost()).InverseCostFitnessFunction(IntegerCostOptimizationProblem<T> problem, double c)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = c / (c + problem.cost(s)  problem.minCost()).InverseCostFitnessFunction(OptimizationProblem<T> problem)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = 1.0 / (1.0 + problem.cost(s)  problem.minCost()).InverseCostFitnessFunction(OptimizationProblem<T> problem, double c)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = c / (c + problem.cost(s)  problem.minCost()).

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



Constructor Detail

InverseCostFitnessFunction
public InverseCostFitnessFunction(OptimizationProblem<T> problem)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = 1.0 / (1.0 + problem.cost(s)  problem.minCost()). Parameters:
problem
 The optimization problem. Throws:
IllegalArgumentException
 if problem.minCost() is nonfinite, such as infinite or nan.

InverseCostFitnessFunction
public InverseCostFitnessFunction(IntegerCostOptimizationProblem<T> problem)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = 1.0 / (1.0 + problem.cost(s)  problem.minCost()). Parameters:
problem
 The optimization problem. Throws:
IllegalArgumentException
 if problem.minCost() equals Integer.MAX_VALUE or Integer.MIN_VALUE.

InverseCostFitnessFunction
public InverseCostFitnessFunction(OptimizationProblem<T> problem, double c)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = c / (c + problem.cost(s)  problem.minCost()). Parameters:
problem
 The optimization problem.c
 A constant which must be positive. Throws:
IllegalArgumentException
 if c is less than or equal to 0.0.IllegalArgumentException
 if problem.minCost() is nonfinite, such as infinite or nan.

InverseCostFitnessFunction
public InverseCostFitnessFunction(IntegerCostOptimizationProblem<T> problem, double c)
Constructs a fitness function that transforms the cost of solution s to fitness with the following transformation: fitness(s) = c / (c + problem.cost(s)  problem.minCost()). Parameters:
problem
 The optimization problem.c
 A constant which must be positive. Throws:
IllegalArgumentException
 if c is less than or equal to 0.0.IllegalArgumentException
 if problem.minCost() equals Integer.MAX_VALUE or Integer.MIN_VALUE.


Method Detail

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

getProblem
public Problem<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.

