Initializing help system before first use

Basic modeling tasks: data input, optimization, enumeration


Type: Scheduling
Rating: 2 (easy-medium)
Description: Simple exam scheduling problem (formulated with disequality constraints) showing basic modeling tasks:
  • data input from file - static arrays (i4exam_ka.mos)
  • data input from file - dynamic arrays (i4exam2*_ka.mos)
  • optimization (i4exam3_ka.mos)
  • definition of a branching strategy over decision variables of type cpvar (i4exam4_ka.mos)
File(s): i4exam_ka.mos, i4exam2_ka.mos, i4exam3_ka.mos, i4exam4_ka.mos
Data file(s): i4exam.dat, i4exam2.dat


i4exam_ka.mos
(!****************************************************************
   CP example problems
   ===================
   
   file i4exam_ka.mos
   ``````````````````
   Scheduling exams
   (See "Applications of optimization with Xpress-MP",
        Section 14.4 Exam schedule)

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

model "I-4 Scheduling exams (CP)"
 uses "kalis"
 
 declarations
  EXAM = 1..11                        ! Set of exams
  TIME = 1..8                         ! Set of time slots  
  INCOMP: array(EXAM,EXAM) of integer ! Incompatibility between exams
  EXAMNAME: array(EXAM) of string
  
  plan: array(EXAM) of cpvar          ! Time slot for exam
 end-declarations
 
 EXAMNAME:: (1..11)["DA","NA","C++","SE","PM","J","GMA","LP","MP","S","DSE"]
 
 initializations from 'Data/i4exam.dat'
  INCOMP
 end-initializations

 forall(e in EXAM) setdomain(plan(e), TIME)
 
! Respect incompatibilities
 forall(d,e in EXAM | d<e and INCOMP(d,e)=1)  plan(d) <> plan(e)

! Solve the problem
 if not(cp_find_next_sol) then
  writeln("Problem is infeasible")
  exit(1)
 end-if
 
! Solution printing
 forall(t in TIME) do
  write("Slot ", t, ": ")
  forall(e in EXAM) 
   if (getsol(plan(e))=t) then write(EXAMNAME(e)," "); end-if
  writeln
 end-do

end-model

i4exam2_ka.mos
(!****************************************************************
   CP example problems
   ===================
   
   file i4exam2_ka.mos
   ```````````````````
   Scheduling exams
   (See "Applications of optimization with Xpress-MP",
        Section 14.4 Exam schedule)
   - Reading indices from file + dynamic creation of variables. -

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       Creation: 2005, rev. Mar. 2013       
*****************************************************************!)

model "I-4 Scheduling exams (CP) - 2"
 uses "kalis"
 
 declarations
  NT: integer                         ! Number of time slots
  EXAM: set of string                 ! Set of exams
  TIME: set of integer                ! Set of time slots  
  INCOMP: dynamic array(EXAM,EXAM) of integer ! Incompatibility between exams
  
  plan: array(EXAM) of cpvar          ! Time slot for exam
 end-declarations

 initializations from 'Data/i4exam2.dat'
  INCOMP NT
 end-initializations

 TIME:= 1..NT
 
 setparam("kalis_default_lb", 1); setparam("kalis_default_ub", NT)
 forall(e in EXAM) create(plan(e))
 
! Respect incompatibilities
 forall(d,e in EXAM | exists(INCOMP(d,e)) and d<e)  plan(d) <> plan(e)  

! Solve the problem
 if not(cp_find_next_sol) then
  writeln("Problem is infeasible")
  exit(1)
 end-if   

! Solution printing
 forall(t in TIME) do
  write("Slot ", t, ": ")
  forall(e in EXAM) 
   if (getsol(plan(e))=t) then write(e," "); end-if
  writeln
 end-do

end-model

i4exam3_ka.mos
(!****************************************************************
   CP example problems
   ===================
   
   file exam3.mos
   ``````````````
   Scheduling exams
   (See "Applications of optimization with Xpress-MP",
        Section 14.4 Exam schedule)
   - Optimization -

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       Creation: 2005, rev. Mar. 2013       
*****************************************************************!)

model "I-4 Scheduling exams (CP) - 3"
 uses "kalis"
 
 declarations
  NT: integer                         ! Number of time slots
  EXAM: set of string                 ! Set of exams
  TIME: set of integer                ! Set of time slots  
  INCOMP: dynamic array(EXAM,EXAM) of integer ! Incompatibility between exams
  
  plan: array(EXAM) of cpvar          ! Time slot for exam
  numslot: cpvar                      ! Number of time slots used
 end-declarations

 initializations from 'Data/i4exam2.dat'
  INCOMP NT
 end-initializations

 finalize(EXAM)
 TIME:= 1..NT
 
 setparam("kalis_default_lb", 1); setparam("kalis_default_ub", NT)
 forall(e in EXAM) create(plan(e))
 
! Respect incompatibilities
 forall(d,e in EXAM | exists(INCOMP(d,e)) and d<e)  plan(d) <> plan(e)

! Calculate number of time slots used
 numslot = maximum(plan)

! Solve the problem
 if not(cp_minimize(numslot)) then
  writeln("Problem is infeasible")
  exit(1)
 end-if   

! Solution printing
 forall(t in TIME) do
  write("Slot ", t, ": ")
  forall(e in EXAM) 
   if (getsol(plan(e))=t) then write(e," "); end-if
  writeln
 end-do

end-model

i4exam4_ka.mos
(!****************************************************************
   CP example problems
   ===================
   
   file exam4.mos
   ``````````````
   Scheduling exams
   (See "Applications of optimization with Xpress-MP",
        Section 14.4 Exam schedule)
   - Optimization and branching strategy -	

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       Creation: 2005, rev. Mar. 2013       
*****************************************************************!)

model "I-4 Scheduling exams (CP) - 4"
 uses "kalis"
 
 declarations
  NT: integer                         ! Number of time slots
  EXAM: set of string                 ! Set of exams
  TIME: set of integer                ! Set of time slots  
  INCOMP: dynamic array(EXAM,EXAM) of integer ! Incompatibility between exams
  
  plan: array(EXAM) of cpvar          ! Time slot for exam
  numslot: cpvar                      ! Number of time slots used
 end-declarations

 initializations from 'Data/i4exam2.dat'
  INCOMP NT
 end-initializations

 finalize(EXAM)
 TIME:= 1..NT
 
 setparam("kalis_default_lb", 1); setparam("kalis_default_ub", NT)
 forall(e in EXAM) create(plan(e))
 
! Respect incompatibilities
 forall(d,e in EXAM | exists(INCOMP(d,e)) and d<e)  plan(d) <> plan(e)

! Calculate number of time slots used
 numslot = maximum(plan)

! Setting parameters of the enumeration
 cp_set_branching(assign_var(KALIS_MAX_DEGREE, KALIS_MIN_TO_MAX))  

! Solve the problem
 if not(cp_minimize(numslot)) then
  writeln("Problem is infeasible")
  exit(1)
 end-if   

! Solution printing
 forall(t in TIME) do
  write("Slot ", t, ": ")
  forall(e in EXAM) 
   if (getsol(plan(e))=t) then write(e," "); end-if
  writeln
 end-do
 
 cp_show_stats
 
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.