Examples
Class ExampleHyperHeuristic1

java.lang.Object
  extended by AbstractClasses.HyperHeuristic
      extended by Examples.ExampleHyperHeuristic1

public class ExampleHyperHeuristic1
extends HyperHeuristic

This class presents an example hyper-heuristic demonstrates basic functionality. it first determines how many low level heuristics exist for the problem domain to be solved. it applies a random low level hyper-heuristic to the current solution. if there is an improvement in solution quality the new solution is accepted. if the new solution is worse than the current solution, it is accepted with a 50% probability.

the easiest way to create your own strategy is to modify the solve method of this class.

we suggest that the reader goes through the example code of this class, and then reads the notes below, which provide further clarification.

It is important to note that every call to the hasTimeExpired() method records the best fitness function value found so far by the hyper-heuristic. This is a mechanism which ensures that only solutions found within the time limit are used for scoring, and it is intended to ensure that there is NO BENEFIT to exceeding the time limit. Every time a low level heuristic is applied with ProblemDomain.applyHeuristic(), the ProblemDomain object updates the "best fitness found so far". However, this is ONLY recorded for scoring purposes when the hasTimeExpired() method is called. For this reason it is beneficial to put as many hasTimeExpired() checks into your hyper-heuristic code as possible. Ideally, for many hyper-heuristics, this will be after every application of a low level heuristic, rather than at the end of each iteration (every iteration may contain multiple low level heuristic applications). In the extreme case, if there are no calls to the hasTimeExpired() method, then the hyper-heuristic will iterate for as long as the user wants. It could obtain a much better solution than the other competitors by using much more time. However, this solution will never be recorded for scoring purposes because the hasTimeExpired() method was never called. While we have taken these reasonable steps to negate any advantage from exceeding the time limit, we admit that we may not have thought of everything! Therefore we issue this warning: attempting to obtain advantage by exceeding the time limit is definitely not in the spirit of the competiton, and will result in disqualification.

we only initialise the solution at index 0 in the memory, we do not need to initialise the solution at index 1 because a solution is subequently created and placed there when the randomly selected low level heuristic is applied. the solution at index 0 needs to be initialised because the chosen heuristic must be applied to it. if it is not initialised then there would be nothing to modify.

using two indices of memory is the standard method to handle a single point search. it is not the only way however. in this example we treat 0 as the current solution, and a new candidate solution is stored temporarily at index 1. This is just the method by which we choose to handle the solutions, but it is up to the user to manage the solution memory. there is technically no reason why we cannot set the memory size to ten, and only use indices 9 and 10.


Field Summary
 
Fields inherited from class AbstractClasses.HyperHeuristic
rng
 
Constructor Summary
ExampleHyperHeuristic1(long seed)
          creates a new ExampleHyperHeuristic object with a random seed
 
Method Summary
 void solve(ProblemDomain problem)
          This method defines the strategy of the hyper-heuristic
 java.lang.String toString()
          this method must be implemented, to provide a different name for each hyper-heuristic
 
Methods inherited from class AbstractClasses.HyperHeuristic
getBestSolutionValue, getElapsedTime, getFitnessTrace, getTimeLimit, hasTimeExpired, loadProblemDomain, run, setTimeLimit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExampleHyperHeuristic1

public ExampleHyperHeuristic1(long seed)
creates a new ExampleHyperHeuristic object with a random seed

Method Detail

solve

public void solve(ProblemDomain problem)
This method defines the strategy of the hyper-heuristic

Specified by:
solve in class HyperHeuristic
Parameters:
problem - the problem domain to be solved

toString

public java.lang.String toString()
this method must be implemented, to provide a different name for each hyper-heuristic

Specified by:
toString in class HyperHeuristic
Returns:
a string representing the name of the hyper-heuristic