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 User Guide', Sections 2.2 Data input from file and 2.3 Optimization and enumeration


Source Files

Data Files





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

Back to examples browserPrevious exampleNext example