Initializing help system before first use

Integer Programming


Type: Resource-constrained project scheduling
Rating: 3 (intermediate)
Description: Alternative formulations using either binary variables (pplan.mos) or SOS-1 (pplan2.mos)
File(s): pplan.mos, pplan2.mos

pplan.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file pplan.mos
   ``````````````
   Manpower planning: MIP example.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2001, rev. Sep. 2013
*******************************************************!)

model Pplan 
 uses "mmxprs"

 declarations
  PROJ = 1..3                      ! Set of projects
  NM = 6                           ! Time horizon (months)
  MONTHS = 1..NM                   ! Set of time periods (months) to plan for
 
  DUR: array(PROJ) of integer      ! Duration of project p
  RESUSE: array(PROJ,MONTHS) of integer 
                                   ! Res. usage of proj. p in its t'th month
  RESMAX: array(MONTHS) of integer ! Resource available in month m
  BEN: array(PROJ) of real         ! Benefit per month once project finished
 
  start: array(PROJ,MONTHS) of mpvar  ! 1 if proj p starts in month t, else 0
 end-declarations

 DUR   :: [3, 3, 4]
 RESMAX:: [5, 6, 7, 7, 6, 6]
 BEN   :: [10.2, 12.3, 11.2]
 RESUSE:: (1,1..3)[3, 4, 2]
 RESUSE:: (2,1..3)[4, 1, 5]
 RESUSE:: (3,1..4)[3, 2, 1, 2]     ! Other RESUSE entries are 0 by default

! Objective: Maximize Benefit
! If project p starts in month t, it finishes in month t+DUR(p)-1 and 
! contributes a benefit of BEN(p) for the remaining NM-(t+DUR(p)-1) months:
 MaxBen:= 
  sum(p in PROJ, m in 1..NM-DUR(p)) (BEN(p)*(NM-m-DUR(p)+1)) * start(p,m)

! Each project starts once and only once:  
 forall(p in PROJ) One(p):= sum(m in MONTHS) start(p,m) = 1

! Resource availability
! A project starting in month m is in its k-m+1'st month in month k: 
 forall(k in MONTHS) ResMax(k):=
  sum(p in PROJ, m in 1..k) RESUSE(p,k+1-m)*start(p,m) <= RESMAX(k)

! Make all the start variables binary
 forall(p in PROJ, m in MONTHS) start(p,m) is_binary

 maximize(MaxBen)                   ! Solve the MIP-problem

 writeln("Solution value is: ", getobjval)
 forall(p in PROJ) writeln( p, " starts in month ", 
                            getsol(sum(m in 1..NM-DUR(p)) m*start(p,m)) )
end-model

pplan2.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file pplan2.mos
   ```````````````
   Defining SOS1.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2001, rev. Sep. 2013
*******************************************************!)

model Pplan2 
 uses "mmxprs"

 declarations
  PROJ = 1..3                      ! Set of projects
  NM = 6                           ! Time horizon (months)
  MONTHS = 1..NM                   ! Set of time periods (months) to plan for
 
  DUR: array(PROJ) of integer      ! Duration of project p
  RESUSE: array(PROJ,MONTHS) of integer 
                                   ! Res. usage of proj. p in its t'th month
  RESMAX: array(MONTHS) of integer ! Resource available in month m
  BEN: array(PROJ) of real         ! Benefit per month once project finished
 
  start: array(PROJ,MONTHS) of mpvar  ! 1 if proj p starts in month t, else 0
 end-declarations

 DUR   :: [3, 3, 4]
 RESMAX:: [5, 6, 7, 7, 6, 6]
 BEN   :: [10.2, 12.3, 11.2]
 RESUSE:: (1,1..3)[3, 4, 2]
 RESUSE:: (2,1..3)[4, 1, 5]
 RESUSE:: (3,1..4)[3, 2, 1, 2]     ! Other RESUSE entries are 0 by default

! Objective: Maximize Benefit
! If project p starts in month t, it finishes in month t+DUR(p)-1 and 
! contributes a benefit of BEN(p) for the remaining NM-(t+DUR(p)-1) months:
 MaxBen:= 
  sum(p in PROJ, m in 1..NM-DUR(p)) (BEN(p)*(NM-m-DUR(p)+1)) * start(p,m)

! Each project starts once and only once:  
 forall(p in PROJ) One(p):= sum(m in MONTHS) start(p,m) = 1

! Resource availability:
! A project starting in month m is in its k-m+1'st month in month k: 
 forall(k in MONTHS) ResMax(k):=
  sum(p in PROJ, m in 1..k) RESUSE(p,k+1-m)*start(p,m) <= RESMAX(k)

! Define SOS-1 sets that ensure that at most one start(p,m) is non-zero
! for each project p. Use month index to order the variables
 forall(p in PROJ) XSet(p):= sum(m in MONTHS) m*start(p,m) is_sos1

 maximize(MaxBen)                   ! Solve the MIP-problem

 writeln("Solution value is: ", getobjval)
 forall(p in PROJ) writeln( p, " starts in month ", 
                            getsol(sum(m in 1..NM-DUR(p)) m*start(p,m)) )
end-model