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

Production of cane sugar

Production of cane sugar:
  • linear, 'ocurrence', and 'element' constraints (a4sugar_ka.mos), branching strategy for variables,
  • alternative formulation using 'distribute' constraints (a4sugar2_ka.mos).
Further explanation of this example: 'Xpress Kalis User Guide', Section 3.6 occurrence: Sugar production

Source Files

Data Files


   CP example problems
   file a4sugar2_ka.mos
   Production of cane sugar
   (See "Applications of optimization with Xpress-MP",
        Section 6.4 Cane sugar production)

   Assignment with resource-dependent cost.
   Wagen loads need to be assigned time slots on production 
   lines. The limit on the number of resources (= production lines)
   is modeled by counting the 'occurrence' of the time slot values
   in the assigment variables 'process'.
   - Alternative formulation using 'distribute' constraint -

   (c) 2008 Artelys S.A. and Fair Isaac Corporation

model "A-4 Cane sugar production (CP) - 2"
 uses "kalis"
  NW = 11                            ! Number of wagon loads of sugar
  NL = 3                             ! Number of production lines
  WAGONS = 1..NW
  NS = ceil(NW/NL)
  SLOTS = 1..NS                      ! Time slots for production
  LOSS: array(WAGONS) of integer     ! Loss in kg/hour
  LIFE: array(WAGONS) of integer     ! Remaining time per lot (in hours)
  DUR: integer                       ! Duration of the production (in hours)
  COST: array(SLOTS) of integer      ! Cost per wagon
  MINUSE,MAXUSE: array(SLOTS) of integer ! Lower and upper bounds on slot use
  loss: array(WAGONS) of cpvar       ! Loss per wagon
  process: array(WAGONS) of cpvar    ! Time slots for wagon loads

  totalLoss: cpvar                   ! Objective variable
 initializations from 'Data/a4sugar.dat'

 forall(w in WAGONS) setdomain(process(w), 1, NS)

! Wagon loads per time slot
 forall(s in SLOTS) MAXUSE(s):= NL
 distribute(process, SLOTS, MINUSE, MAXUSE)

! Limit on raw product life
 forall(w in WAGONS) process(w) <= floor(LIFE(w)/DUR)

! Objective function: total loss
 forall(w in WAGONS) do
  forall(s in SLOTS) COST(s):= s*DUR*LOSS(w)
  loss(w) = element(COST, process(w))
 totalLoss = sum(w in WAGONS) loss(w)

 cp_set_branching(assign_var(KALIS_SMALLEST_MAX, KALIS_MIN_TO_MAX, process))

! Solve the problem
 if not (cp_minimize(totalLoss)) then
  writeln("No solution found")

! Solution printing
 writeln("Total loss: ", getsol(totalLoss))
 forall(s in SLOTS) do 
  write("Slot ", s, ": ")
  forall(w in WAGONS)   
   if(getsol(process(w))=s) then
    write("wagon ", strfmt(w,2), strfmt(" (" + s*DUR*LOSS(w) + ")  ", 8))


Back to examples browserPrevious exampleNext example