this repo has no description
at develop 2.4 kB view raw
1% RUNS ON mzn20_fd 2% RUNS ON mzn-fzn_fd 3% RUNS ON mzn20_mip 4 5%-----------------------------------------------------------------------------% 6% Timetabling problem 7% 8% Serge Kruk 9% 04/2007 10% 11% This is a subset of a real timetabling problem. The job is to assign 12% students to a section of each of the courses they have chosen and assign a 13% timeslot for all sections of all courses so that students can attend their 14% assigned sections. 15%-----------------------------------------------------------------------------% 16 17include "globals.mzn"; 18 19%-----------------------------------------------------------------------------% 20 21int: nS; % Number of students 22int: nC; % Number of course 23int: nSC; % Number of sections per course 24int: nCS; % Number of courses per student 25int: nT; % Number of timeslots 26 27array[1..nS, 1..nCS] of 1..nC: Cs; % Courses of each student 28 29 % Decision variables 30array[1..nS, 1..nCS] of var 1..nSC: x; % Sections assigned 31array[1..nC, 1..nSC] of var 1..nT: z; % Times of each section 32 33 % All the course-sections of a student must have different times 34constraint 35 forall (i in 1..nS) ( 36 alldifferent (j in 1..nCS) (z[Cs[i,j], x[i,j]]) 37 ); 38 39solve satisfy; 40 41%-----------------------------------------------------------------------------% 42 43output [ "timetabling:\n", 44 "course sections assigned (1 row per student, 1 col per course):\n" ] 45 ++ 46 [ show(x[i,j]) ++ if j = nCS then "\n" else " " endif 47 | i in 1..nS, j in 1..nCS ] 48 ++ 49 [ "times of each section (1 row per course, 1 col per section):\n" ] 50 ++ 51 [ show(z[i,j]) ++ if j = nSC then "\n" else " " endif 52 | i in 1..nC, j in 1..nSC ]; 53 54%-----------------------------------------------------------------------------% 55% Small data set. 56 57nS=20; 58nC=6; 59nCS=4; 60nSC=3; 61%nT=5; % To make the problem real 62nT=6; 63 64Cs= [| 65 2, 5, 4, 3 | 66 4, 6, 3, 1 | 67 3, 1, 6, 2 | 68 2, 3, 6, 1 | 69 6, 4, 3, 1 | 70 6, 4, 2, 5 | 71 6, 2, 4, 1 | 72 6, 1, 4, 3 | 73 6, 4, 5, 3 | 74 5, 4, 6, 2 | 75 4, 2, 1, 5 | 76 6, 2, 3, 1 | 77 4, 3, 5, 6 | 78 6, 3, 2, 4 | 79 4, 6, 5, 1 | 80 3, 2, 6, 4 | 81 3, 6, 5, 1 | 82 3, 5, 2, 6 | 83 4, 3, 5, 2 | 84 5, 4, 6, 2 | 85 |]; 86 87%-----------------------------------------------------------------------------% 88%-----------------------------------------------------------------------------%