Module org.cicirello.chips_n_salsa
Package org.cicirello.search.problems
Class CostFunctionScaler<T extends Copyable<T>>
java.lang.Object
org.cicirello.search.problems.CostFunctionScaler<T>
- Type Parameters:
T
- The type of object used to represent candidate solutions to the problem.
- All Implemented Interfaces:
OptimizationProblem<T>
,Problem<T>
public final class CostFunctionScaler<T extends Copyable<T>>
extends Object
implements OptimizationProblem<T>
This is a wrapper class for
OptimizationProblem
objects that enables scaling all cost
values by a positive constant. This transformation doesn't change what solution is optimal, and
doesn't change the topology of the search space. It simply scales the cost values. For example,
if you want to explore the effects of the range of the cost function on the behavior of a search
algorithm, you can use this class to scale the cost values of a problem whose cost function range
is known.
Note that this does not scale the results of the value(T)
method, which will continue to
return the actual value of the candidate solution (see its documentation for details).
-
Constructor Summary
ConstructorDescriptionCostFunctionScaler
(OptimizationProblem<T> problem, double scale) Constructs the CostFunctionScaler. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Computes the cost of a candidate solution to the problem instance.double
minCost()
A lower bound on the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution.double
Computes the value of the candidate solution within the usual constraints and interpretation of the problem.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cicirello.search.problems.OptimizationProblem
costAsDouble, getSolutionCostPair, isMinCost
-
Constructor Details
-
CostFunctionScaler
Constructs the CostFunctionScaler.- Parameters:
problem
- The original problem specification.scale
- The scale factor, which must be positive. All cost values of the original problem will be multiplied by scale.- Throws:
IllegalArgumentException
- if scale ≤ 0.
-
-
Method Details
-
cost
Computes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution.In the case of the CostFunctionScaler, the cost values are all multiplied by the scale factor.
- Specified by:
cost
in interfaceOptimizationProblem<T extends Copyable<T>>
- Parameters:
candidate
- The candidate solution to evaluate.- Returns:
- The cost of the candidate solution. Lower cost means better solution.
-
minCost
public double minCost()A lower bound on the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution. The default implementation returns Double.NEGATIVE_INFINITY.In the case of the CostFunctionScaler, the cost values are all multiplied by the scale factor.
- Specified by:
minCost
in interfaceOptimizationProblem<T extends Copyable<T>>
- Returns:
- A lower bound on the minimum theoretical cost of the problem instance.
-
value
Description copied from interface:OptimizationProblem
Computes the value of the candidate solution within the usual constraints and interpretation of the problem.- Specified by:
value
in interfaceOptimizationProblem<T extends Copyable<T>>
- Parameters:
candidate
- The candidate solution to evaluate.- Returns:
- The actual optimization value of the candidate solution.
-