Functional Programming and Intelligent Algorithms


Week 13: The continuous GA

2 Exercises

2.1 Testing

You should test that the continuous GA for string learning works properly on a set of test strings. Create a test module called TestContinuousGA.hs to hold your code:

1module TestContinuousGA where The module should import the GA module: 1import ContinuousGA You should then implement a main function with the necessary steps to verify proper functionality of the GA: 1main :: IO () 
2main = do
For example, you could do something like the following: 1        -- select a target string 
2        -- obtain a PRNG g 
3        -- initialise a random population 
4        -- print the decoded population (list of candidate strings) 
5        -- evolve the population for itMax iterations 
6        -- print the decoded evolved population (list of evolved strings) 
7        -- print the decoded best chromosome found and its cost

To help you out, here is an example module implementing the steps listed above:

1module TestContinuousGA where 
3import ContinuousGA 
4import System.Random (newStdGen) 
6main :: IO () 
7main = do 
8        g <- newStdGen 
9        let (initPop, g’) = randPop g 
10        putStr ~Initial population decoded to strings:\n~ 
11        print $ decodePopulation initPop 
12        let newPopEvolved = fst $ evolvePop g itMax initPop 
13        putStr ~Final population decoded to strings:\n~ 
14        print $ decodePopulation newPopEvolved 
15        putStr ~Target:\n~ 
16        print target 
17        putStr ~Best solution:\n~ 
18        print $ (decodePopulation newPopEvolved) !! 0 
19        putStr ~Cost of solution:\n~ 
20        print $ chromCost target (newPopEvolved !! 0)

Experiment with algorithm settings such as

and discuss how your choice of GA settings affect the following:

for a number of different test strings, e.g.

If you modify your cost functions or implement other cost functions, examine the performance of the GA for each of these.

2.2 Solve your own problem

This exercise is about adapting the continuous GA to some other problem. Find a problem that a continuous GA can solve. A suitable problem can be a combinatorial problem such as string learning presented here, or the test functions given in the appendix of ?. You will need to think about how to encode the chromosomes, e.g., the sequence of genes could correspond to optimisation variables. You must also define new cost functions to evaluate the chromosomes. Much of the existing code can be reused.

7th April 2017
Robin T. Bye /