Try out your code produced in the last programming exercise

advertisement
Try out your code produced in the last
programming exercise
Find the maximum of the following function:
f(x,y)=exp(-0.7*(x+2)*(x+2))*exp(-0.9*y*y)+2*exp(-(x5)*(x-6))*exp(-(y-2)*(y-2))
for values –10<x,y<10.
Create two versions:
(1) binary representation on e.g. 2x16 bits;
(2) real-valued representation.
Run a few runs and describe the differences in
search behavior. (e.g. how long does it take to find
the optimum, does it always find the global
optimum, how close it gets to the optimum)
Implement it without self-adaptation for now.
Send a half page text about your findings to ECdiscussions.
For lazy Java users, here is some old Java code and comments written by Thorsten:
The code is written to be as simple as possible, to make it easy to read. A number of
things could be done more elegant, modular, and efficient - so don't think this is how you
have to do it. For example, the individual class should probably allow any type of linear
representation - so that you don't have to change it when you go from binary to real. You
could then use factories to create and initialize the individuals - rather than hard-coding
this into the EA as is done here. Also, you would probably define an interface for
mutation and crossover, and then just use different classes to implement different
versions.
A. Binary Representation
A helper class with some random functions is at
http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/binary/RandomHelper.java.html This contains methods for random coin flips,
and uniform, normal, and Cauchy distributed numbers.
The individuals are stored in this class:
http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/binary/Individual.java.html
And the Evolutionary Algorithm itself is here:
http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/binary/EA.java.html
Finally the Fitness Function:
http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/binary/FitnessFunction.java.html
This also does the conversion from binary to real values - there is no need to do the
inverse conversion anywhere in the code !
B. Real Representation
The individual class has changed slightly, to allow for the different genotype
representation:
http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/real/Individual.java.html
The fitness function does not need to convert from binary anymore:
http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/real/FitnessFunction.java.html
The EA now uses different initialization, crossover and mutation methods (but stays the
same otherwise):
http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/real/EA.java.html
And the random helper has not changed:
http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/real/RandomHelper.java.html
Exercise. (3-rd year exam question in 2001)
The payoff matrix of the N-player iterated prisoner’s
dilemma game can be defined as follows:
Player A:
C
D
Number of cooperators among the
remaining N-1 players
0
1
2
N-1
0
2
4
…
2(N-1)
1
3
5
…
2(N-1)+1
All players in an N-player game are treated equally.
The payoff matrix is symmetrical to all players.
Design a co-evolutionary algorithm for learning to play
the iterated 4-player prisoner’s dilemma game.
Exercise/Question. Suppose you have a genotype of
length n. Describe in words, what is the difference
between n-1 point crossover and uniform crossover?
Exercise/Question. Different selection operators
produce different selection pressure. Explain this in
words, in terms of exploration versus exploitation.
Give some examples.
Programming exercise
Traveling Salesman Problem
Aim: to learn to work with order-based
representations in evolutionary algorithms.
Task:
Write an evolutionary algorithm that finds the
minimum tour on a 52-city problem. The location of
the towns is given on the next page. Each location is
has two coordinates, so you can easily compute the
distances between them.
Hints:
You can use any of the methods discussed in Lecture
8.
The ‘Handbook of Evolutionary Computation’ also
contains a description of edge-map based crossover,
but it is non-greedy version.
Questions:
- What is the minimum distance?
- How far can you get with crossover only, and
with mutation only?
Submission procedure:
Email half page text on your findings in plain text
format to ‘EC-discussions’.
private static double[][] towns = new double [][]
{ { 565.0, 575.0}, {25.0, 185.0}, {345.0, 750.0},
{945.0, 685.0}, {845.0, 655.0}, {880.0, 660.0},
{25.0, 230.0}, {525.0, 1000.0}, {580.0, 1175.0},
{650.0, 1130.0}, {1605.0, 620.0}, {1220.0, 580.0},
{1465.0, 200.0}, {1530.0, 5.0}, {845.0, 680.0},
{725.0, 370.0}, {145.0, 665.0}, {415.0, 635.0},
{510.0, 875.0}, {560.0, 365.0}, {300.0, 465.0},
{520.0, 585.0}, {480.0, 415.0}, {835.0, 625.0},
{975.0, 580.0}, {1215.0, 245.0}, {1320.0, 315.0},
{1250.0, 400.0}, {660.0, 180.0}, {410.0, 250.0},
{420.0, 555.0}, {575.0, 665.0}, {1150.0, 1160.0},
{700.0, 580.0}, {685.0, 595.0}, {685.0, 610.0},
{770.0, 610.0}, {795.0, 645.0}, {720.0, 635.0},
{760.0, 650.0}, {475.0, 960.0}, {95.0, 260.0},
{875.0, 920.0}, {700.0, 500.0}, {555.0, 815.0},
{830.0, 485.0}, {1170.0, 65.0}, {830.0, 610.0},
{605.0, 625.0}, {595.0, 360.0}, {1340.0, 725.0},
{1740.0, 245.0}};
Download