HeuristicAbstract

public abstract class HeuristicAbstract<S extends HeuristicSolution<?>> implements Heuristic<S>

A base class for Heuristic implementations.

Author:

Manoel Campos da Silva Filho

Parameters:
  • <S> – The class 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)

Constructors

HeuristicAbstract

HeuristicAbstract(ContinuousDistribution random, Class<S> solutionClass)

Creates a heuristic.

Parameters:
  • random – a random number generator
  • solutionClass – reference to the generic class that will be used to instantiate heuristic solutions

Methods

getBestSolutionSoFar

public S getBestSolutionSoFar()

getNeighborSolution

public S getNeighborSolution()

getNeighborhoodSearchesByIteration

public int getNeighborhoodSearchesByIteration()

Gets the number of neighborhood searches by each iteration of the heuristic.

getRandom

protected ContinuousDistribution getRandom()
Returns:a random number generator

getRandomValue

public int getRandomValue(int maxValue)

getSolveTime

public double getSolveTime()

setBestSolutionSoFar

protected final void setBestSolutionSoFar(S solution)

Sets a solution as the current one.

Parameters:
  • solution – the solution to set as the current one.

setNeighborSolution

protected final void setNeighborSolution(S neighborSolution)

Sets a solution as the neighbor one.

Parameters:
  • neighborSolution – the solution to set as the neighbor one.

setNeighborhoodSearchesByIteration

public void setNeighborhoodSearchesByIteration(int neighborhoodSearches)

Sets the number of neighborhood searches by each iteration of the heuristic.

Parameters:
  • neighborhoodSearches – the number of neighborhood searches to set

setSolveTime

protected void setSolveTime(double solveTime)

Sets the time taken to solve the heuristic.

Parameters:
  • solveTime – the time to set (in seconds)

solve

public S solve()

updateSystemState

protected abstract void updateSystemState()

Updates the state of the system in order to keep looking for a suboptimal solution.