Package org.cloudsimplus.heuristics
Class HeuristicAbstract<S extends HeuristicSolution<?>>
java.lang.Object
org.cloudsimplus.heuristics.HeuristicAbstract<S>
- Type Parameters:
S
- Theclass of solutions
the heuristic will deal with. It starts with an initial solution (usually random, depending on each sub-class implementation) and executes the solution search in order to find a satisfying solution (defined by a stop criteria)
- All Implemented Interfaces:
Heuristic<S>
- Direct Known Subclasses:
SimulatedAnnealingAbstract
public abstract class HeuristicAbstract<S extends HeuristicSolution<?>>
extends Object
implements Heuristic<S>
An abstract class for
Heuristic
implementations.- Since:
- CloudSim Plus 1.0
- Author:
- Manoel Campos da Silva Filho
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected ContinuousDistribution
int
getRandomValue
(int maxValue) Gets a random number between 0 (inclusive) and maxValue (exclusive).int
Gets the number of neighborhood searches by each iteration of the heuristic.double
protected final void
setBestSolutionSoFar
(S solution) Sets a solution as the current one.protected final void
setNeighborSolution
(S solution) Sets a solution as the neighbor one.void
setSearchesByIteration
(int searches) Sets the number of neighborhood searches by each iteration of the heuristic.protected void
setSolveTime
(double solveTime) Sets the time taken to solve the heuristic.solve()
Starts the heuristic to find a suboptimal solution.protected abstract void
Updates the state of the system in order to keep looking for a suboptimal solution.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cloudsimplus.heuristics.Heuristic
createNeighbor, getAcceptanceProbability, getInitialSolution, isToStopSearch
-
Method Details
-
getSolveTime
public double getSolveTime()- Specified by:
getSolveTime
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Returns:
- the time taken to finish the solution search (in seconds).
- See Also:
-
setSolveTime
protected void setSolveTime(double solveTime) Sets the time taken to solve the heuristic.- Parameters:
solveTime
- the time to set (in seconds)
-
getRandom
- Returns:
- a random number generator
-
updateSystemState
protected abstract void updateSystemState()Updates the state of the system in order to keep looking for a suboptimal solution. -
getRandomValue
public int getRandomValue(int maxValue) Description copied from interface:Heuristic
Gets a random number between 0 (inclusive) and maxValue (exclusive).- Specified by:
getRandomValue
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Parameters:
maxValue
- the max value to get a random number (exclusive)- Returns:
- the random number
-
solve
Description copied from interface:Heuristic
Starts the heuristic to find a suboptimal solution. After the method finishes, you can call theHeuristic.getBestSolutionSoFar()
to get the final solution.- Specified by:
solve
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Returns:
- the final solution
- See Also:
-
getBestSolutionSoFar
- Specified by:
getBestSolutionSoFar
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Returns:
- best solution found out up to now
-
getNeighborSolution
- Specified by:
getNeighborSolution
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Returns:
- latest neighbor solution created
- See Also:
-
setBestSolutionSoFar
Sets a solution as the current one.- Parameters:
solution
- the solution to set as the current one.
-
setNeighborSolution
Sets a solution as the neighbor one.- Parameters:
solution
- the solution to set as the neighbor one.
-
getSearchesByIteration
public int getSearchesByIteration()Gets the number of neighborhood searches by each iteration of the heuristic.- Specified by:
getSearchesByIteration
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Returns:
-
setSearchesByIteration
public void setSearchesByIteration(int searches) Sets the number of neighborhood searches by each iteration of the heuristic.- Specified by:
setSearchesByIteration
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Parameters:
searches
- the number of neighborhood searches to set
-