3

プロジェクトの出力とソリューションを拡張する必要があります (試験のスケジュールを作成します)。

- 構造を 5 日間に拡張 (私は常に 1 日で作業しています): スロットタイム (5*10) の日数を細かく考えてから、出力を調整しました! より良い方法はありますか?

今コード全体:

include "globals.mzn";include "alldifferent.mzn";

%------------------------------Scalar_data----------------------
int: Students;          % number of students
int: Exams;             % number of exams
int: Rooms;             % number of rooms
int: Slotstime;         % number of slots
int: Days;              % a period i.e. five days
int: Exam_max_duration; % the maximum length of any exam (in slots)

%------------------------------Vectors--------------------------
array[1..Rooms] of int  : Rooms_capacity;
array[1..Exams] of int  : Exams_duration; % the duration of written test
array[1..Slotstime, 1..Rooms] of 0..1: Unavailability;
array[1..Students,1..Exams]   of 0..1: Enrollments;

登録は、すべての学生の登録を追跡します。これから、定員に応じて適切な部屋を選択するために、試験を受ける学生の数を取得します

%---------------------------Decision_variables------------------
array[1..Slotstime,1..Rooms] of var 0..Exams: Timetable_exams;
array[1..Exams] of var 1..Rooms: ExamsRoom;
array[1..Exams] of var 1..Slotstime: ExamsStart;

%---------------------------Constraints--------------------------

% Calculate the number of subscribers and assign classroom 
% according to time and capacity 

constraint forall (e in 1..Exams,r in 1..Rooms,s in 1..Slotstime)               
(if Rooms_capacity[r] <= sum([bool2int(Enrollments[st,e]>0)| st in 1..Students])
  then Timetable_exams[s,r] != e  
  else true
  endif
);

% Unavailability OK
constraint forall(c in 1..Slotstime, p in 1..Rooms)
(if Unavailability[c,p] == 1
  then Timetable_exams[c,p] = 0
  else true
  endif
);

% Assignment exams according with rooms and slotstimes   (Thanks Hakan)     
constraint forall(e in 1..Exams)                 % for each exam
(exists(r in 1..Rooms)                           % find a room
  ( ExamsRoom[e] = r         /\                  % assign the room to the exam
    forall(t in 0..Exams_duration[e]-1)               
% assign the exam to the slotstimes and room in the timetable
    (Timetable_exams[t+ExamsStart[e],r] = e)
  )
)
/\ % ensure that we have the correct number of exam slots

sum(Exams_duration) = sum([bool2int(Timetable_exams[t,r]>0) | t in 1..Slotstime, 
r in 1..Rooms]);

%---------------------------Solver--------------------------

solve satisfy;

%   solve::int_search([Timetable_exams[s, a] | s in 1..Slotstime, a in    
%   1..Rooms],first_fail,indomain_min,complete) satisfy;

そして今、出力は非常に重く、文字列でいっぱいです。

%---------------------------Output--------------------------

output ["\n" ++ "MiniZinc paper: Exams schedule " ++ "\n" ]
++["\nDay I \n"]++      
[
if r=1 then "\n" else " " endif ++
show(Timetable_exams[t,r])
| t in 1..Slotstime div Days, r in 1..Rooms
]
++["\n\nDay II \n"]++ 
[
if r=1 then "\n" else " " endif ++
show(Timetable_exams[t,r])
| t in 11..((Slotstime div Days)*2), r in 1..Rooms
]
++["\n\nDay III \n"]++ 
[
if r=1 then "\n" else " " endif ++
show(Timetable_exams[t,r])
| t in 21..((Slotstime div Days)*3), r in 1..Rooms
]
++["\n\nDay IV \n"]++ 
[
if r=1 then "\n" else " " endif ++
show(Timetable_exams[t,r])
| t in 31..((Slotstime div Days)*4), r in 1..Rooms
]
++["\n\nDay V \n"]++ 
[
if r=1 then "\n" else " " endif ++
show(Timetable_exams[t,r])
| t in 41..Slotstime, r in 1..Rooms
]
++[ "\n"]++
[
"\nExams_Room:   ", show(ExamsRoom), "\n",
"Exams_Start:  ", show(ExamsStart), "\n",
]
++["Participants: "]++
[
if e=Exams then " " else " " endif ++
show (sum([bool2int(Enrollments[st,e]>0)| st in 1..Students]))
|e in 1..Exams
];

私はデータで終了します:

%Data
Slotstime=10*Days;
Students=50;
Days=5;

% Exams
Exams = 5;
Exam_max_duration=4;
Exams_duration = [4,1,2,3,2]; 

% Rooms
Rooms = 4;
Rooms_capacity   = [20,30,40,50];

Unavailability = [|0,0,0,0           % Rooms rows % Slotstime columns
|0,0,0,0
|0,0,0,0
|0,0,0,0
|1,1,1,1
|1,1,1,1
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
                                      % End first day
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
|1,1,1,1
|1,1,1,1
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
                                      % End secon day
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
|1,1,1,1
|1,1,1,1
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
                                      % End third day
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
|1,1,1,1
|1,1,1,1
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
                                     %  End fourth day
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
|1,1,1,1
|1,1,1,1
|0,0,0,0
|0,0,0,0
|0,0,0,0
|0,0,0,0
                                       %End fifth day
|];

Enrollments= [|1,0,1,0,1        % Exams rows %Students columns              
|1,0,1,0,1
|0,1,0,0,0
|1,0,0,1,0
|0,1,0,0,0
|0,0,1,1,0
|1,0,0,1,0
|0,0,0,0,1
|1,0,0,0,1
|0,0,0,0,1
|0,1,0,0,0
|0,0,0,0,0
|0,1,0,0,1
|0,0,1,0,1
|1,0,1,0,1
|1,0,1,0,1
|0,1,0,0,0
|1,0,0,1,0
|0,1,0,0,0
|0,0,1,1,0
|1,0,0,1,0
|0,0,0,0,1
|1,0,0,0,1
|0,0,0,0,1
|0,1,0,0,0
|0,0,0,0,0
|0,1,0,0,1
|0,0,1,0,1
|1,0,1,0,1
|1,0,1,0,1
|0,1,0,0,0
|1,0,0,1,0
|0,1,0,0,0
|0,0,1,1,0
|1,0,0,1,0
|0,0,0,0,1
|1,0,0,0,1
|0,0,0,0,1
|0,1,0,0,0
|0,0,0,0,0
|0,1,0,0,1
|0,0,1,0,1
|1,0,1,0,1
|1,0,1,0,1
|0,1,0,0,0
|1,0,0,1,0
|0,1,0,0,0
|0,0,1,1,0
|1,0,0,1,0
|0,0,0,0,1
|];

前もって感謝します

4

1 に答える 1