Académique Documents
Professionnel Documents
Culture Documents
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:
(1)
x
i =1
ij
=1 , j N
(2)
x
j =1
ij
=1 , i N
(3)
xij {0,1} , i, j N
(4)
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: (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):
xi ,i = 0 i N
xij eij , i , j N
(6)
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
ci , j xi , j
(7)
i : ( i , j ) A
xi , j 1 j N
xi , k =
(8)
i : ( i , k ) A
j : ( k , j ) A
xk , j k N
(9)
xi , j {0,1} ( i , j ) A
(10)
6. FlowformulationofopentourTSP
FortheopentourformulationweaddtheparametersD={di:iN}wherediisthenetdemandin nodei;anddi=1forthestartnode(thebasecityisnumberednode1);di=+1fortheendnode,for thetransitorintermediatenodesdi=0.Theopentourformulationcanthenbestatedas:
Minimize
( i , j ) A
ci , j xi , j
(11)
i : ( i , j ) A
xi , j 1 j > 1 N
(12)
i : ( i , k ) A
xi , k
j : ( k , j ) A
xk , j = d k k N
(13)
xi , j {0,1} ( i , j ) A
(14)
97
Fulltitleofthepresentarticle:doubleclicktoeditthis
7. Subtoureliminatingconstraints(SECs)
AkeypartofaTSPistomakesurethetouriscontinuous,thatthearcsarelinkedfromthebasecityall thewaytoeverycityvisited.Withoutsuchconstraintswequiteoftenwillgetsolutionscontaining degeneratetoursbetweenintermediatenodesandnotconnectedtothebasecity.TheoriginallySECs wasformedin1954byDantzigFulkersonJohnson(DFJ)(seeDantzig,FulkersonandJohnson,1954):
x
iS jS
i, j
S 1, S N \ {1}, S
(15)
ui u j + 1 ( n 1) (1 xi , j ) ( i, j ) A, : i, j 1
(16)
2 ui n i > 1 N
(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
Figure1Locationsoftheoilrigstovisit
9. Adirectpermutationapproach
Inthissimpleformtheproblemistofindtheorderforeachnodeinthesequenceofthetourthat minimisesthetotaldistance(cost).Ifthesupplyshiptakesthetourbasedontherignumbers:012... 9100;thetotaldistanceis205.67.Weseektheorderorpermutationthatminimisesthetotal distance.Thisdirectapproachisveryeasytoimplementinspreadsheets,asdisplayedinFigure2.
Figure2SpreadsheetfordirectpermutationofTSP
99
Fulltitleofthepresentarticle:doubleclicktoeditthis
Table1:FormulasforspreadsheetinFigure2
Cell G3 D17 D28 C17:C26 G16 H16 Formula =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) =INDEX($G$3:$Q$13;C16+1;C17+1) =SUM(D17:D27) =INDEX($B$3:$D$13;$C16+1;2) =INDEX($B$3:$D$13;$F16+1;3) Copiedto G3:Q13 D18:D27 G17:G27 H17:H27 Name/Task CalculateEuclediandistances betweenanypairofnodes Costonaleg Totalcost Sequence Avisitednodesxcoordinate 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
(1, 1)
10 km
(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 30
60 20
60 15
60 12
60 10
60
7
30 30
30 20
30 15
10
30 12
11
30 10
12
60
60
13
20 30
14
20 20
15
20 15
16
20 12
17
20 10
18
19
15 30
20
15 20
21
15 15
22
15 12
23
15 10
24
60
25
12 30
26
12 20
27
12 15
28
12 12
29
12 10
30
60
31
10
32
10
33
10
34
10
35
10
36
102
InternationalReviewofEconomicsEducation
Figure7SpreadsheetofopenTSP,noncompletegraph(rows66121arehidden)
103
Fulltitleofthepresentarticle:doubleclicktoeditthis
Table2FormulasforthespreadsheetinFigure7 Cell
B63 C63 D63 D123 F63 G3 K4 L3 M3 E3:E122 I36 I38 J4:J38 N3:N38 P3 Q3 R3 S3
Formula
=C3 =B3 =D3 =SUMPRODUCT(D3:D122;E3:E122) =E3+E63 =IF(OR(B3=1;C3=1);0;INDEX($J$3:$J$38;B3) INDEX($J$3:$J$38;C3)+($I$37*E3)) =SUMIF($C$3:$C$122;$I$3:$I$38;$E$3:$E$122) =SUMIF($B$3:$B$122;$I$3:$I$38;$E$3:$E$122) =K3L3 =RANK(J3;$J$3:$J$38;1) =MATCH(U3;$P$3:$P$38;0) =INDEX($U$3:$W$38;$Q3;2) =INDEX($U$3:$W$38;$Q3;3)
Copiedto
B64:B122 C64:C122 D64:D122 F64:F122 G4:G122 K5:K38 L4:L38 M4:M38 P4:P38 Q4:Q38 R4:R38 S4:S38
Name/Task
Reversearcs:stopstart Reversearcs:startstop Reversearcs:copycosts Eq11 Eq18(LHS) Eq16(LHS) Eq12(LHS) FirstpartofEq13 Eq13(LHS) Var_x Param_n_2 Param_n Var_u Param_d Therankofanode Visitingsequence Avisitednodesxcoordinate 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)
InternationalReviewofEconomicsEducation
Figure8SolversettingsforFigure7
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 AM39 AM42 C78 D83 C3:AL38 C42:AL77 B36 B38 AM83:AM117 AO82 AP82 AP118 AQ82 AR82 Formula =SUMPRODUCT(C3:AL38;C42:AL77) =SUM(C42:AL42) =SUM(C42:C77) =INDEX($AM$82:$AM$117;$B83) INDEX($AM$82:$AM$117;D$81) +INDEX($C$42:$AL$77;$B83;D$81)*$B$37 =RANK(AM82;$AM$82:$AM$117;1) =MATCH(AT82;$AO$82:$AO$117;0) =AP82 =INDEX($AT$82:$AV$117;$AP82;2) =INDEX($AT$82:$AV$117;$AP82;3) Copiedto AM43:AM77 D78:AL78 D83:AL117 AO83:AO117 AP83:AP117 AQ83:AQ118 AR83:AR118 Name/Task Eq1 Eq3(LHS) Eq2(LHS) Eq15(LHS) Eq6(RHS) Var_x Param_n_2 Param_n Var_u Therankofanode Visitingsequence Lastleg,returntobase Avisitednodesx coordinate Avisitednodesy coordinate
109
Fulltitleofthepresentarticle:doubleclicktoeditthis
Table4:Keyfeaturesofthemodels
Lessonslearnedfromthissmallexamplearethatformulationmatters.Avoidusingnonexisting variablesrectifiedbynonexistingconstraints.However,addingconstraintsmayhaveagreatimpact, evenwhennotchangingtheoptimalsolution.Constraintsthataretighteningthefeasiblespacemay speedupthesolutiontime(orthecontrary),butsuchconstraintsmustnoteliminateanotherwise optimalsolution.
ModelsofTSP Type, model Integervariables Continuousvariables Constraints Boundsonvariables Solutiontime(seconds) TimeStandardSolver Figure7 Open, network 155 35 248 70 0.44 5 Notshown Closed, network 155 35 249 70 3.84 Overnight Figure911 Closed, assignment 1296 35 1297 1331 24.01 Notsolvable
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
Figure14RelabelledstreetplanforMBTSP
1 $90 -$60 7 $30 -$60 13 $30 -$60 19 $90 -$60 25 $30 -$60 31 $30 -$60 2 $80 -$60 3 $70 -$60 4 $60 -$60 5 $50 -$60 6 $40
-$15 -$30 10 $0
-$15 -$12 28 $0
111
Fulltitleofthepresentarticle:doubleclicktoeditthis
Figure15ClosedMBTSPflowformulationinaspreadsheet,rows66119arehidden
112
InternationalReviewofEconomicsEducation
Table5:FormulasforspreadsheetinFigure15
Cell B63 C63 D63 D123 F3 I39 I40 L3 M3 E3:E122 H36 H38 K4:K38 J4:J38 O3 P3 Q3 Q39 R3 S3 Formula =C3 =B3 =D3 =SUMPRODUCT(D3:D122;E3:E122) =IF(OR(B3=1;C3=1);0;INDEX($K$3:$K$38;B3) INDEX($K$3:$K$38;C3)+$H$37*E3) =SUMPRODUCT(I3:I38;J3:J38) =I39D123 Copiedto Name/Task B64:B122 C64:C122 F4:F122 Reversearcs:stopstart Reversearcs:startstop Computingcosts Eq16(LHS) Computingrevenues Eq19 Eq20(LHS) Eq9(RHS) Var_x Param_n_2 Param_n Var_u Var_y Apreliminaryrankofnodes Rankofanodeinthetour Visitingsequence Lastleg,returntodepot Avisitednodesxcoordinate Avisitednodesycoordinate
D64:D122 Reversearcs:copycosts
=SUMIF($C$3:$C$122;$H$3:$H$38;$E$3:$E$122) L4:L38 =SUMIF($B$3:$B$122;$H$3:$H$38;$E$3:$E$122) M4:M38 =IF(J3=0;"";RANK(K3;$K$3:$K$38;1)) =IF(J3=0;"";RANK(O3;$O$3:$O$38;1)) =MATCH(U3;$P$3:$P$38;0) =Q3 =INDEX($U$3:$W$38;$Q3;2) =INDEX($U$3:$W$38;$Q3;3) O4:O38 P4:P38 Q4:Q38 R4:R39 S4:S39
Figure16SolversettingsforspreadsheetinFigure15
Fulltitleofthepresentarticle:doubleclicktoeditthis
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 4.47
4 4.47
Sincethisisanoncompletegraph,aspreadsheetlayoutsimilartoFigure7isprobablymostefficient, skippingequation(18),asitishardlyneeded.
16. Thetriangleinequalityisnotalwayssatisfied
HavealookatthecostmatrixesinTable6.Theonlydifferenceisthatoncemorethenodes1and2 havebeenrenumbered.Thisisacompletegraph,asthereisadirectlinkbetweenanynodetoevery othernode.
114
InternationalReviewofEconomicsEducation
Table6:Identicalcostmatrixesofacompletegraph,thetriangleinequalitydoesnotapply
cij 1 2 3 4 5 1
5 4 3 2
2
2 123 124 135
3
3 130 34 35
4
4 140 40 54
5
5 150 50 45 -
cij 1 2 3 4 5
1
2 123 124 135
2
5 4 3 2
3
130 3 34 35
4
140 4 40 54
5
150 5 50 45 -
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