Initializing help system before first use

Production of cane sugar


Type: Assignment
Rating: 2 (easy-medium)
Description: Production of cane sugar:
  • linear, 'ocurrence', and 'element' constraints (a4sugar_ka.mos), branching strategy for variables,
  • alternative formulation using 'distribute' constraints (a4sugar2_ka.mos).
File(s): a4sugar_ka.mos, a4sugar2_ka.mos
Data file(s): a4sugar.dat


a4sugar_ka.mos
(!****************************************************************
   CP example problems
   ===================
   
   file a4sugar_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'.

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

model "A-4 Cane sugar production (CP)"
 uses "kalis"
 
 declarations
  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
  
  loss: array(WAGONS) of cpvar       ! Loss per wagon
  process: array(WAGONS) of cpvar    ! Time slots for wagon loads

  totalLoss: cpvar                   ! Objective variable
 end-declarations
 
 initializations from 'Data/a4sugar.dat'
  LOSS LIFE DUR
 end-initializations

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

! Wagon loads per time slot
 forall(s in SLOTS) occurrence(s, process) <= NL

! 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))
 end-do
 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")
  exit(0)
 end-if

! 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))
   end-if 
  writeln
 end-do

end-model

a4sugar2_ka.mos
(!****************************************************************
   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"
 
 declarations
  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
 end-declarations
 
 initializations from 'Data/a4sugar.dat'
  LOSS LIFE DUR
 end-initializations

 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))
 end-do
 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")
  exit(0)
 end-if

! 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))
   end-if 
  writeln
 end-do

end-model

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.