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 start 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:
SimulatedAnnealing
public abstract class HeuristicAbstract<S extends HeuristicSolution<?>> extends Object implements Heuristic<S>
A base class for
Heuristic
implementations.- Since:
- CloudSim Plus 1.0
- Author:
- Manoel Campos da Silva Filho
-
Field Summary
-
Method Summary
Modifier and Type Method Description S
getBestSolutionSoFar()
int
getNeighborhoodSearchesByIteration()
Gets the number of neighborhood searches by each iteration of the heuristic.S
getNeighborSolution()
protected ContinuousDistribution
getRandom()
int
getRandomValue(int maxValue)
Gets a random number between 0 (inclusive) and maxValue (exclusive).double
getSolveTime()
protected void
setBestSolutionSoFar(S solution)
Sets a solution as the current one.void
setNeighborhoodSearchesByIteration(int neighborhoodSearches)
Sets the number of neighborhood searches by each iteration of the heuristic.protected void
setNeighborSolution(S neighborSolution)
Sets a solution as the neighbor one.protected void
setSolveTime(double solveTime)
Sets the time taken to solve the heuristic.S
solve()
Starts the heuristic to find a suboptimal solution.protected abstract void
updateSystemState()
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:
Heuristic.solve()
-
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:
Heuristic.getBestSolutionSoFar()
-
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:
Heuristic.createNeighbor(HeuristicSolution)
-
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:
neighborSolution
- the solution to set as the neighbor one.
-
getNeighborhoodSearchesByIteration
public int getNeighborhoodSearchesByIteration()Gets the number of neighborhood searches by each iteration of the heuristic.- Specified by:
getNeighborhoodSearchesByIteration
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Returns:
-
setNeighborhoodSearchesByIteration
public void setNeighborhoodSearchesByIteration(int neighborhoodSearches)Sets the number of neighborhood searches by each iteration of the heuristic.- Specified by:
setNeighborhoodSearchesByIteration
in interfaceHeuristic<S extends HeuristicSolution<?>>
- Parameters:
neighborhoodSearches
- the number of neighborhood searches to set
-