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

Basic modeling tasks: data input, optimization, enumeration

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)
Further explanation of this example: 'Xpress Kalis Mosel User Guide', Sections 2.2 Data input from file and 2.3 Optimization and enumeration


Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
i4exam_ka.mos[download]
i4exam2_ka.mos[download]
i4exam3_ka.mos[download]
i4exam4_ka.mos[download]

Data Files





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 | getsol(plan(e))=t) write(e," ")
  writeln
 end-do

end-model

Back to examples browserPrevious exampleNext example