Lindo Systems

! A Fleet Routing and Assignment model in LINGO.
Given a number of flights, each with a number of passengers to carry,
and a set of vehicle types, each with a capacity, how should
vehicles be assigned to flights, and vehicles be routed,
to carry the passengers at minimum cost;
! Keywords: Aircraft scheduling, Airline, Assignment, Fleet assignment,
 Fleet routing, FTL routing, Load assignment, Routing, Trucking, Vehicle routing;
SETS:
  LOCN;                    ! List of locations or cities;
  VTYPE: CAP, CLEG, NVAIL; ! Vehicle types & attributes/fields;
  PERIOD;                  ! Period or Event index set;
  FLIGHT( LOCN, PERIOD, LOCN, PERIOD): NUMPASS; ! Flight demand info;
  V2F( VTYPE, FLIGHT): XVF; ! Vehicle flight combinations;
  VxL( VTYPE, LOCN): IDLEB; ! Vehicle locaton combinations;
  VxLxP( VTYPE, LOCN, PERIOD): IDLE; ! V, L, P combinations;
ENDSETS
DATA:
 ! The cities in today's problem;
  LOCN = CHI MNN, KC_;
 ! The periods or event points in today's problem;
  PERIOD = P0600 P0630 P0700 P0730 P0800 P0830 P0900 P0930; 
 ! Vehicles and their attribues;
  VTYPE,  CAP, CLEG, NVAIL =
   B737   162    20    2
   A320   150    19    4;
 ! Start and end point and passengers, each flight;
    FLIGHT, NUMPASS =
     CHI P0600 KC_ P0730  145
     MNN P0600 CHI P0730  100
     KC_ P0630 MNN P0930  130
     CHI P0700 MNN P0830  120
     MNN P0730 KC_ P0930  130
     KC_ P0730 CHI P0900  135;
ENDDATA
! To see the scalar version, click on Solver | Generate | Display model;
! Variables:
    XVF( v, i, p1, j, p2) = number vehicle of type v departing locn i
                         in period p1, arriving at j in p2,
    IDLE( v, i, p) = number vehicles of type v idle on ground at i,
                         just after period/event p
    IDLEB( v, i) =  number vehicles of type v idle on ground at i,
                         just before 1st period/event.

! Objective: Minimize cost;
   MIN = @SUM( V2F( v, i, p1, j, p2) : CLEG( v) * XVF( v, i, p1, j, p2)); 

! Flow balance,
    Begin on ground + arrivals = ending on ground + departures;
!   Begining period, vehicle v, city i;
   @FOR( VxL( v, i):
     [BAL0] IDLEB( v, i) = IDLE( v, i, 1) 
            + @SUM( V2F( v, i, p1, j, p2) | p1 #EQ# 1: XVF( v, i, p1, j, p2)); 
       );
! Subsequent periods, flow into v, j, p = flow out of v, j, p;
   @FOR( VxLxP( v, j, p) | p #GT# 1: 
      [BAL] IDLE( v, j, p-1) + @SUM( V2F( v, i, p1, j, p) : XVF( v, i, p1, j, p))
          = IDLE( v, j, p)   + @SUM( V2F( v, j, p,  i, p2): XVF( v, j, p,  i, p2)); 
        );

! Cannot use more planes than have in fleet;
   @FOR( VTYPE( v):
     [VAVAIL] @SUM( LOCN( i): IDLEB( v, i)) <= NVAIL( v);
       );

 ! Capacity on leg i, p1, j, p2 must cover demand on leg;
    @FOR( FLIGHT( i, p1, j, p2): 
      [FCOV] @SUM( V2F( v, i, p1, j, p2) : CAP( v) * XVF( v, i, p1, j, p2)) 
                                                 >= NUMPASS( i, p1, j, p2) ; 
        ); 

! The XVF variables must be general integer;
    @FOR( V2F( v, i, p1, j, p2):
        @GIN( XVF( v, i, p1, j, p2))
        );

! Optional features not included:
     Deadheading/Repositioning/RedEye flights,
     Cyclic schedule that repeat daily or weekly.
     Specified initial position of vehicles,
     Revenue/flight to allow selection of most profitable
     legs to fly in face of limited capacity.
     Random demand with safety capacity;