Lindo Systems

! Single product Capacitated lot sizing with backlogging in LINGO.
  Decide how much to produce each period of a single 
 product so as to
  Minimise setup, holding, and backlogging costs,
 subject to:
  each period:
    satisfying demand,
    not exceeding production capacity,
    not exceeding inventory capacity
    not exceeding backlogging limit;
! Keywords: Lot sizing, Capacitated lot sizing, Production planning, Backlogging,
            Backorder;
SETS:
  TIME:
   DEM,  ! Demand each time period;
   MAKE, ! Amount to produce each period;
   INV,  ! Amount in inventory at end of period;
   BKL,  ! Amount backlogged at end of period;
   Y;    ! = 1 if anything is produced in period, else 0;
 ENDSETS
 DATA:
  TIME = 1..15;
  PCAP = 200;   ! Production Capacity per period;
  ICAP = 100;   ! Inventory upper limit each period;
  BCAP =  75;   ! Upper limit on backlogging each period;
  SC = 280 ;    ! Setup cost to produce > 0 in a period;
  HC =  2 ;     ! Holding cost per unit per period;
  BC = 3;       ! Backlogging cost per unit per period;
  I0 = 9;       ! Initial inventory;
  DEM =  15  60 130   0 100 200  111 210   5 121  10  10  90   5   5; ! Demands;
 ! Assume initial inventory is 0;
 ENDDATA

!------------------------------------;
!  The straightforward formulation;

! The objective;
  MIN = SCOST + ICOST + BCOST;
     SCOST = @SUM( TIME(t): SC*Y(t));
     ICOST = @SUM( TIME(t): HC*INV(t));
     BCOST = @SUM( TIME(t): BC*BKL(t));

! Inventory balance constraints;
    I0 + MAKE(1) = DEM(1) + INV(1) - BKL(1); ! Period 1 starts with I0 inventory;
  @FOR( TIME(t) | t #GT# 1:    ! Subsequent periods;
      INV(t-1) - BKL(t-1) + MAKE(t) = DEM(t) + INV(t) - BKL(t);
        );
 ! Assume all demand must be satisfied at the end;
     BKL(@SIZE(TIME)) = 0;

  @FOR( TIME(t):  
   ! Inventory capacity;
      INV(t) <= ICAP;
   ! Backlogging limit;
      BKL(t) <= BCAP;
   ! Production capacity and setup forcing;
     MAKE(t) <= @SMIN( PCAP, @SUM( TIME(s): DEM(s)))*Y(t);
   ! Make the Y's binary (0 or 1);
      @BIN( Y(t));
       );