Package es.urjc.etsii.grafo.solution
Class Objective<M extends Move<S,I>,S extends Solution<S,I>,I extends Instance>
java.lang.Object
es.urjc.etsii.grafo.solution.Objective<M,S,I>
- Type Parameters:
S
- Solution classI
- Instance class
- Direct Known Subclasses:
Objective.SimpleObjective
public abstract class Objective<M extends Move<S,I>,S extends Solution<S,I>,I extends Instance>
extends Object
Represents an objective function to be optimized for a given problem. In general, an objective function is a function that takes a solution and returns a double value representing the quality of the solution.
In this class, we also include a method to evaluate the quality of a move, which is the difference or delta in the objective function value between the solution before applying the move and the solution after applying the move.
Objective functions can be of two types: MINIMIZE or MAXIMIZE. It is important to correctly set the type of the objective function, as it will affect the behavior of the algorithms.
In single objective optimization, usually there is a single objective to optimize. However, sometimes it can be useful to use secondary functions, for example when the solution landscape is flat.
Usage of objectives is left to the user discretion.
In multi-objective optimization, of course there are multiple objective functions.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
best
(double a, double b) bestSolution
(Iterable<S> list) bestSolution
(S s1, S s2) Comparator that orders solutions by qualityComparator
<? super Move<S, I>> Comparator that orders moves by qualityabstract double
abstract double
double
abstract FMode
getFMode()
abstract String
getName()
boolean
improves
(double a) boolean
isBetter
(double a, double b) boolean
boolean
boolean
isBetterOrEqual
(double a, double b) boolean
isBetterOrEqual
(S a, S b) boolean
isBetterOrEquals
(S a, double b) of
(String name, FMode fMode, ToDoubleFunction<S> evaluateSolution, ToDoubleFunction<M> evaluateMove) ofMaximizing
(String name, ToDoubleFunction<S> evaluateSolution, ToDoubleFunction<M> evaluateMove) ofMinimizing
(String name, ToDoubleFunction<S> evaluateSolution, ToDoubleFunction<M> evaluateMove)
-
Constructor Details
-
Objective
public Objective()
-
-
Method Details
-
ofMinimizing
public static <M extends Move<S,I>, Objective<M,S extends Solution<S, I>, I extends Instance> S, ofMinimizingI> (String name, ToDoubleFunction<S> evaluateSolution, ToDoubleFunction<M> evaluateMove) -
ofMaximizing
public static <M extends Move<S,I>, Objective<M,S extends Solution<S, I>, I extends Instance> S, ofMaximizingI> (String name, ToDoubleFunction<S> evaluateSolution, ToDoubleFunction<M> evaluateMove) -
of
public static <M extends Move<S,I>, Objective<M,S extends Solution<S, I>, I extends Instance> S, ofI> (String name, FMode fMode, ToDoubleFunction<S> evaluateSolution, ToDoubleFunction<M> evaluateMove) -
evalSol
-
evalMove
-
getFMode
-
getName
-
isBetterOrEquals
-
isBetterOrEqual
-
isBetterOrEqual
public boolean isBetterOrEqual(double a, double b) -
isBetter
-
isBetter
-
isBetter
public boolean isBetter(double a, double b) -
getBadValue
public double getBadValue() -
improves
public boolean improves(double a) -
comparator
Comparator that orders solutions by quality- Returns:
- a comparator that sorts solutions from best to worse
-
comparatorMove
Comparator that orders moves by quality- Returns:
- a comparator that sorts moves from best to worse
-
bestSolution
-
bestMove
-
best
public double best(double a, double b) -
bestMove
-
bestSolution
-