quick review of tsp algorithms - jlmartin.ku.edu

48
Quick Review of TSP Algorithms I Brute force: Examine all (N - 1)! Hamilton circuits individually; choose the cheapest one. Finds the optimal answer but is very inefficient. I Nearest-Neighbor Algorithm (NNA): Pick a reference vertex. At each step, walk to the nearest vertex not already visited. I Repetitive Nearest-Neighbor Algorithm (RNNA): Perform the NNA from every possible reference vertex, obtaining N different Hamilton circuits. Choose the cheapest one.

Upload: others

Post on 23-Jul-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Quick Review of TSP Algorithms - jlmartin.ku.edu

Quick Review of TSP Algorithms

I Brute force: Examine all (N − 1)! Hamilton circuitsindividually; choose the cheapest one.

— Finds the optimal answer but is very inefficient.

I Nearest-Neighbor Algorithm (NNA): Pick a referencevertex. At each step, walk to the nearest vertex notalready visited.

I Repetitive Nearest-Neighbor Algorithm (RNNA):Perform the NNA from every possible reference vertex,obtaining N different Hamilton circuits. Choose thecheapest one.

Page 2: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

The Cheapest-Link Algorithm (CLA) is a bit different.

Instead of starting at a reference vertex and moving to thenearest neighbor at each step, we “start in the middle.”

That is, if there is a cheap edge that you know you will wantto use eventually — make sure you use it!

At each stage of the algorithm, pick the cheapest edgeavailable, regardless of what its endpoints are.

Of course, all the edges you pick have to come together toform a circuit.

Page 3: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Here’s a more precise description of the Cheapest-LinkAlgorithm.

I Find the cheapest edge that you haven’t already added.

I Add it to the list of edges to use.

I Keep doing this until you have a Hamilton circuit.

I Make sure you add exactly two edges at each vertex. (Inother words, don’t put a third edge at a vertex, and don’tclose the circuit too early.)

Page 4: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Here’s a more precise description of the Cheapest-LinkAlgorithm.

I Find the cheapest edge that you haven’t already added.

I Add it to the list of edges to use.

I Keep doing this until you have a Hamilton circuit.

I Make sure you add exactly two edges at each vertex. (Inother words, don’t put a third edge at a vertex, and don’tclose the circuit too early.)

Page 5: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Here’s a more precise description of the Cheapest-LinkAlgorithm.

I Find the cheapest edge that you haven’t already added.

I Add it to the list of edges to use.

I Keep doing this until you have a Hamilton circuit.

I Make sure you add exactly two edges at each vertex. (Inother words, don’t put a third edge at a vertex, and don’tclose the circuit too early.)

Page 6: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Here’s a more precise description of the Cheapest-LinkAlgorithm.

I Find the cheapest edge that you haven’t already added.

I Add it to the list of edges to use.

I Keep doing this until you have a Hamilton circuit.

I Make sure you add exactly two edges at each vertex. (Inother words, don’t put a third edge at a vertex, and don’tclose the circuit too early.)

Page 7: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Here’s a more precise description of the Cheapest-LinkAlgorithm.

I Find the cheapest edge that you haven’t already added.

I Add it to the list of edges to use.

I Keep doing this until you have a Hamilton circuit.

I Make sure you add exactly two edges at each vertex. (Inother words, don’t put a third edge at a vertex, and don’tclose the circuit too early.)

Page 8: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Here is an example of designing a tour of Australia using theCheapest-Link Algorithm.

(Warning: The figure is not quite to scale!)

Page 9: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Start by finding the shortest edge (Sydney–Canberra).

Page 10: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Now find the next shortest edge (Perth–Albany).

Page 11: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

And the next shortest (Alice Springs–Uluru). . .

Page 12: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

and the next shortest (Hobart–Melbourne). . .

Page 13: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

and the next shortest (Canberra-Melbourne).

Page 14: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

(UL)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

The next shortest edge is actually Adelaide–Melbourne, but wecan’t use it because Melbourne already has two edges.

Page 15: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

So instead we include the next shortest edge (Cairns-Mackay).

Page 16: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Page 17: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Page 18: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Page 19: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Page 20: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Page 21: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Page 22: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

The edges we add get longer and longer.

Page 23: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Page 24: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

Page 25: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru(UL)

The last edge is very long indeed. . .

Page 26: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

(UL)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

. . . but finally the circuit is complete.

Page 27: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Here is the same example, but with the links shown in aspreadsheet rather than pictorially.

(This way we don’t have to worry about the figure not beingto scale!)

At each stage, we look for the smallest number we haven’t yetused (always being careful not to draw three edges to anyvertex, or to close the circuit prematurely).

Page 28: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

The distance table

Page 29: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Step 1: Add the cheapest link: Sydney–Canberra

Page 30: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Step 2: Add the next cheapest link: Albany–Perth

Page 31: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Step 3: Add the next cheapest link: Alice Spings–Uluru

Page 32: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Step 4: Add the next cheapest link: Hobart–Melbourne

Page 33: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Step 5: Add the cheapest link: Canberra-Melbourne

Page 34: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

CN and ML both have two edges, so we are done with them

Page 35: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Keep adding links until the circuit is complete

Page 36: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Keep adding links until the circuit is complete

Page 37: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Keep adding links until the circuit is complete

Page 38: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Keep adding links until the circuit is complete

Page 39: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Two more links to go!

Page 40: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Next-to-last step: add AD–AL

Page 41: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Last step: close the circuit

Page 42: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

Here is the output of the Cheapest-Link Algorithm.

(UL)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

Page 43: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

It is not optimal since it involves crossings. . .

(UL)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

Page 44: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

. . . this route is an improvement.

(UL)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

Page 45: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

But it is unclear whether the new route is optimal.

(UL)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

Page 46: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Cheapest-Link Algorithm

For example, maybe this route is even better.

(UL)

(HO)

(KU)

(MK)

(DA)

(AL)

(AS)

(CS)

(BR)

(BM)Broome

Melbourne (ML)

Adelaide (AD)

Uluru

Hobart

Canberra

Sydney

Brisbane

Mackay

Cairns

Mount Isa

Alice Springs

Kununurra

Darwin

Perth

Albany

(SY)(PE)

(MI)

(CN)

Page 47: Quick Review of TSP Algorithms - jlmartin.ku.edu

Comparing Algorithms

Randomly chosen Hamilton circuit: 40,680 kmHamilton circuit using NNA/Sydney: 21,049 kmHamilton circuit using RNNA: 18,459 kmHamilton circuit using CLA: 18,543 km

So CLA did not find an optimal circuit. But it is a reasonablemethod that might perform better in a different example.

Might there be an even better Hamilton circuit? Canwe find it without having to use brute force?

Page 48: Quick Review of TSP Algorithms - jlmartin.ku.edu

The Bad News

There is no known algorithm to solve theTSP that is both optimal and efficient.

I Brute-force is optimal but not efficient.

I NNA, RNNA, and CLA are efficient but not optimal.

I Maybe no optimal, efficient algorithm exists. . . or maybeit’s out there but no one has found it yet. We don’t know!