Vous êtes sur la page 1sur 23

TSPinSpreadsheetsaGuided

Tour
RasmusRasmussen

Abstract
Thetravellingsalesmanproblem(TSP)isawellknownbusinessproblem,andvariantslikethemaximum
benefitTSPorthepricecollectingTSPmayhavenumerouseconomicapplications.Wearelookingatseveral
differentvariantsofTSP;allsolvedinspreadsheets,notusingtailoredsolversforTSP.Astheseproblemsare
NPhard,solvingthoseusingstandardLP/MIPsolvershasbeenregardedfeasibleonlyforverysmallsized
problems.However,acarefulconsiderationofthespreadsheetlayoutmayfacilitateefficientsoftware
utilisation.Forrealworldproblemsthiscanhaveconsiderableeffects,andwiththerecentadvancementsin
solverengines,problemspreviouslyregardedasbigarenoweasilysolvableinspreadsheets.Thispaper
showsyouhow;andhowtheflexibilityofspreadsheetsmakesitaconvenienttoolsolvingmanyvariantsof
TSP,wheretailoredsolverssimplywouldnotfit.
JELclassification:C61,Z00

1. Introduction
Afteraformalstatementoftheproblem,threedifferentspreadsheetmodelswillbeillustrated.The
flexibilityofspreadsheetswillalsobedemonstrated,aswillhowspreadsheetlayoutmayhelpinmaking
anefficientproblemformulation,inadditiontohelpingtoclearlycommunicateanddisplaythe
solution.Thedirectpermutationapproachispresentedfirst,applyingintegervariablestodescribethe
sequenceofthevisits.Thedirectpermutationapproachfitssmallproblemswell,andrequiresverylittle
workafterdatahasbeenobtained.Noconstraintstoeliminatesubtoursareneeded,buttheproblemis
nonlinearandnonsmooth,requiringheuristicsolvers.Second,anetworkformulationispresented,
wherebinaryvariablesareusedtomakealinearformulationoftheproblem.Anefficientspreadsheet
layoutispresentedfornoncompletegraphs.Thirdlyanassignmentformulationispresented,applying
aspreadsheetlayoutmoresuitableforcompletegraphs.
VariantsofTSPnotfittingtailoredTSPsoftwarearealsosolved.Inadditionsomeconfiningsideeffects
ofcommonsubtoureliminatingconstraintsarediscussed,particularlywhenmultiplevisitsarerequired.

2. ThestandardTSP
Travellingsalesmanproblems(TSP)areeasytodescribe:asalesmanneedstovisitallhiscustomers
locatedindifferentcitiesinhisregion,andhewouldliketofindthecheapesttourthatwillassurethat
allcitieshavebeenvisited.UnfortunatelyTSPisnotsoeasytoformulate,andrelativelyhardtosolve.
Whenmakingamathematicalformulationoftheseproblemswewillforthemostpartuseanetwork
framework.Thecitiesarethencallednodes,andtheroadsconnectingthecitiesarecalledarcs.See
GutinandPunnen(2007)forafulltreatmentofTSPanditsvariants.
ThesetofnodestobevisitedaredefinedasN={1,2,...,n}wherenisthetotalnumberofnodes
(referredtoasthesizeofaTSP),andthesetofarcsconnectingthenodesisdefinedasA={(i,j):i,jN,

InternationalReviewofEconomicsEducation

ij},wherethepair(i,j)indicatesthearcbetweennodeiandj.AstandardassumptioninTSPisto
assumedirectlinksbetweeneverypairofnodes,usuallyreferredtoasacompletegraph.Thegraph
consistingofthenodesNandarcsAisthenconnected;thereisaconnectionorpathfromanynodeto
anyothernodeinthegraph.Thebasicstandardassumptionistorestrictthenumberofvisitstoexactly
oneforeachnode.Whythesalesmanisnotallowedtovisitanodemorethanonceisnotobvious.One
canspeculatethatsucharequirementmakesiteasiertodevelopsolutionprocedures,therebyfitting
theproblemtothetoolsathand.AcommondefinitionofthesetofdecisionvariablesisX{xij:i,jN,
ij}wherexij=1ifthesalesmantravelsfromnodeitoj(nodeiisvisitedimmediatelybeforenodej),
and0otherwise.ThecostmatrixisdefinedasC={cij:i,jN,ij}andusuallyassumedtobepositive,
wherecijrepresentsthecostoftraversingfromnodeitonodej.InstandardTSPacommonassumption
isthatthesquarecostmatrixissymmetric,cij=cji,thecostisthesameinbothdirections.Another
standardassumptionistoassumethetriangleinequality;cij+cjkciki,j,kN,thedirectconnection
betweentwonodesisalwaysthecheapest.
OnebasicassumptioninTSPistoassumethatthesalesmanhastoreturntothenodewherehestarts
thetour;thisnodeisusuallyreferredtoasthebasecityordepot.Thisassumptioniscalledaclosed
tour.Foraclosedtouranynodecanbeselectedasthestartingnode,butforpracticalreasonsnode1is
settobethestartingnode.Node1isthenthebasecityordepot.
ForastandardTSPthereisalwaysafeasiblesolution(asacompletegraphisalwaysconnected),andwe
canchooseanynodetostart(asthetourisclosedandallnodesarevisited).Therearealways
alternativeoptimalsolutions;thetourcangoineitherdirection(asthecostsaresymmetric).Andinthe
optimaltour(s)everynodeisvisitedonlyonce(becauseofthetriangleinequality,andtheobjectiveis
alwaysminimisation).

3. VariantsofTSP
Quitealotofreallifeproblemsdonotfittheseassumptions.OftenwemustallowforthesetAnot
beingcomplete,incaseswheresomenodesdonothavedirectlinkstoallothernodes.Graphsthatare
notcompletearenolongerguaranteedtobeconnected,andfordisconnectedgraphsthereisno
feasiblesolution.Inreallifewealsohavetoallowforcijcji,thecostoftravellingfromnodeitojmay
notbethesameastravellingfromjtonodei.Thisrepresentstheasymmetrictravellingsalesman
problem(ATSP),andimpliesdirectedarcs.Similarlyitisnotalwayscheapesttotravelthedirectlink
fromnodeitonodek,sometimesitmaybecheapertotravelvianodej.Thuswemustallowforthe
triangleinequalitynottoapply.Thebasicstandardassumptiontorestrictthevisitstoexactlyonefor
eachnodemayalsobeskipped;TSPwithmultiplevisitsisreferredtoasTSPM,asinGutinandPunnen
(2007).
Ofcoursethereasonforthesalesmantomakethetouristoderivesomebenefitfromvisitingthe
nodes.ThenletB={bj:jN},wherebjisthebenefitfromvisitingnodej.Forsuchproblemswehave
themaximumbenefittravellingsalesmanproblem(MBTSP);seeMalandrakiandDaskin(1993).Another
variantisthepricecollectingTSP(orPCTSP),seeGutin(2007).
Sometimesthesalesmandoesnothavetoreturntothebase,andrelaxingsucharequirementiscalled
anopentour.Foranopentouritmaybeadvantageoustobeabletoselecttheendingnodeaspartof
theproblemsolution,butthismayincreasetheproblemsizeforsometypesofformulations,exceptfor
thedirectpermutationapproach.
Thereisawideselectionofliteratureontheseproblems,andseveralvariantsofproblemformulations.
Wewillgrouptheformulationsintwoclasses:theassignmentformulationsandtheflowformulations.
Further,ineachgroupthemodelsvaryaccordingtowhichassumptionsaremade,mostnotably
whetheracompletegraphisassumed.

95

Fulltitleofthepresentarticle:doubleclicktoeditthis

4. AssignmentformulationofTSP
Fortheclosedtouranassignmentformulationcouldbeofthefollowingform:
n

Minimize cij xij

(1)

=1 , j N

(2)

=1 , i N

(3)

(4)

i =1 j =1

x
i =1

ij

x
j =1

ij

xij {0,1} , i, j N

Inadditionsubtoureliminationconstraints(SECs)areneeded.Constraints(2)and(3)arethestandard
assignmentconstraints.Theobjectivein(1)willminimisethetotalcostalongallthearcsusedto
completethetour.However,aswrittenthisformulationassumesacompletegraph,andifthedataare
beingarrangedinasquarematrixwillalsoincludethediagonal.Foracompletegraphtheonlyarcsthat
donotexistarerelatedtotheselfloopvariablexi,i(alongthediagonal).Thereforeitusuallyismore
convenienttoexcludethesevariablesbyanewconstraint(5),insteadofexcludingtheminthe
definitionofthesetX.Thisconveniencecomesatthecostofincreasedproblemsize(bothintermsof
variablesandconstraints).Foracompletegraphthefollowingconstraintwillfixthediagonalinasquare
nmatrixofthebinaryvariablesxijequaltozero:

xi ,i = 0 i N

(5)

Adifferentapproachtorectifythis,andallowforinstancesofnoncompletegraphs;istosetthecostcij
sufficientlylargefornonexistingarcs,therebypreventingthemfromenteringthefinalsolution.
Howeverthisisnotafoolprooftrick.Inaconnectedgraphthereisapathfromanynodetoanyother
nodeinthegraph,andacompletegraphisalwaysconnected,andthushasafeasiblesolution.Non
completegraphsmaynotbeconnected(disconnected),andwillassuchhavenofeasiblesolution.A
highcostfornonexistingarcsisthennoguaranteeforthesesarcstobeexcludedinthefinalsolution.
Thereforeanotherstrategyistosetanewparameter:eij=1ifnodeiisdirectlyconnectedtonodej,
otherwise0;andreplaceconstraint(5)with(6):

xij eij , i , j N

(6)

Thisformulationdoesnotrequireacompletegraphandallowsforasymmetriccostsandalsoforthe
triangleinequalitynottoapply,butunfortunatelyithassomeflaws.Iftheassumptionofacomplete
graphisnotsatisfied(andthereforeconstraint(6)isrequired),thenafeasiblesolutionforaclosedtour
mayrequiresomenodestobevisitedtwice,breakingthe=requirementinconstraint(2).
Thelimitationofvisitingeachnodeexactlyoncemayalsocausedifficultiesevenforproblemswitha
completegraph,ifthetriangleinequalityisnotsatisfied.Thisrequirementwilleffectivelyprohibithub
likesolutions,evenwhensuchsolutionsarethemostcosteffective.Aproblemformulationthat
excludessuchpossibleoptimalsolutionsisgenerallynotrecommended.

96

InternationalReviewofEconomicsEducation

5. FlowformulationofTSP
Aflowformulationoftheclosedtour,thatexplicitlyconsidersvalidconnectionsonly,canbemadeafter
redefiningC={ci,j:(i,j)A}andX{xi,j:(i,j)A}.Thisformulationwillthusworkevenwhenthe
graphisnotcomplete:

Minimize

( i , j ) A

(7)

(8)

xk , j k N

(9)

(10)

xi , j 1 j N

xi , k =

i : ( i , k ) A

i : ( i , j ) A

ci , j xi , j

j : ( k , j ) A

xi , j {0,1} ( i , j ) A

OfcourseSECsarealsorequired.Theobjective(7)willminimisethetotalcostofthetour,only
consideringvalidarcs.Constraint(8)statesthatthesalesmanhastoarriveeachnodeatleastonce.
Constraint(9)statesthatthesalesmanhastoleaveeachnodeasmanytimesashearrivethenode.By
usinginsteadof=in(8),weavoidthepossibilityofmakingtheprobleminfeasiblefornoncomplete
graphswheresomenodesneedtobevisitedtwice,andwedonotexcludehublikeoptimalsolutions
ifthetriangleinequalitydoesnotapply.

6. FlowformulationofopentourTSP
FortheopentourformulationweaddtheparametersD={di:iN}wherediisthenetdemandin
nodei;anddi=1forthestartnode(thebasecityisnumberednode1);di=+1fortheendnode,for
thetransitorintermediatenodesdi=0.Theopentourformulationcanthenbestatedas:

(11)

xi , j 1 j > 1 N

(12)

xi , k

( i , j ) A

i : ( i , j ) A

i : ( i , k ) A

ci , j xi , j

Minimize

j : ( k , j ) A

xk , j = d k k N

xi , j {0,1} ( i , j ) A

(13)

(14)

WemustaddSECstocompletetheTSPformulation.Theobjectivein(11)isidenticalto(7).Constraint
(12)issimilarto(8),exceptthatwedonotrequirethesalesmantoarrive/returntothestartingnode1.
Constraints(13)requirethesalesmantoleavethestartingnodeonemoretimethanentering,enterthe
stoppingnodeonemoretimethanleaving,andleaveanyintermediatenodeasoftenasarrivingthe
node.Byremovingconstraint(12)wehavethecommonshortestpathproblem.Iftheendnodeisnot
specified,thediparametersmaybeconvertedtobinaryvariables(exceptforthestartnode),requiring
theirsumtoequal1.

97

Fulltitleofthepresentarticle:doubleclicktoeditthis

7. Subtoureliminatingconstraints(SECs)
AkeypartofaTSPistomakesurethetouriscontinuous,thatthearcsarelinkedfromthebasecityall
thewaytoeverycityvisited.Withoutsuchconstraintswequiteoftenwillgetsolutionscontaining
degeneratetoursbetweenintermediatenodesandnotconnectedtothebasecity.TheoriginallySECs
wasformedin1954byDantzigFulkersonJohnson(DFJ)(seeDantzig,FulkersonandJohnson,1954):

iS jS

i, j

S 1, S N \ {1}, S

(15)

Unfortunatelythisintroducesanexponentialnumberofconstraints,andbecomesimpracticalevenfor
smallsizedproblems.AdifferentSECproposedin1960byMillerTuckerZemlin(MTZ)(seeMiller,
TuckerandZemlin,1960)introducesonlyamaximum1of(n2)2constraints,atthedisadvantageofa
weakLPrelaxation:

ui u j + 1 ( n 1) (1 xi , j ) ( i, j ) A, : i, j 1

2 ui n i > 1 N

(16)

In(16)anewsetofvariablesU={ui:iN,i1}isrequired.Theuiarearbitraryrealnumbers,butcan
berankedtononnegativeintegers,representingthesequencethenodesarebeingvisited.For
conveniencewemayaddu11(node1isthebasecity),andlimittherangeofui,thushelpingthe
optimisationsoftware(seealsoPataki(2003)):

(17)

TheMTZSECswillbeusedinthispaper,andhavethefollowingproperties:
node1isrequiredtobethebasecity;
theymakesurethateverycityvisitedbelongstoatourconnectedtothebasecity,thereby
eliminatingsubtours;
theyallownodestobevisitedmorethanonce(unlessotherconstraintspreventsuchasolution);
theydonotrequireallnodesbeingvisited(unlessotherconstraintsmakesuchrequirements);
theyallowunidirectionalarcstobeutilisedinbothdirectionsonthesametour.

Foraclosedtourvisitingallnodesthebasenodecanalwaysbechosenarbitrarily.Afundamental
weaknessofMTZSECsisthatfeasibilityandfinalsolutionmaydependonwhichnodeisselectedasthe
basecity.TheMTZSECsmayfailtofindafeasiblesolutionevenifsuchexists,andtheymayfailtofind
theglobaloptimalsolution.Problemswithfeasibilitymayoccurinnoncompletegraphs,whereall
feasiblesolutionsrequiresomenodestobevisitedtwice.Problemsfindingtheglobaloptimalsolution
mayoccurincompletegraphswherethetriangleinequalitydoesnotapply,andwheretheglobal
optimalsolutionrequiressomenodestobevisitedmorethanonce.Itisthereforeimportanttobe
awareofthesetwosituationswhereapplyingtheMTZSECsmaymakethefinalsolutionsensitiveasto
whichnodeisselectedasthestartingnode.Theywillneverfailiftheglobaloptimalsolutionvisitseach
nodeonlyonce.

8. ClosedTSPinacompletegraph
AsanexampleofaTSPinacompletegraphweshallusethefollowingexample.Asupplyshipisserving
10oilrigsatsea.Thebaseislocatedatcoordinates(0,0),andtherigsarelocatedasdisplayedinFigure
1

Inasquarennmatrix;thefirstrow,firstcolumnandthediagonalareexcluded.

98

InternationalReviewofEconomicsEducation

1.Assumingopenseathedistancesbetweenanypairofnodes(oilrigs)canbecalculatedasstraight
lines(ignoringthefactthatthesealevelisnotflat).ThisisastandardsymmetricTSPwithacomplete
graphwherethetriangleinequalityapplies.DataistakenfromRagsdale(2001).

Figure1Locationsoftheoilrigstovisit

9. Adirectpermutationapproach
Inthissimpleformtheproblemistofindtheorderforeachnodeinthesequenceofthetourthat
minimisesthetotaldistance(cost).Ifthesupplyshiptakesthetourbasedontherignumbers:012...
9100;thetotaldistanceis205.67.Weseektheorderorpermutationthatminimisesthetotal
distance.Thisdirectapproachisveryeasytoimplementinspreadsheets,asdisplayedinFigure2.

Figure2SpreadsheetfordirectpermutationofTSP

99

Fulltitleofthepresentarticle:doubleclicktoeditthis

Table1:FormulasforspreadsheetinFigure2
Cell

Formula

Copiedto

Name/Task

G3

=SQRT((INDEX($C$3:$D$13;$F3+1;1)
INDEX($C$3:$D$13;G$2+1;1))^2
+(INDEX($C$3:$D$13;$F3+1;2)
INDEX($C$3:$D$13;G$2+1;2))^2)

G3:Q13

CalculateEuclediandistances
betweenanypairofnodes

D17

=INDEX($G$3:$Q$13;C16+1;C17+1)

D18:D27

Costonaleg

D28

=SUM(D17:D27)

Totalcost

C17:C26

Sequence

G16

=INDEX($B$3:$D$13;$C16+1;2)

G17:G27

Avisitednodesxcoordinate

H16

=INDEX($B$3:$D$13;$F16+1;3)

H17:H27

Avisitednodesycoordinate

Figure3SolversettingsforthespreadsheetinFigure2

Thespreadsheetisorganisedintwoparts.Theupperpartholdsatableofthecoordinatesforthe
nodes,andacorrespondingtablecalculatingthedistances.Thelowerpartholdsatableofthetour
sequenceandthecostofeachleg,andacorrespondingtablewiththecoordinatesofeachleg,to
facilitateaplotofthetour.Thetableofthetoursequencestartsatthebase.Notethatnodenumber0
isusedforthedepotinthisexample,tofacilitateuseoftheAlldifferentconstraintinSolver.(Atrial
versionofSolverisavailableatwww.solver.com.)Theproblemistoselectwhichnodetogotonextin
thesequence(headingSequenceinFigure2).Thelastleghastoreturntothebase.Theminimum
totaldistance/costof122.77isachievedbythetoursequence0946572810130(orreverse).To
modelanopentoursimplydeleterow27inthesheet.Figure4displaystheoptimalopentour,which
hasacostof103.58.
Thescatterplotconsistsoftwoseries.Oneseriesisaplotofthenodes(C3:D13inFigure2),with
markersbutnoline.Thesecondseriesisthetour(G13:H27inFigure2),withnomarkersandaline.
100

InternationalReviewofEconomicsEducation

Figure4TheopenTSPsolution

BoththespreadsheetandtheSolversettingsareverysimple.Wehave10decisionvariables(numberof
nodeslessthedepot),namedSequenceinthespreadsheet.TheobjectiveintheSolversettingsisto
minimisethevalueinthecellnamedTotal_cost,andtheonlyconstraintisthatthevariablesmustbe
alldifferent.Thealldifferentconstraintsetsthevariablestointegersrangingfrom1tothenumberof
variables,andallaredifferent.(ThistypeofconstraintisnotavailableintheStandardSolverthatships
withExcelpriortoExcel2010,butisintroducedintheeducationalversionofSolver,includedinmany
textbooks.)
TheuseoftheIndexfunctioninExceltolookupthecostateachlegmakestheobjectivefunctionnon
smooth,becausethedecisionvariablesareusedasargumentsintheIndexfunction.Anintegernon
smoothproblemisnoteasytosolve,andisdefinitelynotthepreferredformforlargeproblems.Inthis
casethePremiumSolverPlatform(PSP)selectstheOptQuestsolverengine,andSolverspendslessthan
twosecondsinfindingtheoptimaltour(theAutoStopoptionforOptQuestwasincreasedfrom100to
1000iterationstoavoidaprematureending).Asthissolverengineappliesheuristics,itcannot
guaranteethataglobaloptimalsolutionhasbeenfound.Whensuchproblemsbecomelarge,thisnon
linearapproachisnolongerefficient.Wewillthereforeintroducethelinearformulation,whichwillbe
appliedintherestofthepaper.Alsonotethatthedirectpermutationapproachdoesnotallowfor
multiplevisits.

10. TSPinanoncompletegraph,flowformulation
AsanintroductoryexampleforanoncompletegraphtheGridspeedpuzzlewillbeused,takenfrom
Chlond(2008).Figure5presentsthepuzzle,basedonarectangulargridstreetplan,wherethedistance
betweenanytwointersectionsis10kilometres.(Ihavetakenthelibertytotransformthedatatothe
metricsystem.)Thespeedalongallnorthsouthstreetsandalleastwestavenuesisconstant.However
thespeedonthenorthsouthstreetsishighestontheeastendofthegrid,andfortheavenueseast
westthespeedishighestinthesouthendofthegrid.Thefastestareaisthereforeatthesoutheast
edgesofthegrid,andslowestinnorthwest.

101

Fulltitleofthepresentarticle:doubleclicktoeditthis

Figure5Streetplan

10 km/h
(6, 1)
10 km/h

20 km/h

30 km/h

40 km/h

50 km/h

60 km/h
(6, 6)

20 km/h

30 km/h

40 km/h

50 km/h

60 km/h

10 km

(1, 1)

(1, 6)

OnepuzzlerelatedtoFigure5istofindthefastestroutefromintersection(6,1)(northwest)to
intersection(1,1)(southwest),butvisitingeachintersectionatleastonce.Theoriginalproblemisto
visiteachintersectiononceandonlyonce.Howeverthisismorerestrictedthanrequired.Sinceit
obviouslywilltakemoretimetovisitanintersectionmorethanonce,andwewanttospendasshort
timeaspossibleonthetour,itissufficienttousetherequirementtovisiteachintersectionatleast
once.
Itisnecessarytotransformtheproblembynumberingtheintersectionsandcalculatethetravelling
timebetweeneach(directlyconnectednode),tofacilitateamathematicalformulation.Thenumbered
intersectionsarethenodes,andthelinesconnectingthenodesarethearcs.Thetravellingtime(in
minutes)alongeacharciscalculatedasshowninFigure6.

Figure6Relabelledstreetplan

60

60
30

60

13

60

14

15

60
10

30

27

10

10

30

20

15

12
28

10

24

10
29

12

12
34

18

10
23

12

12

10
17

15

15
33

11

20

15

20
32

30

10

12
22

12

60

12
16

15

20
26

10

20

12

15
21

12

60

15
15

15

30
31

20

15

20
20

12

60

20

30
25

102

30

30

60

20

20

30

19

60

30
7

30

10
35

10

36

InternationalReviewofEconomicsEducation

Figure7SpreadsheetofopenTSP,noncompletegraph(rows66121arehidden)

103

Fulltitleofthepresentarticle:doubleclicktoeditthis

Table2FormulasforthespreadsheetinFigure7
Cell

Formula

Copiedto

Name/Task

B63

=C3

B64:B122

Reversearcs:stopstart

C63

=B3

C64:C122

Reversearcs:startstop

D63

=D3

D64:D122

Reversearcs:copycosts

D123

=SUMPRODUCT(D3:D122;E3:E122)

Eq11

F63

=E3+E63

F64:F122

Eq18(LHS)

G3

=IF(OR(B3=1;C3=1);0;INDEX($J$3:$J$38;B3)
INDEX($J$3:$J$38;C3)+($I$37*E3))

G4:G122

Eq16(LHS)

K4

=SUMIF($C$3:$C$122;$I$3:$I$38;$E$3:$E$122)

K5:K38

Eq12(LHS)

L3

=SUMIF($B$3:$B$122;$I$3:$I$38;$E$3:$E$122)

L4:L38

FirstpartofEq13

M3

=K3L3

M4:M38

Eq13(LHS)

E3:E122

Var_x

I36

Param_n_2

I38

Param_n

J4:J38

Var_u

N3:N38

Param_d

P3

=RANK(J3;$J$3:$J$38;1)

P4:P38

Therankofanode

Q3

=MATCH(U3;$P$3:$P$38;0)

Q4:Q38

Visitingsequence

R3

=INDEX($U$3:$W$38;$Q3;2)

R4:R38

Avisitednodesxcoordinate

S3

=INDEX($U$3:$W$38;$Q3;3)

S4:S38

Avisitednodesycoordinate

11. Theopentour
Wewillfirsthavealookattheopentourvariantofthepuzzle.Anefficientlayoutofthisnetworkina
spreadsheetwouldbetoorganisetheproblemintwotables,onetableforthearcsandthebinary
decisionvariables,andanothertableforthenodesandthecontinuousvariables(asinRagsdale,2001).
Thiswillfacilitatetheentryoftheequations(11)(14),(16)and(17),andalsomakeasolutioneasyto
understand.Oncethedatahasbeenenteredinthespreadsheet,themodelcaneasilybebuiltaround
thedata.Noticethatfornondirectedarcsitissufficienttoentertheminonedirection,andusesimple
formulastomirrortheotherdirection.Athirdtablehasbeenaddedtothespreadsheettofacilitatea
plotofthetour,whichofcourseisnotneededforsolvingtheproblem,buthandyfordisplayingthe
solution.
Anewconstrainthasbeenadded,tospeedupthesolutionprocess:

xi , j + x j ,i 1 ( i , j ) A

(18)

Constraint(18)simplystatesthatnoarcwillbeusedinbothdirections,whichisquiteobviousforthis
problem.Suchboundsonthevariablesareveryhelpfulfortheoptimisationprocess,particularlysofor
binaryvariables.Howevertheyshouldbeusedwithcare,sinceaddingthemcanmakesomeproblems
infeasible.
InFigure7thetableforthearcsislistedfirst;thenthetableforthenodesandfinallythetablefor
facilitatingaplotofthetour.Thefirsthalfofthearcsarelisted(allarcsinonedirection)andafewof
therest,togetherwiththeobjective.(Therestofthearcsareinthehiddenrows66121.)Weseethat
104

InternationalReviewofEconomicsEducation

theoptimalvalueoftheobjective(11)is726;thefastestopentourfromnode1tonode31takesa
minimumof726minutes.TheformulasinthespreadsheetaredisplayedinTable2,andtheSolver
settingsarelistedinFigure8.

ThefirstthreerowsinTable2arepurelyforeasydataentry.Theoptimisationmodelconsistsofthe
nextsixrows.Thefollowingfiverowsareusedfornamingsomekeycells,makingthemodeleasierto
read.Thelastfourrowsfacilitateaplotofthesolution,assumingonlynlegsinthetour(eachnodeis
visitedonlyonce).ThescatterplotinFigure7consistsoftwodataseries.Oneseriesisthexy
coordinatesofthenodes(incolumnVandW),withnoline,andacircle(size20)asmarker.2The
secondseriesisthexycoordinatesofthetour(incolumnRandS),withnomarkerandaline.Fora
closedtourafinallegisaddedattheend(byreferringtothefirstlegincolumnQ).

Figure8SolversettingsforFigure7

TheStandardSolverParameterDialogBoxdisplayedinFigure8hasascrollbartodisplaythe
constraintsnotfittingthefixedsizeofthebox.Hereconstraint(14)isnotdisplayed;thisisthe
declarationofthexijvariablebeingbinary.Observethatconstraint(14)and(17)isentereddirectlyin
Solver,involvingnoformulasinthespreadsheet.Constraints(17)arethelasttwovisibleconstraintsin
theSolverParameterDialogBox.
Thismodelhas120binaryvariablesand35continuousvariables,155boundsonthevariablesand191
constraints.Thenumberofconstraintscanbereducedby4ifwegroupthefourarcsconnectedtonode
1andlistthemfirst,thennotincludetheminconstraints(16).Inthespreadsheettheformulafor(16)
includethesearcs,butfixtheirvalueto0,therebysatisfyingtheconstraint.
ExcelandtheStandardSolvertakelessthanfivesecondstofindtheoptimalsolutionfortheopentour.
(ThesolutiontimewillofcoursedependontheversionofExcel,theoperatingsystem,andthe
computer.)Thisspreadsheetdesignisquiteversatileformanytypesofnetworkproblems.Ifwedrop
(12),(16),(17)and(18)wehavetheshortestpathproblem.(WemaythendeletecolumnF,G,JandP
W.)

12. AclosedTSPinanoncompletegraph,assignmentformulation
Wewillnowrephrasetheproblemtoaclosedtour,requiringthesalesmantoreturntothebase.We
willimplementtheassignmentformulationandcompareitwithaflowformulation(notshown).We
willalsodemonstrateanefficientlayoutforthespreadsheetofaTSPinacompletegraph,eventhough
thisparticularexampleisnoncomplete.ForaTSPinacompletegraph,itismoreefficienttogroupthe
probleminthreetables;onetableforthecostmatrixandtheobjective(1),asecondtableforthexij
2

ThelabelsofthescatterplotweremadebytheXYChartLabeleraddinforExcel,freeatwww.appspro.com.

105

Fulltitleofthepresentarticle:doubleclicktoeditthis

binarydecisionvariablesandconstraint(2)and(3),andathirdtablefortheSECsandtherelatedui
variables.Forconvenienceatableofthecoordinatesofthenodescanbeaddedtofacilitateaplotof
thetour.Forlargeproblemsthesematrixesmaybeenteredindifferentsheetsintheworkbook.(Itis
moreeffectivethoughforSolvertohavetheobjective,constraintsandvariablesinonesheet.Thecost
matrixandtheplotdatacanbestoredinaseparatesheet.)
Amatrixlayoutofthecostsisveryefficientforacompletegraph,whentherearedirectlinksbetween
anynodetoeveryothernode.However,itisalsoverycommontousethesameapproachfornon
completegraphs,maybebecauseitisconsideredhandierfordataentry,atleastinthepreferred
softwaretoolsmostcommonlyused.
Unfortunatelythisconveniencehasatradeoff.Addingenormousamountofnonexistingvariablesand
correctingthisbyaddinganequalamountofnonexistingconstraints,makesasubstantialburdenon
thesoftware.Incontrast,enteringthedatainaspreadsheetmayactuallybeeasierfornoncomplete
graphsituations,usingonlytwotablesinsteadofthree.

Figure9MatrixofcostsforTSPnoncompletegraph,assignmentformulation

106

InternationalReviewofEconomicsEducation

Figure10MatrixofbinaryvariablesforTSPnoncompletegraph,assignmentformulation

107

Fulltitleofthepresentarticle:doubleclicktoeditthis

Figure11MatrixofSECsandplotdataforTSPnoncompletegraph,assignmentformulation

Figure12TheplotoftheclosedTSPinanoncompletegraph,assignmentformulation

108

InternationalReviewofEconomicsEducation

Figure13SolversettingsforFigures9to11

Table3:FormulasforspreadsheetinFigures9to11
Cell

Formula

Copiedto

Name/Task

AM39

=SUMPRODUCT(C3:AL38;C42:AL77)

Eq1

AM42

=SUM(C42:AL42)

AM43:AM77

Eq3(LHS)

C78

=SUM(C42:C77)

D78:AL78

Eq2(LHS)

D83

=INDEX($AM$82:$AM$117;$B83)
INDEX($AM$82:$AM$117;D$81)
+INDEX($C$42:$AL$77;$B83;D$81)*$B$37

D83:AL117

Eq15(LHS)

C3:AL38

Eq6(RHS)

C42:AL77

Var_x

B36

Param_n_2

B38

Param_n

AM83:AM117

Var_u

AO82

=RANK(AM82;$AM$82:$AM$117;1)

AO83:AO117

Therankofanode

AP82

=MATCH(AT82;$AO$82:$AO$117;0)

AP83:AP117

Visitingsequence

AP118

=AP82

Lastleg,returntobase

AQ82

=INDEX($AT$82:$AV$117;$AP82;2)

AQ83:AQ118

Avisitednodesx
coordinate

AR82

=INDEX($AT$82:$AV$117;$AP82;3)

AR83:AR118

Avisitednodesy
coordinate

109

Fulltitleofthepresentarticle:doubleclicktoeditthis

DuetoitssizethisformulationcannotbesolvedbytheStandardSolverinExcel,whichhasalimitof
200variables.WeseefromFigure9thattheminimumtimetocompleteaclosedtouris834,thevalue
fortheobjective(1).
InTable4themodelinFigure7,aclosednetworkversion(notshown),andtheclosedassignment
versioninFigures9to11arecompared.Thesolutiontimefortheassignmentformulationoftheclosed
tourismorethan6.2timesthesolutiontimefortheflowformulation(usingtheGurobiSolverEnginein
RSPV9.04forExcel).

Table4:Keyfeaturesofthemodels

ModelsofTSP

Figure7

Type,
model

Integervariables

Continuousvariables
Boundsonvariables

Solutiontime(seconds)

Figure911

Open,
network

Closed,
network

Closed,
assignment

155

155

1296

35

35

35

248

249

1297

70

70

1331

0.44

3.84

24.01

Overnight

Notsolvable

Constraints

Notshown

TimeStandardSolver

Lessonslearnedfromthissmallexamplearethatformulationmatters.Avoidusingnonexisting
variablesrectifiedbynonexistingconstraints.However,addingconstraintsmayhaveagreatimpact,
evenwhennotchangingtheoptimalsolution.Constraintsthataretighteningthefeasiblespacemay
speedupthesolutiontime(orthecontrary),butsuchconstraintsmustnoteliminateanotherwise
optimalsolution.

13. AclosedMBTSPinanoncompletegraph,flowformulation
Theultimateminimumcostforanyproblemiszero;simplydonothing.Sotheremustbeareasonfor
doingsomething(presumablythereisanullalternative).Minimisingcostscanoftenturnouttobe
solvingthewrongproblem.Unlessanyrevenuesarecompletelyunaffectedbythedecisionsathandwe
cannotbesurethatminimisingcostsisavalidmodelthataccuratelyrepresentstherelevant
characteristicsoftheproblem.
Letusassumetherearesomerevenuesorbenefitsbjbyvisitingnodej;wherejN.Alsointroducethe
setY={yj:jN,j1,yj{0,1}}wherethebinarydecisionvariableyj=1ifthesalesmanvisitsnodej,
else0.Definetheparametery1=1astherequirementtovisit/returntothedepot(node1),a
consequenceofourSECs.
Theobjectivenowistomaximisethetotalnetbenefit(totalbenefitsminustotalcosts):

maximize

b
jN

yj

( i , j ) A

ci , j xi , j

(19)

Thesalesmanhastoarrive(atleast)onceeachnodehedecidestovisit:

110

i:( i , j )A

xi , j y j j N

(20)

InternationalReviewofEconomicsEducation

Inadditionthebalanceconstraint(9)andbinaryconditions(10)apply,aswellastheSECs(16)andthe
correspondingbounds(17).Here(19)and(20)replacetheoriginalobjective(7)andconstraint(8),
whencomparedtotheclosedTSPflowformulation.
TherevisedproblemispresentedinFigure14.Therevenuesareenteredwith$symbolsundereach
nodenumber,indicatingtherevenueifthenodeisbeingvisited.Thecostisassumedtobe1$foreach
minuteoftraveltime,sowehaveacommonunitofmeasurementintheobjective.Observethatnode
10andnode28havenorevenues,andarethereforeobviouscandidatesfornovisits.

Figure14RelabelledstreetplanforMBTSP
1
$90
-$60
7
$30
-$60
13
$30
-$60
19
$90
-$60
25
$30
-$60
31
$30

-$60

2
$80

-$30
-$30

8
$20

-$30
-$20

14
$40

-$30
-$15

20
$80

-$30
-$12

26
$20

-$30
-$10

32
$40

-$60

3
$70

-$60

-$15

-$20
-$30

9
$10

-$30

15
$50

-$20

-$15

21
$70

-$15

27
$10

33
$50

-$10

-$30

11
$10

-$20

17
$70

-$12

22
$60

-$15

23
$50

-$12
28
$0

-$15

-$20
-$10

16
$60

-$12

5
$50

-$12

-$15

-$20
-$12

10
$0

-$15

-$20

-$60

-$12

-$15

-$20
-$20

4
$60

34
$60

-$12

29
$10

-$12
-$10

35
$70

-$60

6
$40

-$10
-$30

12
$20

-$10
-$20

18
$80

-$10
-$15

24
$40

-$10
-$12

30
$20

-$10
-$10

36
$80

ThisisavariationofthePriceCollectingTSP.Thecommonfeatureoftheseproblemsinthiscategoryis
thecombinationoftwokindsofdecisions,theselectionofsomenodes,andtheorderingofthenodes
selectedforthetour(seeGutin,2007).

111

Fulltitleofthepresentarticle:doubleclicktoeditthis

Figure15ClosedMBTSPflowformulationinaspreadsheet,rows66119arehidden

112

InternationalReviewofEconomicsEducation

Table5:FormulasforspreadsheetinFigure15
Cell

Formula

Copiedto Name/Task

B63

=C3

B64:B122

Reversearcs:stopstart

C63

=B3

C64:C122

Reversearcs:startstop

D63

=D3

D64:D122 Reversearcs:copycosts

D123

=SUMPRODUCT(D3:D122;E3:E122)

Computingcosts

F3

=IF(OR(B3=1;C3=1);0;INDEX($K$3:$K$38;B3)
INDEX($K$3:$K$38;C3)+$H$37*E3)

F4:F122

Eq16(LHS)

I39

=SUMPRODUCT(I3:I38;J3:J38)

Computingrevenues

I40

=I39D123

Eq19

L3

=SUMIF($C$3:$C$122;$H$3:$H$38;$E$3:$E$122) L4:L38

Eq20(LHS)

M3

=SUMIF($B$3:$B$122;$H$3:$H$38;$E$3:$E$122) M4:M38

Eq9(RHS)

E3:E122

Var_x

H36

Param_n_2

H38

Param_n

K4:K38

Var_u

J4:J38

Var_y

O3

=IF(J3=0;"";RANK(K3;$K$3:$K$38;1))

O4:O38

Apreliminaryrankofnodes

P3

=IF(J3=0;"";RANK(O3;$O$3:$O$38;1))

P4:P38

Rankofanodeinthetour

Q3

=MATCH(U3;$P$3:$P$38;0)

Q4:Q38

Visitingsequence

Q39

=Q3

Lastleg,returntodepot

R3

=INDEX($U$3:$W$38;$Q3;2)

R4:R39

Avisitednodesxcoordinate

S3

=INDEX($U$3:$W$38;$Q3;3)

S4:S39

Avisitednodesycoordinate

Figure16SolversettingsforspreadsheetinFigure15

FromFigure15weseethatthesalesmanvisitsonly30ofthe36nodes,withanetprofitof$812.Notice
thatthetouractuallyincludesnode10with$0benefits,butskipnode13with$30inbenefits.Using
theStandardSolverittakesmorethanafullweekendtofindtheoptimalsolution.Anearlytestversion
ofExcel2010(TechnicalPreview)withthenewStandardSolverfinishedduringanovernightrun.Again,
anassignmentformulationapplyingafullnnmatrixofthexvariableswouldincludetoomany
variablesfortheStandardSolver.UsingthecommercialPSPV9.04,thesolutiontimeinExcelis9.06
secondsfortheflowformulation.Thisalsorevealsanalternativeoptimalsolution,visiting32nodes.
Thesolutiontimewhentheassignmentformulationisimplementedis11.45seconds,onthesame
113

Fulltitleofthepresentarticle:doubleclicktoeditthis

computer.Intheassignmentformulationacompletegraphisassumed,andtheextravariablesare
eliminatedbyextraconstraints,therebyincreasingthesolutiontime.
UnfortunatelytheMTZSEQsused(16)(17)assumesnode1tobethedepot.Thereforewecannot
applythistypeofSECifourgoalistofindtheoptimallocationforthedepot.

14. PitfallsusingMTZSECs
Foraclosedtourthestartingnodecanalwaysbechosenarbitrarily,ifallnodeshavetobevisited.
Unfortunately,whenapplyingtheMTZSECs,thesolutionmaydependuponwhichnodehasbeen
selectedasthestartnode.Whendoweneedtostayalert?

15. Noncompletegraphsrequiringmultiplevisits
TakealookatFigure17.Twoidenticalgraphsaredisplayed,exceptthatnode1and2havebeen
renumbered.Youcaneasilyfindtheoptimalsolutionbyvisualinspection.Tryingtosolveoneofthem
fails,whereastheothersucceeds,iftheMTZSECsareappliedinaclosedTSP.Therearetwoother
nodesthatcouldberenumberedasnumber1.Noneofthemwillsucceedifwetrytosolveusingthe
MTZSECs.

Figure17TSPinanoncompletegraph,requiringmultiplevisitsinaclosedtour

4.47

4.47

Sincethisisanoncompletegraph,aspreadsheetlayoutsimilartoFigure7isprobablymostefficient,
skippingequation(18),asitishardlyneeded.

16. Thetriangleinequalityisnotalwayssatisfied
HavealookatthecostmatrixesinTable6.Theonlydifferenceisthatoncemorethenodes1and2
havebeenrenumbered.Thisisacompletegraph,asthereisadirectlinkbetweenanynodetoevery
othernode.

114

InternationalReviewofEconomicsEducation

Table6:Identicalcostmatrixesofacompletegraph,thetriangleinequalitydoesnotapply
cij

cij

130

140

150

130

140

150

123

40

50

123

40

50

124

34

45

124

34

45

135

35

54

135

35

54

Solvingoneofthemusingtheflowformulation(7)(10)andtheMTZSECs(16)(17)returnsa
solutionwithaminimalcostof209,visitingeverynodeonce.Solvingtheotherreturnsaminimumcost
of28,visitingfourofthenodesonceandvisitingonenodefourtimes.Thenumberingofthenodeshas
thusagreatimpactonwhichsolutionisobtained.Theassignmentformulationwouldreturna
minimumcostof209insteadof28.SeealsoLeeandRaffensperger(2006)forusingAMPLteachingTSP,
wheretheDFJSECsarebeingimplemented.
ForacompletegraphaspreadsheetlayoutsimilartoFigures9to11isprobablymostefficient,skipping
columnsAOARandtheplot,sincenocoordinatesaregiveninthisexample.

17. Conclusion
SolvingTSPusinggeneralpurposeoptimisationtoolslikeMIPsolversinspreadsheetshasbeen
regardedpracticalonlyforproblemsofasmallsize.Recentadvancementsinthesetypesofsoftware
haveincreasedthislimit;problemsofsize358ofnoncompletegraphshavebeensolvedinlessthan10
minutes.
SuchgeneralpurposeoptimisationtoolsalsoallowforagreatervarietyoftypesofTSP,whereas
proceduresdesignedspecificallyforTSPoftenrestricttheproblemtoalimitednumberofvariants.In
fact,wemayoverlookthebestsolutionbyapplyingthestandardapproachusingtheassignment
formulationorthesespecifictoolsforsolvingTSP.Wemustbeabsolutelysureourproblemformulation
isvalidallrelevantcostsandrevenueshavetobeconsidered,andtheconstraintsmustnotbetoo
limiting.Otherwisewemayendupsolvingthewrongproblem.Anticipatingaspecifictypeofsolution
whenformulatingtheproblemislikestartingatthewrongend,andmayleadtoapoorresult.
However,theSECsneededinaTSPformulationmayhaveunfortunateconsequencesandlimitations.
WhenusingtheMTZSECs,theselectionofthebasenodecanbecritical,evenforaclosedtourina
completegraph.Itmayalsoprohibitasolution,eveninaconnectedgraph.
Wehavefurtherseenthatformulationmattersincludingnonexistingvariablesandeliminatingthem
byaddingnonexistingconstraintscanbothincreasesolutiontimeandcauseproblemsinfindingthe
optimalsolution(thenumberofvariablesorconstraintsmayevenbecometoobigforthesolver).A
wideformulationwillalwaysincludetheoptimalsolution.Atightformulationmayhelpfindingthe
optimalsolution,butmayalsoexcludetheoptimalsolution.Atightformulationmayreduceor
increasethesolutiontime,thisdependsonthetypeofsolverusedandtheproblemathand.
Toplaysafeawideformulationseemslikeagoodstrategy.Ifthegraphisnotcompleteorthetriangle
inequalitydoesnotapply,bothimplysituationswheremultiplevisitsmayberequired,thena
replacementofthecostmatrixmaybeadvisable.Thenthecostsshouldbereplacedbyaminimumcost
matrix(youcanusetheshortestpathformulation(n1)2times),whichformanylinksmayinvolvea
lengthytourvisitingmanynodesfromnodeitonodej.TheTSPmodelcanthenbetight,whichmayor
maynotbehelpfulforsomesolvers.UnfortunatelytheTSPmodelwillthenalsobeblindeyed;ithasno
115

Fulltitleofthepresentarticle:doubleclicktoeditthis

realtrackofthetourorhowmanyvisitsareactuallybeingmadeateachnode.TheTSPsolutionthen
onlyindicatesthesequenceofthevisits,andignoresanyrevisits.

References
Chlond,M.J.(2008).Shashasgridspeedpuzzle,INFORMSTransactionsofEducation,Vol.9(1),pp.4652.
Availableonlineathttp://ite.pubs.informs.org/.
Dantzig,G.,Fulkerson,D.andJohnson,S.(1954).Solutionofalargescaletravelingsalesmanproblem,
OperationsResearch,Vol.2,pp.393410.
Gutin,G.andPunnen,A.P.(eds)(2007).Thetravelingsalesmanproblemanditsvariations,NewYork:
Springer.
LeeJ.,andJ.F.Raffensperger:(2006).UsingAMPLforteachingtheTSP,INFORMSTransactionson
Education,Vol.7(1),pp.3769.http://archive.ite.journal.informs.org/Vol7No1/LeeRaffensperger/
Malandraki,C.andDaskin,M.S.(1993).ThemaximumbenefitChinesepostmanproblemandthemaximum
benefittravelingsalesmanproblem,EuropeanJournalofOperationalResearch,Vol.65,pp.21834.
Miller,C.E.,Tucker,A..W.andZemlin,R.A.(1960).Integerprogrammingformulationoftravelingsalesman
problems,JournalofACM,Vol.7,pp.3269.
Pataki,G(2003).Teachingintegerprogrammingformulationsusingthetravelingsalesmanproblem,SIAM
Review,Vol.45(1),pp.11623.
Ragsdale,C.T.(2001).SpreadsheetModelingandDecisionAnalysis,Cincinatti:SouthWesternCollege
Publishing.

AuthorBiography
RasmusRasmussensteachingexperienceismostlyinthefieldsofbusinesseconomics,financeand
managementscience.Hisresearchinterestsareinthefieldsofappliedmanagementsciencerelatedto
problemsinbusinesseconomics,quiteoftenusingspreadsheets,thetoolfrequentlyusedalsoin
teaching.

Contactdetails
RasmusRasmussen
MoldeUniversityCollege
P.O.Box2110
6402Molde,Norway
Tel:+4771214242

Fax:+4771214100

rasmus.rasmussen@himolde.no

116

Vous aimerez peut-être aussi