(!****************************************************** Mosel Example Problems ====================== file f5tour2.mos ```````````````` Problem 9.6: Planning a flight tour (second formulation for other data format) (c) 2002 Dash Associates author: S. Heipcke, Jun. 2002 *******************************************************!) model "F-5 Tour planning (2)" uses "mmxprs", "mmsystem" parameters DATAFILE="f5tour7.dat" end-parameters forward procedure break_subtour forward procedure print_sol declarations starttime: real CITIES: set of string ! Set of cities end-declarations starttime:=gettime initializations from DATAFILE CITIES end-initializations finalize(CITIES) declarations NCITIES=getsize(CITIES) DIST: array(CITIES,CITIES) of integer ! Distance between cities NEXTC: array(CITIES) of string ! Next city after i in the solution fly: array(CITIES,CITIES) of mpvar ! 1 if flight from i to j end-declarations initializations from DATAFILE DIST end-initializations ! Objective: total distance TotalDist:= sum(i,j in CITIES | i<>j) DIST(i,j)*fly(i,j) ! Visit every city once forall(i in CITIES) sum(j in CITIES | i<>j) fly(i,j) = 1 forall(j in CITIES) sum(i in CITIES | i<>j) fly(i,j) = 1 forall(i,j in CITIES | i<>j) fly(i,j) is_binary ! Solve the problem minimize(TotalDist) ! Eliminate subtours break_subtour !----------------------------------------------------------------- procedure break_subtour declarations TOUR,SMALLEST,ALLCITIES: set of string end-declarations forall(i in CITIES) forall(j in CITIES) if(getsol(fly(i,j))=1) then NEXTC(i):=j break end-if ! Print the current solution print_sol ! Get (sub)tour containing city 1 TOUR:={} first:="Bordeaux" repeat TOUR+={first} first:=NEXTC(first) until first="Bordeaux" size:=getsize(TOUR) ! Find smallest subtour if size < NCITIES then SMALLEST:=TOUR if size>2 then ALLCITIES:=TOUR forall(i in CITIES) do if(i not in ALLCITIES) then TOUR:={} first:=i repeat TOUR+={first} first:=NEXTC(first) until first=i ALLCITIES+=TOUR if getsize(TOUR)