Você está na página 1de 21

1

Formulations for the Traveling Salesman Problem


Drive 1 car via n cities, minimising travel.
History: Dantzig, Fulkerson, ohnson !a!er: "#", cutting
!lanes.
$ook, %ar!, &evin: com!le'ity theory.
Some formulations for the TSP:
(ssignment.
(ssignment ) tight subtours *DF+.
(ssignment ) loose subtours *,T-+.
Symmetric.
Flo. *Svestka+.
Ste!s *Dantzig+.
/e't time: solution metho0s.
(ssignment ) cuts.
(ssignment ) "#".
,in s!anning tree.
1
The Travelling Salesman $ontest
Here are the 0istances bet.een 2 cities. Fin0 the shortest tour.
1 1 3 4 5 6 7 8
2
1 41.9 53.9 61.2 196.3 86.1 78.1 74.5
47.7
1 15.8 17.1 62.6 69.8 48.1 46.6
36.4
3 31.2 67.3 71.3 57.2 58.6
52.3
4 53.2 44.1 31.1 12.2
18.8
5 37.9 31.5 37.6
67.9
6 14.5 14.3
32.5
7 5.1
35.9
8
39.1
This is all the 0ata you nee0 to solve the !roblem e'actly.
The !roblem is easy to 0escribe, but very har0 to solve e'actly.
( gra!hical 0is!lay is on the ne't !age.
3
9
39
69
29
9 39 69 29
:ast
/orth
1
3
1
5
4
2
8
7
6
9
39
69
29
9 39 69 29
:ast
/orth
1
3
1
5
4
2
8
7
6
The TSP, gra!hically. "est: 187.1.
4
:arly history of the TSP
1239s;59s: Publicise0 in the math # <= community by ,errill
Floo0.
1248: Po!ularise0 at =(/D $or!., a >.S. military thinktank,
.hich hel!e0 0evelo!e0 <=.
1254: ?Solution of a large;scale traveling;salesman !roblem,@
Dantzig, Fulkerson # ohnson, J. of Ops Research of America.
(t =(/D, they solve0 a 42;city TSP to o!timality.
DF# thought a nearly o!timal tour coul0 be im!rove0,
an0 then o!timality coul0 be guarantee0,
by a00ing Aust a fe. cuts.
DF# .ere the first to use cuts an0 "#"
for integer !rogramming.
5
Bhy is the TSP im!ortantC
Ste!hen $ook
1271 $ook, 1271 %ar!, 1273 &evin: computational complexity.
Ho. har0 is a !roblem to solve, as a function of the in!ut 0ataC
Df Problem 1 converts easily to Problem 1 # vice versa,
then Problem 1 is as easy or har0 as Problem 1.
Some !roblems are
easy: shortest !ath, min s!anning tree, assignment.
im!ossible: given a com!uter !rogram # in!ut, .ill it sto!C
har0: TSP E because no ?goo0@ algorithms have been foun0.
,any har0 !roblems, such as Aob sho! sche0uling,
can be converte0 algebraically to # from the TSP.
( goo0 TSP algorithm .ill be goo0 for other har0 !roblems.
The TSP is easy to state, takes no math backgroun0 to un0erstan0,
an0 no great talent to fin0 feasible solutions.
DtFs fun, an0 invites recreational !roblem solvers.
6
1 general strategies for the TSP
Given that the TSP is har0, .hat can .e 0oC
1+ (!!ro'imate. >se heuristicsH
/earest neighbour, nearest merger,
&ove # /orback *angles+, &in;%ernighan *3;
o!t+,
min s!anning tree ) shortcuts *$hristofi0es+,
an0 many others.
1+ S!en0 a lot of time at it. :numerationH
$utting !lanes,
branch # boun0,
0ynamic !rogramming.
BeFll 0o *1+ here.
/e't: formulations for the TSP.
7
(ssignment !roblem ; easy, naturally integer.
Dn0ices: i I teacher, j I course.
Parameters: c
ij
I value if teacher i is assigne0 to course j.
Jariables: x
ij
I 1 if teacher i is assigne0 to course j, else 9.
,o0el (P: 1+ ,a'
i

j
c
ij
x
ij
subAect to
1+
j
x
ij
I 1, for all i,
3+
i
x
ij
I 1, for all j,
4+ x
ij
K9,1L, for all i,j.
:'!lanation: 1+ ,a'imise value of assignments.
1+ (ssign each teacher i to one course.
3+ (ssign each course j to one teacher.
Almost the TSP. Ds (P a !ossible formulation for the TSPC
Dn0ices: i, j I city.
Parameter: c
ij
I cost to go from city i to city j.
Jariables: x
ij
I 1 if .e 0rive from city i to city j, else 9.
8
The (P formulation .onFt .ork.
BhatFs"est formulation. BhatFs
.rongC
(t least .e have a lo.er boun0 of 9.
2
So Aust leave out variables x
ii
.
D reset the variables on the
0iagonal so they are fi'e0 to
9.
&ooks goo0. <r 0oes itC
( better lo.er boun0 of
172.4.
19
Be have subtours.
<o!s. Ho. 0o .e get ri0 of theseC
1. $an you .rite (,P& co0e to !rint the tour from an o!timal
solutionC
1. $an you .rite (,P& co0e to !rint a subtour of an infeasible
solutionC
3. Do .e nee0 an integer solution to fin0 subtoursC
3
1
4
5
6
7
8
2
1
11
Bays to break subtours: 1
n
subtour constraints.
The Dantzig, Fulkerson # ohnson *DF+ mo0el.
Dn0ices, !arameters, # 0ecision variables as before.
,inimise total cost: min
i

j
c
ij
x
ij
,
:nter each city once:
i
x
ij
I 1 for all j.
&eave each city once:
j
x
ij
I 1 for all i.
Subtour breaking constraints:
i,jS
x
ij
MSM E 1, for every subset S.
"inary integrality: x
ij
K9, 1L for all i, j.
For the subtour sho.n, a00: x
3,1
) x
1,4
) x
4,3
1. Bhat are the othersC
(fter solving again .ith the ne. constraints, more subtours
a!!ear.
For a large TSP, .e may nee0 many subtour breaking constraints.
Dn the .orst case, .e may nee0 1
n
subtour breaking constraints.
/e't .eek, .e .ill see a .ay to generate these constraints.
The solution becomes fractional, so .e also nee0 to 0o "#".
Ho.ever, every solution gives a lo.er boun0 on the o!timum.
3
1
4
11
Bays to break subtours: ,T- mo0el
Dn0ices # !arameters as before.
Jariables: x
ij
I 1 if .e 0rive from city i to city j, else 9.
u
i
I number of cities visite0 at city i.
,inimise total cost: min
i

j
c
ij
x
ij
,
:nter each city once:
i
x
ij
I 1 for all j.
&eave each city once:
j
x
ij
I 1 for all i.
Subtour breaking: u
i
) 1 u
j
) n*1 x
ij
+, for i I 1, N, n, i j, j I 1,
N,n,
x
ij
K9, 1L for all i, jO u
i
9 for all i.
Fe.er constraints, but har0er to solveH The &P rela'ation is not as
tight.
<kay for small !roblems, but is ba0 for large ones.
=elate0 variations are a bit tighter.
=ef: $. :. ,iller, (. B. Tucker, an0 =. (. -emlin, ?Dnteger !rogramming
formulations an0 traveling salesman !roblems,@ J. ACM, 7 *1269+, !!. 316E312.
3
1
4
13
BeFll use this 0ata for our (,P& mo0els.
param N := 12;
param C := [*,*] :
1 2 3 4 5 6 7 8 9 10 11 12:=
1 . 26 40 34 35 48 30 23 48 17 20 29
2 26 . 64 61 59 78 54 47 50 29 28 33
3 40 64 . 3 5 8 10 15 24 30 33 39
4 34 61 3 . 3 10 8 13 26 28 30 35
5 35 59 5 3 . 13 5 10 29 25 28 33
6 48 78 8 10 13 . 18 23 16 38 39 33
7 30 54 10 8 5 18 . 5 34 20 23 28
8 23 47 15 13 10 23 5 . 38 15 18 23
9 48 50 24 26 29 16 34 38 . 23 21 16
10 17 29 30 28 25 38 20 15 23 . 3 8
11 20 28 33 30 28 39 23 18 21 3 . 5
12 29 33 39 35 33 33 28 23 16 8 5 .;
14
param N integer > 2; N!m"er #$ n#%e&
&et N#%e& #r%ere% := '1..N(;
&et )r*& := 'i in N#%e&, + in N#%e&: i ,> +(;
param C'-i,+. in )r*&(;
/ar 0 '-i,+. in )r*&( "inar1;
/ar ! 'N#%e&( >= 0;
minimi2e 3#!r4engt5: &!m '-i,+. in )r*&( C[i,+]*0[i,+];
&!"+e*t t# 6egree1 'i in N#%e&(: &!m'-i,+. in )r*&( 0[i,+]=1;
&!"+e*t t# 6egree2 'i in N#%e&(: &!m'-+,i. in )r*&( 0[+,i]=1;
&!"+e*t t# N#7!"t#!r1 '-i,+. in )r*&: i,>+ an% i>=2 an% +>=2(:
![i] 8 ![+] 9 N*0[i,+] ,= N 8 1;
&!"+e*t t# N#7!"t#!r2 'i in N#%e&: i >= 2(:
![i] ,= N 8 1 8 -N 8 2.*0[1,i];
&!"+e*t t# N#7!"t#!r3 'i in N#%e&: i >= 2(:
![i] >= 1 9 -N 8 2.*0[i,1];
(,P& solution
![1] ![4] ![12] ![6] ![2] ![11] ![9] ![3] ![7] ![10] ![5] ![8]
0 1 2 3 4 5 6 7 8 9 10 11
1,4 4,12 12,6 6,2 2,11 11,9 9,3 3,7 7,10 10,5 5,8 8,1
,T- formulation in (,P&, P6 secs.
15
Parts of the ,T- mo0el in &in0o
min 500 01,1 9 70.9 01,2 9 41.6 01,3 9 29.1 01,4
9 17.1 01,5 9 56.1 01,6 9 55.6 01,7 9 7.3 01,8
...
9 104 012,10 9 39.4 012,11 9 500 012,12
&!"+e*t t#
3] 02,1 9 03,1 9 04,1 9 05,1 9 06,1 9 07,1
9 08,1 9 09,1 9 010,1 9 011,1 9 012,1 = 1
4] 01,2 9 01,3 9 01,4 9 01,5 9 01,6 9 01,7
9 01,8 9 01,9 9 01,10 9 01,11 9 01,12 = 1
...
25] 01,12 9 02,12 9 03,12 9 04,12 9 05,12 9 06,12
9 07,12 9 08,12 9 09,12 9 010,12 9 011,12 = 1
26] 012,1 9 012,2 9 012,3 9 012,4 9 012,5 9 012,6
9 012,7 9 012,8 9 012,9 9 012,10 9 012,11 = 1
27] 12 02,2 ,= 11
28] 12 02,3 9 !2 8 !3 ,= 11
29] 12 02,4 9 !2 8 !4 ,= 11
30] 12 02,5 9 !2 8 !5 ,= 11
...
143] 12 012,8 8 !8 9 !12 ,= 11
144] 12 012,9 8 !9 9 !12 ,= 11
145] 12 012,10 8 !10 9 !12 ,= 11
146] 12 012,11 8 !11 9 !12 ,= 11
147] 12 012,12 ,= 11
en%
inte 01,1
inte 01,2
...
Df .e go from city 1 to
city 5, then u1 ) 1I
u5.
16
The symmetric TSP
Symmetric TSP: c
ij
I c
ji
.
Dn0ices: i, j I city.
Parameter: c
ij
I cost to go from city i to city j.
Jariables: x
ij
I 1 if .e 0rive from city i to city j, else 9,
0efine0 only for i<j. Half as many variables as the
asymmetricH
,inimise total cost: min
i

jQi
c
ij
x
ij
,
:nter each city once:
jRi
x
ji
)
jQi
x
ij
I 1 for all i.
Subtour breaking:
i,jS
x
ij
MSM E 1, for each subset S.
"inary integrality: x
ij
K9, 1L for all i, j.
The home.ork is a symmetric TSP.
The asymmetric TSP, c
ij
c
ji
, is more realistic. BhyC
2
1
S3
S3
2
1
S8
S3
17
Ho. 0oes the ro. 1 summation .orkC
,o0el: 1. ,in T
n
iI1
T
n
jIi)1
c
i,j
x
i,j
,
1. T
iI1
jE1
x
i,j
) T
n
ij)1
x
j,i
I 1, for all j.
3. T
i,jS
x
i,j
U MSME 1, for every subset S,
4. x
i,j
K9,1L for all i,an0 j: jQi.
The variables into city 5 are: '15, '15, '35, '45, '65, '75, '85, '25.
The variables out of city 5 are: '51, '51, '53, '54, '56, '57,
'58, '52.
Since costs are symmetric, c
ij
I c
ji
, letVs 0ro! half the variables.
For x
ij
, reWuire i R j. (llo. only the variables going out.
Be nee0 only variables '15, '15, '35, '45, '56, '57, '58, '52.
The meaning is not ?Go in@ or ?come out@, but ?use this arc@.
The summation makes sure that .e cover only the variables .e
nee0.
'15 ) '15 ) '35 ) '45 ) '56 ) '57 ) '58 ) '52 I 1.
18
( flo. .ith gain mo0el of the TSP
Parameter: f I gain in flo. from city i to city j.
Decision variables: x
ij
I 1 if .e 0rive from city i to city j, else 9.
y
ij
I flo. from city i to city j.
1. ,in total cost: min
i

j
c
ij
x
ij
,
1. (rrive in each city:
jXi
y
ji
Y 1, for i I 1,N,n,
3. Flo. .ith gain of f:
jXi
y
ij
Z
jXi
y
ji
I f, for i I 1,N,n,
4. <nly n !ositive vars:
i

j
x
ij
U n, car0inality constraint,
5. Force the y
ij
vars: y
ij
U *1 ) n!f+x
ij
for all i, j,
6. /onnegative, binary: y
ij
Y 9 for all i, j, x
ij
K9, 1L for all i, j.
This formulation flo.s f ?material@ from city to city.
(s f a!!roaches 9, the solution a!!roaches the o!timum.
Har0 to solve because of *4+, the car0inality constraint.
<ther ro.s can be a00e0 to tighten the mo0el.
=ef: ( Svestka, ?( continuous variable re!resentation of the TSP,@
Math "ro#, v15, 1278, !!111;113.
12
37:, 7/e&t;a $#rm!4ati#n. <e$: =) 7/e&t;a, >) *#ntin!#!& /aria"4e
repre&entati#n #$ t5e 37:,? @at5 :r#g, /15, 1978, pp2118213.
param N integer > 2; N!m"er #$ n#%e&
&et N#%e& #r%ere% := '1..N(;
&et )r*& := 'i in N#%e&, + in N#%e&: i ,> +(;
param C'-i,+. in )r*&(;
param A := 0.01;
/ar 0 '-i,+. in )r*&( "inar1; /ar 1 '-i,+. in )r*&( >= 0;
minimi2e 3#!r4engt5: &!m '-i,+. in )r*&( C[i,+] * 0[i,+];
&!"+e*t t# 6eman%1 'i in N#%e&: i>=2(: &!m'-i,+. in )r*&( 1[+,i] >= 1;
&!"+e*t t# A4#B1 'i in N#%e&: i>=2(:
&!m '-i,+. in )r*&( 1[i,+] 8 &!m '-i,+. in )r*&( 1[+,i] = A;
&!"+e*t t# 3#ta40: &!m '-i,+. in )r*&( 0[i,+] ,= N;
&!"+e*t t# )r*gain '-i,+. in )r*&(: 1[i,+] ,= -1 9 N*A.*0[i,+];
35e&e r#B& tig5ten t5e m#%e4.
&!"+e*t t# 6eman%0 'i in N#%e&: i>=2(: &!m'-i,+. in )r*&( 0[+,i] = 1;
&!"+e*t t# A4#B0 'i in N#%e&: i >= 2(:
&!m '-i,+. in )r*&( 0[i,+] = &!m '-i,+. in )r*&( 0[+,i];
&!"+e*t t# 7tart0: &!m 'i in N#%e&: i >= 2( 0[1,i] = 1;
&!"+e*t t# 7tart1: &!m 'i in N#%e&: i >= 2( 1[1,i] = 1;
(,P& solution
11,8 18,7 17,5 15,4 14,3 13,6 16,9 19,12 112,11 111,10 110,2 12,1
1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.1 1.11
01,8 08,7 07,5 05,4 04,3 03,6 06,9 09,12 012,11 011,10 010,2 02,1
TSP gain mo0el in
(,P&.
(bout 7 secs.
19
( formulation of ste!s for the TSP, Dantzig
Dn0ices: i, j, $ I city, t I ste!.
Jariables: x
ijt
I 1 if .e 0rive from city i to city j at ste! t, else 9.
,inimise total cost: min
i

t
c
ij
x
ijt
,
Flo. in I flo. out:
i
x
i,j,t
E
$
x
j,$,t)1
I 9 for all j, an0 tI1,N,n.
Go to each city once:
j

t
x
ijt
I 1, for iI1,N,n.
"inary integrality: x
ijt
K9, 1L for all i, j, t.
This is tighter than the earlier formulations.
>nfortunately this reWuires n
3
variables.
( 59;city !roblem .oul0 reWuire 115,999 variablesH
/e't: solution metho0s.
(ssignment ) cuts.
(ssignment ) "#".
,in s!anning tree.
11
37: &tep&. <e$ Linear Progg & Extensions, 6ant2ig, 1963;
param N integer > 2; N!m"er #$ n#%e&
&et N#%e& #r%ere% := '1..N(;
&et )r*& := 'i in N#%e&, + in N#%e&, ; in N#%e&: i ,> +(;
param C'i in N#%e&, + in N#%e&: i ,> +(;
/ar 0 '-i,+,;. in )r*&( "inar1;
minimi2e 3#!r4engt5: &!m'-i,+,;. in )r*&: i,>+( C[i,+]*0[i,+,;];
&!"+e*t t# 6eman% 'i in N#%e&(: &!m'-i,+,;. in )r*&( 0[i,+,;] = 1;
&!"+e*t t# Cn% 'i in N#%e&(:
&!m '+ in N#%e&: + ,> i( 0[+,i,N]
= &!m '; in N#%e&: ; ,> i( 0[i,;,1];
&!"+e*t t# 7tep 't in N#%e&, + in N#%e&: t ,= N 8 1(:
&!m 'i in N#%e&: i ,> +( 0[i,+,t]
= &!m '; in N#%e&: ; ,> +( 0[+,;,t91];
(,P& solution
8,1,1 1,1,1 1,19,3 19,11,4 11,11,5 11,2,6 2,6,7 6,3,8 3,4,2 4,5,19 5,7,11
7,8,11
TSP ste! mo0el in (,P&. (bout 7 secs.

Você também pode gostar