(!****************************************************************
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
|
(!****************************************************************
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
|
(!****************************************************************
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
|
(!****************************************************************
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
|