FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Ground transport

Description
Problem name and type, featuresDifficultyRelated examples
E‑1 Car rental: Transport problem *** transport_graph.mos
data preprocessing, set operations, sqrt and ^2, if-then-elif
E‑2 Choosing the mode of transport: Minimum cost flow ** mincostflow_graph.mos
formulation with extra nodes for modes of transport; encoding of arcs, finalize, union of sets, nodes labeled with strings
E‑3 Depot location: Facility location problem *** facilityloc_graph.mos
modeling flows as fractions, definition of model cuts
E‑4 Heating oil delivery: Vehicle routing problem (VRP) **** vrp_graph.mos
elimination of inadmissible subtours, cuts; selection with `|', definition of model cuts
E‑5 Combining different modes of transport ***
modeling implications, weak and strong formulation of bounding constraints; triple indices
E‑6 Fleet planning for vans ***
maxlist, minlist, max, min


Further explanation of this example: 'Applications of optimization with Xpress-MP', Chapter 10: Ground transport

mosel_app_5.zip[download all files]

Source Files

Data Files





e1carrent.mos

(!******************************************************
   Mosel Example Problems
   ======================

   file e1carrent.mos
   ``````````````````
   Fleet management in car rental

   A rental company has 94 cars at 10 locations. Assume the
   distance between each location is 1.3 times the Euclidean
   distance. Given the transport cost per km, determine how
   many cars to move between locations so that morning demand
   is met while minimizing total cost.

   Here the data is checked to confirm there are the number
   of cars required, exiting if stock does not meet demand.
   Then the locations are sorted into 'NEED' or 'EXCESS'
   locations with 'if-then-elif' to determine start (source) and 
   destination (sink) locations. To calculate distance, this 
   problem introduces the function 'sqrt' and the exponential 
   operator '^'.
 
   (c) 2008-2022 Fair Isaac Corporation
       author: S. Heipcke, Mar. 2002, rev. Mar. 2022
*******************************************************!)

model "E-1 Car rental"
 uses "mmxprs"

 declarations
  AGENTS = 1..10                     ! Car rental agencies

  REQ: array(AGENTS) of integer      ! Required number of cars
  STOCK: array(AGENTS) of integer    ! Number of cars in stock
  X,Y: array(AGENTS) of integer      ! Coordinates of rental agencies
  COST: real                         ! Cost per km of moving a car
  NEED: set of integer               ! Agencies needing more cars
  EXCESS: set of integer             ! Agencies with too many cars
 end-declarations

 initializations from 'e1carrent.dat'
  REQ STOCK X Y COST
 end-initializations

 if sum(a in AGENTS) (STOCK(a)-REQ(a)) <> 0 then
  writeln("Problem is infeasible")
  exit(0)
 end-if 

! Calculate sets of agencies with excess or deficit of cars
 forall(a in AGENTS)
  if STOCK(a) - REQ(a) < 0 then
   NEED += {a}
  elif STOCK(a) - REQ(a) > 0 then
   EXCESS += {a}
  end-if

 finalize(NEED); finalize(EXCESS)

 declarations
  DIST: array(EXCESS,NEED) of real   ! Distance between agencies
  move: array(EXCESS,NEED) of mpvar  ! Cars exchanged between agencies
 end-declarations

! Calculate distances between agencies
 forall(a in EXCESS,b in NEED) 
  DIST(a,b):= 1.3*sqrt((X(a)-X(b))^2 + (Y(a)-Y(b))^2)

! Objective: total transport cost
 Cost:= sum(a in EXCESS,b in NEED) COST*DIST(a,b)*move(a,b)

! Agencies with excess availability
 forall(a in EXCESS) sum(b in NEED) move(a,b) = STOCK(a) - REQ(a)

! Agencies in need of cars
 forall(b in NEED) sum(a in EXCESS) move(a,b) = REQ(b) - STOCK(b)

 forall(a in EXCESS,b in NEED) move(a,b) is_integer

! Solve the problem
 minimize(Cost)
 
! Solution printing
 writeln("Total cost: ", getobjval)
 write(" ->")
 forall(b in NEED) write(strfmt(b,3))
 writeln
 setparam("realfmt","%3g")
 forall(a in EXCESS) do
  write(a,"  ")
  forall(b in NEED) write(getsol(move(a,b)))
  writeln
 end-do 

end-model

Back to examples browserPrevious exampleNext example