object oriented programming assignment introduction dr. mike spann [email protected]

21
Object Oriented Programming Assignment Introduction Assignment Introduction Dr. Mike Spann Dr. Mike Spann [email protected] [email protected]

Upload: fay-charles

Post on 02-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Object Oriented Programming

Assignment IntroductionAssignment Introduction

Dr. Mike SpannDr. Mike Spann

[email protected]@bham.ac.uk

Page 2: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Assignment Introduction Aims/ObjectivesAims/Objectives

To produce a C# implementation of the To produce a C# implementation of the ANT colony optimisation algorithm ANT colony optimisation algorithm (ACO) and derivatives(ACO) and derivatives

To apply to the Travelling Salesman To apply to the Travelling Salesman ProblemProblem

Page 3: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

ANT algorithms

Page 4: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

ANT algorithms

Ants are practically blind but they still manage Ants are practically blind but they still manage to find their way to and from food. How do they to find their way to and from food. How do they do it?do it?

These observations inspired a new type of These observations inspired a new type of algorithm called algorithm called ant algorithmsant algorithms (or ant systems) (or ant systems)

These algorithms are very new (Dorigo, 1996) These algorithms are very new (Dorigo, 1996) and is still very much a research area where they and is still very much a research area where they are applied to the solution of hard discrete are applied to the solution of hard discrete optimization problemsoptimization problems

Page 5: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

ANT algorithms

Ant systems are a population based Ant systems are a population based approach. In this respect they is similar to approach. In this respect they is similar to genetic algorithmsgenetic algorithms

There is a population of ants, with each ant There is a population of ants, with each ant finding a solution and then communicating finding a solution and then communicating with the other antswith the other ants Communication is not peer to peer but Communication is not peer to peer but

indirect with the use of pheromoneindirect with the use of pheromone

Page 6: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

ANT algorithms Real ants can find the shortest path to a food source by Real ants can find the shortest path to a food source by

laying a pheromone traillaying a pheromone trail

The ants which take the shortest path, lay the largest The ants which take the shortest path, lay the largest amount of pheromone per unit timeamount of pheromone per unit time

Positive feedback reinforces this behaviour and more Positive feedback reinforces this behaviour and more ants take the shortest path resulting in more ants take the shortest path resulting in more pheromone being laidpheromone being laid

Page 7: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Travelling Salesman Problem

Classic discrete optimisation problemClassic discrete optimisation problem Salesman needs to visit all cities just once and Salesman needs to visit all cities just once and

return back homereturn back home Find the best route (minimum route length)Find the best route (minimum route length)

Page 8: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Travelling Salesman Problem

The TSP is a The TSP is a NP-hardNP-hard problem problem Essentially it means there is no polynomial Essentially it means there is no polynomial

time solution (complexity time solution (complexity O(NO(Nkk) ) ) nor can a ) nor can a solution be verified in polynomial timesolution be verified in polynomial time We would need to check the solution We would need to check the solution

over all possible routes to verify itover all possible routes to verify it One of many NP hard problemsOne of many NP hard problems

Page 9: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Travelling Salesman Problem N cities -> (N-1)!/2 routesN cities -> (N-1)!/2 routes

Small problem involving 29 cities in Small problem involving 29 cities in Western Sahara has 2x10Western Sahara has 2x102828 routes! routes!

Currently TSP’s involving 1000’s cities are Currently TSP’s involving 1000’s cities are being studiedbeing studied

You should restrict your algorithm to problems You should restrict your algorithm to problems with <1000 cities!with <1000 cities!

The ACO algorithm has proved to be an The ACO algorithm has proved to be an effective approach with performances close to effective approach with performances close to optimaloptimal

Page 10: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Applying the ACO algorithm to the TSP ACO is an iterative algorithm ACO is an iterative algorithm During each iteration a number of ants are During each iteration a number of ants are

released to search the ‘solution space’released to search the ‘solution space’ Typically the number of ants ~ number of citiesTypically the number of ants ~ number of cities

Each ant makes a probabilistic choice about its Each ant makes a probabilistic choice about its routeroute The higher the pheromone on an edge in the The higher the pheromone on an edge in the

TSP graph, the higher the chance of selecting TSP graph, the higher the chance of selecting that edgethat edge

Page 11: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Applying the ACO algorithm to the TSP

nodes allowed

1)(

1)(

)(

j ij

ij

ij

ij

ij

dt

dt

tP

i

j

ij

ddijij distance between cities distance between cities

i i and and jj ττijij the amount of the amount of

pheremone between cities pheremone between cities i i and and jj

ββ determines influence of determines influence of arc length over arc length over accumulated pheromoneaccumulated pheromone

Page 12: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Applying the ACO algorithm to the TSP After each ant has completed it’s route, the route After each ant has completed it’s route, the route

length for each ant is computed length for each ant is computed Assumes each ant has a local memory of where Assumes each ant has a local memory of where

it’s been unlike biological ants!it’s been unlike biological ants! The pheromone on the edges of each route are The pheromone on the edges of each route are

updated according to the route lengthupdated according to the route length Also, it is assumed that a certain amount of Also, it is assumed that a certain amount of

pheromone ‘evaporation’ takes place so that pheromone ‘evaporation’ takes place so that old routes are forgottenold routes are forgotten

Page 13: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Applying the ACO algorithm to the TSP

raten evaporatio

ant oflength route

)()1()1(

),( which

kL

L

Qtt

k

jiedgeusekants k

ijij

Page 14: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Improvements to the basic ACO algorithm The performance of the basic ACO is not greatThe performance of the basic ACO is not great

But definitely better than the Greedy algorithm!But definitely better than the Greedy algorithm! A number of improvements are possible which produce A number of improvements are possible which produce

closer to optimal solutionscloser to optimal solutions These include:These include:

Min-MaxMin-Max algorithm algorithm Rank orderRank order algorithm algorithm ElitistElitist algorithm algorithm Non-probabilistic transition Non-probabilistic transition

Also ‘local search’ algorithms can refine the solutionAlso ‘local search’ algorithms can refine the solution

Page 15: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Improvements to the basic ACO algorithm ‘‘Elitist’ algorithmElitist’ algorithm

Only update the pheromone on the Only update the pheromone on the currently optimum routecurrently optimum route

The pheromone on all edges still The pheromone on all edges still undergoes evaporationundergoes evaporation

Makes a big difference in performance over Makes a big difference in performance over the basic ACOthe basic ACO

Page 16: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Improvements to the basic ACO algorithm Non probablistic transitionNon probablistic transition

Choose a non-probabilistic transition rule according to some ‘annealing’ scheduleChoose a non-probabilistic transition rule according to some ‘annealing’ schedule Choose a random number 0<Choose a random number 0<q<1q<1 and some threshold parameter and some threshold parameter qq00(t)(t)

q< qq< q00(t) (t) probabilistic transition rule applied as beforeprobabilistic transition rule applied as before Otherwise, a deterministic transition rule is applied :Otherwise, a deterministic transition rule is applied :

)( maxarg 0 tqqPj k

ij

Page 17: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Improvements to the basic ACO algorithm qq00(t) (t) defines an annealing scheduledefines an annealing schedule

qq00(t) (t) small for small small for small tt, the normal , the normal

probabilistic transition rule is favouredprobabilistic transition rule is favouredExplorationExploration

qq00(t) (t) approaches 1 for increasing approaches 1 for increasing t, t, the the

deterministic transition rule is favoureddeterministic transition rule is favouredExploitationExploitation

Page 18: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Improvements to the basic ACO algorithm Local searchLocal search

Exchanges edges to reduce the edge lengthExchanges edges to reduce the edge length‘‘k-optk-opt’ algorithms’ algorithmsCan impose a huge computational Can impose a huge computational

burden for burden for k>3k>3 I implemented a simple approach which I implemented a simple approach which

requires a single comparison at each noderequires a single comparison at each node

Page 19: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Improvements to the basic ACO algorithm

a

bc d

e

f

city Move

cbadfe

dfecba

Page 20: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Assessment Programming report (deadlines are on the Programming report (deadlines are on the

handout)handout) Follow closely the marking pro-formaFollow closely the marking pro-forma The report should contain discussions about object The report should contain discussions about object

orientation, code re-useability, object interaction, orientation, code re-useability, object interaction, algorithm performance and comparisons (close to algorithm performance and comparisons (close to ‘optimal’?)‘optimal’?)

A formal design discussion is not expected but A formal design discussion is not expected but informal class/object diagrams and pseudo-code informal class/object diagrams and pseudo-code should be usedshould be used

Page 21: Object Oriented Programming Assignment Introduction Dr. Mike Spann m.spann@bham.ac.uk

Demo