AbstractClasses
Class HyperHeuristic

java.lang.Object
  extended by AbstractClasses.HyperHeuristic
Direct Known Subclasses:
ExampleHyperHeuristic1, ExampleHyperHeuristic2, ExampleHyperHeuristic3

public abstract class HyperHeuristic
extends java.lang.Object

HyperHeuristic is the superclass of all hyper-heuristic classes which will be entered into the competition. It provides the methods to manage the time limit, and to run the hyper-heuristic. This class ensures that competitors only need to implement the hyper-heuristic strategy, and not be concerned with further implementation details. The timing elements of this class always use CPU seconds, obtained by the ThreadMXBean.getCurrentThreadCpuTime() method. This minimises the effect of other minor processes which are running on the machine in the background.

Author:
mvhj, jav, tec

Field Summary
protected  java.util.Random rng
          The random variable which can be used by subclasses of HyperHeuristic
 
Constructor Summary
HyperHeuristic()
          Constructs a new HyperHeuristic object with an unknown random seed.
HyperHeuristic(long seed)
          Constructs a new HyperHeuristic object, and creates a new random number generator using the seed provided.
 
Method Summary
 double getBestSolutionValue()
          Gets the best solution found before the time limit expires.
 long getElapsedTime()
          Returns the elapsed time since the hyper-heuristic began the search process.
 double[] getFitnessTrace()
          Gets an array of the fitness of the best initial solution and the fitness of the best solutions found at 100 checkpoints through the search.
 long getTimeLimit()
          Returns the time limit in milliseconds (CPU time).
protected  boolean hasTimeExpired()
          Tests if the time limit has been reached and it records the best solution value found so far, for scoring in the competition.
 void loadProblemDomain(ProblemDomain problemdomain)
          Assigns the problem domain to be solved by this hyper-heuristic, when the run method is called.
 void run()
          Runs the hyper-heuristic on the current problem domain to produce a solution.
 void setTimeLimit(long time_in_milliseconds)
          Sets the time limit for the hyper-heuristic in milliseconds.
protected abstract  void solve(ProblemDomain problem)
          Solves the instance of the problem domain which is provided as an argument.
abstract  java.lang.String toString()
          returns the name of this hyper-heuristic
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rng

protected java.util.Random rng
The random variable which can be used by subclasses of HyperHeuristic

Constructor Detail

HyperHeuristic

public HyperHeuristic(long seed)
Constructs a new HyperHeuristic object, and creates a new random number generator using the seed provided. The HyperHeuristic will then behave the same way when using an identical seed, but only if the rng variable is used for every random operation.

Parameters:
seed - A seed for the random number generator

HyperHeuristic

public HyperHeuristic()
Constructs a new HyperHeuristic object with an unknown random seed. The HyperHeuristic will run, but the exact behaviour cannot be replicated.

Method Detail

setTimeLimit

public void setTimeLimit(long time_in_milliseconds)
Sets the time limit for the hyper-heuristic in milliseconds. This method must be called before the run() method.

Parameters:
time_in_milliseconds - The time limit for the hyper-heuristic in milliseconds (CPU time)

getTimeLimit

public long getTimeLimit()
Returns the time limit in milliseconds (CPU time).


getElapsedTime

public long getElapsedTime()
Returns the elapsed time since the hyper-heuristic began the search process. This time is initialised when the run() method is called.


getBestSolutionValue

public double getBestSolutionValue()
Gets the best solution found before the time limit expires. This variable is updated each time the hasTimeExpired() method is called. Therefore, this method should only be called after the hasTimeExpired() method has been called at least once.

Returns:
the objective function value of the best solution found within the time limit

getFitnessTrace

public double[] getFitnessTrace()
Gets an array of the fitness of the best initial solution and the fitness of the best solutions found at 100 checkpoints through the search. Before a run, the timelimit is divided by 100, to obtain the length of the interval between checkpoints. The fitness at index 0 is the fitness of the best solution found when the first call is made to the hasTimeExpired() method. If the hyper-heuristic only uses one solution in memory, then the first fitness value recorded in the trace will be the fitness of the initial solution. If the hyper-heuristic uses multiple solutions in memory, and initialises more than one solution before the first call to hasTimeExpired(), then the first fitness value recorded in the trace will be the best of those. The fitness at index 1 is after the first checkpoint. The fitness at index 100 is the last recorded fitness of the best solution before the time limit is exceeded.

Returns:
an array of 101 double values, which represent the fitness of the best solution found so far, at 101 checkpoints in the search process, including the initial solution and the last recorded best solution before the time limit is exceeded.

hasTimeExpired

protected boolean hasTimeExpired()
Tests if the time limit has been reached and it records the best solution value found so far, for scoring in the competition. This method should be called as often as possible by an implemented hyper-heuristic within its solve() method, to ensure that the time limit is not exceeded by a significant amount. It is important to note that each call to hasTimeExpired() registers the current best solution found, and it is this record that will be used to determine the best solution found within the time limit. This is a mechanism which is intended to ensure that there is NO BENEFIT to exceeding the time limit.

Returns:
Returns true if the time limit has been exceeded, and false if it has not been exceeded.

loadProblemDomain

public void loadProblemDomain(ProblemDomain problemdomain)
Assigns the problem domain to be solved by this hyper-heuristic, when the run method is called. This method must be called before the run() method.

Parameters:
problemdomain - The problem domain to be solved by this hyper-heuristic.

run

public void run()
Runs the hyper-heuristic on the current problem domain to produce a solution. The hyper-heuristic will run for the length of time specified by the user to the setTimeLimit() method.


solve

protected abstract void solve(ProblemDomain problem)
Solves the instance of the problem domain which is provided as an argument. The exact instance and time limit can be set via methods in the problem domain class. This method must be implemented by hyper-heuristic objects, as it specifies the hyper-heuristic's strategy.

Parameters:
problem - The problem that is to be solved.

toString

public abstract java.lang.String toString()
returns the name of this hyper-heuristic

Overrides:
toString in class java.lang.Object