Testers

The GIalgorithm here was implemented to be tester independent. The script is heavily designed for the hash function but the algorithm and the components implemening testing, selection, mutation and crossover are all tester agnostic so the tester can be changed out.

The Tester component is defined as a template and super class for testers. It works with the trainingPerformance component so any correctly implemented Tester can be applied to generate fitness scores for the algorithm.

A Tester component has 4 global parameters, name (default values) - description:

  1. maxTime - an integer defining the cut off time for tests in milliseconds to prevent halting problems.

  2. halted (false) - boolean flag to indicate whether the code should be stopped because it has exceeded its time limit.

  3. finished (false) - boolean flag to indicate if the code has finished executing.

  4. current_test (0) - integer value used to identify test being run to match timeLimit threads to testing threads so they don’t interfere with later tests.

They have 3 required functions:

  1. setData(int time, char testFile[], bool perf) - Sets the data to be used for test.

  2. runTest(IDC com, char file[], int j, opt bool penalty) - Runs testing and returns a speed (could be swapped for other integer value of interest).

  3. fitnessScore(int speed, int length, int metric) - Takes speed and token length of code (can be replaced with other integer value of interest) and a metric to return an integer score for the code.

There are a further 4 functions which should be implemented in a component inheriting from Tester. These are not required to allow their parameters to be changed to suit a particular implementation.

  1. setParameters - A particular tester will have its own global parameters which will be set in the outer script using this function.

  2. timeLimit - A function which can be found in the hashTest function example with is used to impose the time limit on the code test. Even if not testing for speed this is needed to prevent a halting problem.

  3. A test function - The runTest function is just intended to be a wrapper which allows compatibility with the trainingPerformance component. So a seperate function, which will run threaded with the timeLimit function is needed for actually testing the code.

An example of a full testing component is given in functions/hashTest.dn which can be used as a template for any new Tester.