Class HeuristicAbstract<S extends HeuristicSolution<?>>
java.lang.Object
org.cloudsimplus.heuristics.HeuristicAbstract<S>
- Type Parameters:
S- Theclass of solutionsthe heuristic will deal with. It starts with an initial solution (usually random, depending on each subclass implementation) and executes the search 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
-
Constructor Summary
ConstructorsConstructorDescriptionHeuristicAbstract(@NonNull ContinuousDistribution random, @NonNull Class<S> solutionClass) Creates a heuristic. -
Method Summary
Modifier and TypeMethodDescriptionintgetRandomValue(int maxValue) Gets a random number between 0 (inclusive) and maxValue (exclusive).protected final voidsetBestSolutionSoFar(S solution) Sets a solution as the current one.protected final voidsetNeighborSolution(S solution) Sets a solution as the neighbor one.protected voidsetSolveTime(double solveTime) Sets the time taken to solve the heuristic.solve()Starts the heuristic to find a suboptimal solution.protected abstract voidUpdates the state of the system to keep looking for a suboptimal solution.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.cloudsimplus.heuristics.Heuristic
createNeighbor, getAcceptanceProbability, getBestSolutionSoFar, getInitialSolution, getNeighborSolution, getSearchesByIteration, getSolveTime, isToStopSearch, setSearchesByIteration
-
Constructor Details
-
HeuristicAbstract
public HeuristicAbstract(@NonNull @NonNull ContinuousDistribution random, @NonNull @NonNull Class<S> solutionClass) Creates a heuristic.- Parameters:
random- a pseudo-random number generatorsolutionClass- reference to the generic class that will be used to instantiate heuristic solutions
-
-
Method Details
-
setSolveTime
protected void setSolveTime(double solveTime) Sets the time taken to solve the heuristic.- Parameters:
solveTime- the time to set (in seconds)
-
updateSystemState
protected abstract void updateSystemState()Updates the state of the system to keep looking for a suboptimal solution. -
getRandomValue
public int getRandomValue(int maxValue) Description copied from interface:HeuristicGets a random number between 0 (inclusive) and maxValue (exclusive).- Specified by:
getRandomValuein interfaceHeuristic<S extends HeuristicSolution<?>>- Parameters:
maxValue- the max value to get a random number (exclusive)- Returns:
- the random number
-
solve
Description copied from interface:HeuristicStarts the heuristic to find a suboptimal solution. After the method finishes, you can call theHeuristic.getBestSolutionSoFar()to get the final solution.- Specified by:
solvein interfaceHeuristic<S extends HeuristicSolution<?>>- Returns:
- the final solution
- 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.
-