tsp in excel.pdf
Post on 28-Feb-2018
270 Views
Preview:
TRANSCRIPT
-
7/25/2019 TSP IN EXCEL.pdf
1/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,
-
7/25/2019 TSP IN EXCEL.pdf
2/23
InternationalReviewofEconomicsEducation
95
ij},wherethepair(i,j)indicatesthearcbetweennodeiandj.AstandardassumptioninTSPisto
assumedirectlinksbetweeneverypairofnodes,usuallyreferredtoasacompletegraph.Thegraph
consistingofthenodesNandarcsAisthenconnected;thereisaconnectionorpathfromanynodeto
anyothernodeinthegraph.Thebasicstandardassumptionistorestrictthenumberofvisitstoexactly
oneforeachnode.Whythesalesmanisnotallowedtovisitanodemorethanonceisnotobvious.Onecanspeculatethatsucharequirementmakesiteasiertodevelopsolutionprocedures,therebyfitting
theproblemtothetoolsathand.AcommondefinitionofthesetofdecisionvariablesisX{xij:i,jN,
ij}wherexij=1ifthesalesmantravelsfromnodeitoj(nodeiisvisitedimmediatelybeforenodej),
and0otherwise.ThecostmatrixisdefinedasC={cij:i,jN,i j}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
Quite
a
lot
of
real
life
problems
do
not
fit
these
assumptions.
Often
we
must
allow
for
the
set
A
not
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,
in
each
group
the
models
vary
according
to
which
assumptions
are
made,
most
notably
whetheracompletegraphisassumed.
-
7/25/2019 TSP IN EXCEL.pdf
3/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
96
4. AssignmentformulationofTSP
Fortheclosedtouranassignmentformulationcouldbeofthefollowingform:
1 1
n n
ij ij
i j
Minimize c x= =
(1)
1
1 ,n
ij
i
x j N=
= (2)
1
1 ,n
ij
j
x i N=
= (3)
{ }0,1 , ,ijx 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:
, 0i ix 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):
, ,ij ijx e 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.
-
7/25/2019 TSP IN EXCEL.pdf
4/23
InternationalReviewofEconomicsEducation
97
5. FlowformulationofTSP
Aflowformulationoftheclosedtour,thatexplicitlyconsidersvalidconnectionsonly,canbemadeafter
redefiningC={ci,j:(i,j)A}andX{xi,j:(i,j)A}.Thisformulationwillthusworkevenwhenthe
graph
is
not
complete:
, ,
( , )
i j i ji j A
Minimize c x
(7)
,
: ( , )
1i ji i j A
x j N
(8)
, ,
: ( , ) : ( , )
i k k ji i k A j k j A
x x k N
= (9)
{ } ( ), 0,1 ,i jx i j A (10)
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,forthetransitorintermediatenodesdi=0.Theopentourformulationcanthenbestatedas:
, ,
( , )
i j i ji j A
Minimize c x
(11)
,
: ( , )
1 1i ji i j A
x j N
> (12)
, ,
: ( , ) : ( , )
i k k j k i i k A j k j A
x x d k N
=
(13)
{ } ( ), 0,1 ,i jx i j A (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.
-
7/25/2019 TSP IN EXCEL.pdf
5/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
98
7. Subtoureliminatingconstraints(SECs)
AkeypartofaTSPistomakesurethetouriscontinuous,thatthearcsarelinkedfromthebasecityall
thewaytoeverycityvisited.Withoutsuchconstraintswequiteoftenwillgetsolutionscontaining
degenerate
tours
between
intermediate
nodes
and
not
connected
to
the
base
city.
The
originally
SECs
wasformedin1954byDantzigFulkersonJohnson(DFJ)(seeDantzig, FulkersonandJohnson,1954):
, 1, \{1},i ji S j S
x S S N S
(15)
Unfortunatelythisintroducesanexponentialnumberofconstraints,andbecomesimpracticalevenfor
smallsizedproblems.AdifferentSECproposedin1960byMillerTuckerZemlin(MTZ)(seeMiller,
TuckerandZemlin,1960)introducesonlyamaximum1of(n2)
2constraints,atthedisadvantageofa
weakLPrelaxation:
( )( ) ( ),1 1 1 , , : , 1
i j i j
u u n x i j A i j +
(16)
In(16)anewsetofvariablesU={ui:iN,i1}isrequired.Theuiarearbitraryrealnumbers,butcan
berankedtononnegativeintegers,representingthesequencethenodesarebeingvisited.For
conveniencewemayaddu11(node1isthebasecity),andlimittherangeofui,thushelpingthe
optimisationsoftware(seealsoPataki(2003)):
2 1iu n i 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
1Inasquarennmatrix;thefirstrow,firstcolumnandthediagonalareexcluded.
-
7/25/2019 TSP IN EXCEL.pdf
6/23
InternationalReviewofEconomicsEducation
99
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
-
7/25/2019 TSP IN EXCEL.pdf
7/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
100
Table1:FormulasforspreadsheetinFigure2
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),withmarkersbutnoline.Thesecondseriesisthetour(G13:H27inFigure2),withnomarkersandaline.
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:Q13CalculateEuclediandistances
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
-
7/25/2019 TSP IN EXCEL.pdf
8/23
InternationalReviewofEconomicsEducation
101
Figure4TheopenTSPsolution
BoththespreadsheetandtheSolversettingsareverysimple.Wehave10decisionvariables(numberof
nodeslessthedepot),namedSequenceinthespreadsheet.TheobjectiveintheSolversettingsistominimisethevalueinthecellnamedTotal_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.
-
7/25/2019 TSP IN EXCEL.pdf
9/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
102
Figure5Streetplan
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
10 km/h
20 km/h
30 km/h
40 km/h
50 km/h
60 km/h10 km
10 km/h 20 km/h 30 km/h 40 km/h 50 km/h 60 km/h(6, 6)(6, 1)
(1, 1) (1, 6)
60 60 60 60 60
60
60
60
60
60
30
30
30
30
30
30 30 30 30 30
20
20
20
20
20
20 20 20 20 20
15
15
15
15
15
15 15 15 15 15
12
12
12
12
12
12 12 12 12 12
10
10
10
10
10
10 10 10 10 10
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36
-
7/25/2019 TSP IN EXCEL.pdf
10/23
InternationalReviewofEconomicsEducation
103
Figure7SpreadsheetofopenTSP,noncompletegraph(rows66121arehidden)
-
7/25/2019 TSP IN EXCEL.pdf
11/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
104
Table2FormulasforthespreadsheetinFigure7
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:
( ), , 1 ,i j j ix x 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
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
-
7/25/2019 TSP IN EXCEL.pdf
12/23
InternationalReviewofEconomicsEducation
105
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;thisisthedeclarationofthexijvariablebeingbinary.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
2ThelabelsofthescatterplotweremadebytheXYChartLabeleraddinforExcel,freeatwww.appspro.com.
-
7/25/2019 TSP IN EXCEL.pdf
13/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
106
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
-
7/25/2019 TSP IN EXCEL.pdf
14/23
InternationalReviewofEconomicsEducation
107
Figure10MatrixofbinaryvariablesforTSPnoncompletegraph,assignmentformulation
-
7/25/2019 TSP IN EXCEL.pdf
15/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
108
Figure11MatrixofSECsandplotdataforTSPnoncompletegraph,assignmentformulation
Figure12TheplotoftheclosedTSPinanoncompletegraph,assignmentformulation
-
7/25/2019 TSP IN EXCEL.pdf
16/23
InternationalReviewofEconomicsEducation
109
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:AQ118Avisitednodesx
coordinate
AR82 =INDEX($AT$82:$AV$117;$AP82;3) AR83:AR118 Avisitednodesycoordinate
-
7/25/2019 TSP IN EXCEL.pdf
17/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
110
DuetoitssizethisformulationcannotbesolvedbytheStandardSolverinExcel,whichhasalimitof
200variables.WeseefromFigure9thattheminimumtimetocompleteaclosedtouris834,thevalue
fortheobjective(1).
InTable4themodelinFigure7,aclosednetworkversion(notshown),andtheclosedassignment
versioninFigures9to11arecompared.Thesolutiontimefortheassignmentformulationoftheclosed
tourismorethan6.2timesthesolutiontimefortheflowformulation(usingtheGurobiSolverEnginein
RSPV9.04forExcel).
Table4:Keyfeaturesofthemodels
Lessonslearnedfromthissmallexamplearethatformulationmatters.Avoidusingnonexisting
variablesrectifiedbynonexistingconstraints.However,addingconstraintsmayhaveagreatimpact,
evenwhennotchangingtheoptimalsolution.Constraintsthataretighteningthefeasiblespacemay
speedupthesolutiontime(orthecontrary),butsuchconstraintsmustnoteliminateanotherwise
optimalsolution.
13.AclosedMBTSPinanoncompletegraph,flowformulation
Theultimateminimumcostforanyproblemiszero;simplydonothing.Sotheremustbeareasonfor
doingsomething(presumablythereisanullalternative).Minimisingcostscanoftenturnouttobe
solvingthewrongproblem.Unlessanyrevenuesarecompletelyunaffectedbythedecisionsathandwe
cannotbesurethatminimisingcostsisavalidmodelthataccuratelyrepresentstherelevant
characteristicsoftheproblem.
Let
us
assume
there
are
some
revenues
or
benefits
bj
by
visiting
node
j;
where
j
N.
Also
introduce
the
setY={yj:jN,j1,yj{0,1}}wherethebinarydecisionvariableyj=1ifthesalesmanvisitsnodej,
else0.Definetheparametery1=1astherequirementtovisit/returntothedepot(node1),a
consequenceofourSECs.
Theobjectivenowistomaximisethetotalnetbenefit(totalbenefitsminustotalcosts):
, ,
( , )
maximizej j i j i j
j N i j A
b y c x
(19)
Thesalesmanhastoarrive(atleast)onceeachnodehedecidestovisit:
,
:( , )
i j ji i j A
x y j N
(20)
ModelsofTSP Figure7 Notshown Figure911
Type,
model
Open,
network
Closed,
network
Closed,
assignment
Integervariables 155 155 1296Continuousvariables 35 35 35
Constraints 248 249 1297
Boundsonvariables 70 70 1331
Solutiontime(seconds) 0.44 3.84 24.01
TimeStandardSolver 5 Overnight Notsolvable
-
7/25/2019 TSP IN EXCEL.pdf
18/23
InternationalReviewofEconomicsEducation
111
Inadditionthebalanceconstraint(9)andbinaryconditions(10)apply,aswellastheSECs(16)andthe
correspondingbounds(17).Here(19)and(20)replacetheoriginalobjective(7)andconstraint(8),
whencomparedtotheclosedTSPflowformulation.
TherevisedproblemispresentedinFigure14.Therevenuesareenteredwith$symbolsundereachnodenumber,indicatingtherevenueifthenodeisbeingvisited.Thecostisassumedtobe1$foreach
minuteoftraveltime,sowehaveacommonunitofmeasurementintheobjective.Observethatnode
10andnode28havenorevenues,andarethereforeobviouscandidatesfornovisits.
Figure14RelabelledstreetplanforMBTSP
ThisisavariationofthePriceCollectingTSP.Thecommonfeatureoftheseproblemsinthiscategoryis
thecombinationoftwokindsofdecisions,theselectionofsomenodes,andtheorderingofthenodes
selectedforthetour(seeGutin,2007).
-$60 -$60 -$60 -$60 -$60
-$60
-$60
-$60
-$60
-$60
-$30
-$30
-$30
-$30
-$30
-$30 -$30 -$30 -$30 -$30
-$20
-$20
-$20
-$20
-$20
-$20 -$20 -$20 -$20 -$20
-$15
-$15
-$15
-$15
-$15
-$15 -$15 -$15 -$15 -$15
-$12
-$12
-$12
-$12
-$12
-$12 -$12 -$12 -$12 -$12
-$10
-$10
-$10
-$10
-$10
-$10 -$10 -$10 -$10 -$10
1$90
2$80
3$70
4$60
5$50
6$40
7$30
8$20
9$10
10$0
11$10
12$20
13$30
14$40
15$50
16$60
17$70
18$80
19$90
20$80
21$70
22$60
23$50
24$40
25$30 26$20 27$10 28$0 29$10 30$20
31$30
32$40
33$50
34$60
35$70
36$80
-
7/25/2019 TSP IN EXCEL.pdf
19/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
112
Figure15ClosedMBTSPflowformulationinaspreadsheet,rows66119arehidden
-
7/25/2019 TSP IN EXCEL.pdf
20/23
InternationalReviewofEconomicsEducation
113
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
-
7/25/2019 TSP IN EXCEL.pdf
21/23
Fulltitleofthepresentarticle:doubleclicktoeditthis
114
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,
whereas
the
other
succeeds,
if
the
MTZ
SECs
are
applied
in
a
closed
TSP.
There
are
two
other
nodesthatcouldberenumberedasnumber1.Noneofthemwillsucceedifwetrytosolveusingthe
MTZSECs.
Figure17TSPinanoncompletegraph,requiringmultiplevisitsinaclosedtour
Sincethisisanoncompletegraph,aspreadsheetlayoutsimilartoFigure7isprobablymostefficient,
skippingequation(18),asitishardlyneeded.
16.Thetriangleinequalityisnotalwayssatisfied
HavealookatthecostmatrixesinTable6.Theonlydifferenceisthatoncemorethenodes1and2
havebeenrenumbered.Thisisacompletegraph,asthereisadirectlinkbetweenanynodetoevery
othernode.
3 2 1
45
4
3
2
1
1 2 3 4 5 6
32
4
4.47
3 1 2
45
4
3
2
1
1 2 3 4 5 6
32
44.47
-
7/25/2019 TSP IN EXCEL.pdf
22/23
InternationalReviewofEconomicsEducation
115
Table6:Identicalcostmatrixesofacompletegraph,thetriangleinequalitydoesnotapply
c ij 1 2 3 4 5 cij 1 2 3 4 5
1 - 2 3 4 5 1 - 5 130 140 150
2 5 - 130 140 150 2 2 - 3 4 5
3 4 123 - 40 50 3 123 4 - 40 50
4 3 124 34 - 45 4 124 3 34 - 45
5 2 135 35 54 - 5 135 2 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
-
7/25/2019 TSP IN EXCEL.pdf
23/23
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,finance and
managementscience.Hisresearchinterestsareinthefieldsofappliedmanagementsciencerelatedto
problemsinbusinesseconomics,quiteoftenusingspreadsheets,thetoolfrequentlyusedalsoin
teaching.
Contactdetails
RasmusRasmussen
MoldeUniversityCollege
P.O.Box2110
6402Molde,Norway
Tel:+4771214242
Fax:+4771214100
rasmus.rasmussen@himolde.no
top related