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

Cut generation for an economic lot-sizing (ELS) problem

This model implements various forms of cut-and-branch and branch-and-cut algorithms. In its simplest form (looping over LP solving) it illustrates the following features:
  • adding new constraints and resolving the LP-problem (cut-and-branch)
  • basis in- and output
  • if statement
  • repeat-until statement
  • procedure
The model els.mos also implements a configurable cutting plane algorithm:
  • defining the cut manager node callback function,
  • defining and adding cuts during the MIP search (branch-and-cut), and
  • using run-time parameters to configure the solution algorithm.
The version elsglobal.mos shows how to implement global cuts. And the model version elscb.mos defines additional callbacks for extended logging and user stopping criteria based on the MIP gap.

Another implementation (master model: runels.mos, submodel: elsp.mos) parallelizes the execution of several model instances, showing the following features:
  • parallel execution of submodels
  • communication between different models (for bound updates on the objective function)
  • sending and receiving events
  • stopping submodels
The fourth implementation (master model: runelsd.mos, submodel: elsd.mos) is an extension of the parallel version in which the solve of each submodels are distributed to various computing nodes.

Further explanation of this example: elscb.mos, elsglobal.mos, runels.mos: Xpress Whitepaper 'Multiple models and parallel solving with Mosel', Section 'Solving several model instances in parallel'.

Source Files

Data Files


   Mosel Example Problems

   file runelst.mos
   Run several instances of the model elsp.mos in
   parallel and coordinate the solution update.
   -- Using the 'bin' IO driver --
   -- Implements a timer to interrupt submodels --
   *** ATTENTION: This model will return an error if ***
   *** no more than one Xpress licence is available. ***

   *** This model cannot be run with a Community Licence 
       for the provided data instance ***

   (c) 2017 Fair Isaac Corporation
       author: S. Heipcke, June 2017

model "Els main"
 uses "mmjobs", "mmsystem"

  DATAFILE = "els5.dat"    !els   !els4
  T = 45   !15    !60
  P = 4
  MAXDUR = 1000                            ! Timer delay in millisec
  RM = 0..5                                ! Range of models
  TIMES = 1..T                             ! Time periods
  PRODUCTS = 1..P                          ! Set of products
  solprod: array(PRODUCTS,TIMES) of real   ! Sol. values for var.s produce
  solsetup: array(PRODUCTS,TIMES) of real  ! Sol. values for var.s setup
  DEMAND: array(PRODUCTS,TIMES) of integer ! Demand per period
  modELS: array(RM) of Model               ! Models
  NEWSOL = 2                               ! Identifier for "sol. found" event
  Msg: Event                               ! Messages sent by models
  params: text                             ! Submodel runtime parameters
  ifsol: boolean                           ! Whether a solution has been found
  tid: integer                             ! Timer identifier

! Compile, load, and run models M1 and M2
 M1:= 1; M2:=3
 res:= compile("elsp.mos")             ! Compile the submodel
 load(modELS(M1), "elsp.bim")          ! Load submodels
 load(modELS(M2), "elsp.bim")
 forall(m in RM) modELS(m).uid:= m
 setmodpar(params, "DATAFILE", DATAFILE)
 setmodpar(params, "T", T); setmodpar(params, "P", P)
 tid:=settimer(0,MAXDUR,true)          ! Start the timer (true=heartbeat)
 forall(m in [M1,M2]) do
  setworkdir(modELS(m), ".")
  setmodpar(params, "ALG", m);         ! Configure submodels
  run(modELS(m), params)               ! Start submodel runs

 ifsol:= false
 objval:= MAX_REAL
 algsol:= -1; algopt:= -1

  wait                                 ! Wait for the next event
  Msg:= getnextevent                   ! Get the event
  if getclass(Msg)=NEWSOL then         ! Get the event class
    if getvalue(Msg) < objval then     ! Value of the event (= obj. value)
      algsol:= Msg.fromuid             ! ID of model sending the event
      objval:= getvalue(Msg)
      writeln("Improved solution ", objval, " found by model ", algsol)
      forall(m in RM | m <> algsol) send(modELS(m), NEWSOL, objval)
      ifsol:= true
      writeln("Solution ", getvalue(Msg), " found by model ", Msg.fromuid)
   elif getclass(Msg)=EVENT_TIMER then ! Handle timer events
     if ifsol then
       writeln("Time limit reached, stopping all submodels.")
       canceltimer(tid)                ! Stopping the timer
       break                           ! Exit from 'repeat' loop
     else                              ! Timer enters new iteration to continue
       writeln("No solution found - relaunching timer.")
   elif getclass(Msg)=EVENT_END then
     algopt:= Msg.fromuid              ! Retrieve ID of terminated model
 until getclass(Msg)=EVENT_END         ! A model has finished
 forall(m in RM) stop(modELS(m))       ! Stop all running models

 if algsol=-1 then
  writeln("No solution available")
 else                     ! Retrieve the best solution from shared memory
  initializations from "bin:shmem:sol"+algsol
  initializations from DATAFILE
! Solution printing
  writeln("Best solution found by model ", algsol) 
  writeln("Optimality proven by model ", algopt) 
  writeln("Objective value: ", objval) 
  write("Period  setup    ")
  forall(p in PRODUCTS) write(strfmt(p,-7))
  forall(t in TIMES) do
   write("\n ", strfmt(t,2), strfmt(sum(p in PRODUCTS) solsetup(p,t),8), "    ")
   forall(p in PRODUCTS) write(strfmt(solprod(p,t),3), " (",DEMAND(p,t),")")

! Cleaning up temporary files
 fdelete("shmem:sol"+M1);  fdelete("shmem:sol"+M2)

Back to examples browserPrevious exampleNext example