Debian Codegraph @

tests/spec/unit/regression/bug259.mzn

raw
1 /***
2 !Test
3 solvers: [gecode]
4 expected:
5 - !Result
6 solution: !Solution
7 _output_item: !Trim |
8 sz[1][1][1][5] = 1
9 sz[1][2][1][1] = 1
10 pz[1][1][1][2][13] = 1
11 pz[1][2][1][1][13] = 1
12 obj: 62
13 - !Result
14 solution: !Solution
15 _output_item: !Trim |
16 sz[1][1][1][5] = 1
17 sz[1][2][1][1] = 1
18 pz[1][1][1][1][13] = 1
19 pz[1][2][1][2][13] = 1
20 obj: 62
21 - !Result
22 solution: !Solution
23 _output_item: !Trim |
24 sz[1][1][1][1] = 1
25 sz[1][2][1][5] = 1
26 pz[1][1][1][1][13] = 1
27 pz[1][2][1][2][13] = 1
28 obj: 62
29 - !Result
30 solution: !Solution
31 _output_item: !Trim |
32 sz[1][1][1][1] = 1
33 sz[1][2][1][5] = 1
34 pz[1][1][1][2][13] = 1
35 pz[1][2][1][1][13] = 1
36 obj: 62
37 ***/
38
39 % Regression test for bug #259: mzn2fzn (and consequently solns2out) didn't support
40 % array5d casts.
41
42 %----------------------------------------------------------------------------%
43
44
45 % Copyright (c) 2011 HighTechKids. All rights reserved
46 % HighTechKids is on the web at: http://www.hightechkids.org
47 % This code is released under GPL; see LICENSE.txt for details.
48
49 include "globals.mzn";
50
51 % run with 'minizinc -G linear -b mip' - doesn't work because of 5d arrays
52 % mzn2fzn --no-output-ozn --globals-dir linear schedule.mzn <param file>.dzn && flatzinc -b mip -o schedule.result schedule.fzn
53
54 % parameters
55 int: TInc;
56 int: TMax_hours;
57
58 % subjective setup
59 int: NSubjective;
60
61 % performance setup
62 int: NRounds;
63 int: NTables;
64
65 % judging groups
66 int: NGroups;
67
68 int: alpha_perf_minutes;
69
70 int: ct_minutes;
71 int: pct_minutes;
72
73
74
75 %%%% Don't edit below here %%%%
76 int: M = 10000;
77
78 % computed parameters
79
80 array [1..NSubjective] of int : subj_minutes;
81 array [1..NGroups] of int : group_counts;
82
83 array [1..NSubjective] of int : alpha_subj = [ x div TInc | x in subj_minutes ];
84
85 int: NTeams = sum(group_counts);
86 constraint assert(NTeams mod 2 == 0, "Number of teams must be even");
87
88 int: TMax = TMax_hours * 60 div TInc;
89 int: alpha_perf = alpha_perf_minutes div TInc;
90 int: ct = ct_minutes div TInc;
91 int: pct = pct_minutes div TInc;
92
93
94 int: MaxTeamsInGroup = max(group_counts);
95
96
97 % variables
98 array [1..NGroups, 1..MaxTeamsInGroup, 1..NSubjective, 1..TMax ] of var
99 0..1 : sz;
100 array [1..NGroups, 1..MaxTeamsInGroup, 1..NSubjective, 1..TMax ] of var
101 0..1 : sy;
102 array [1..NGroups, 1..MaxTeamsInGroup, 1..NTables, 1..2, 1..TMax ] of var
103 0..1 : pz;
104 array [1..NGroups, 1..MaxTeamsInGroup, 1..NTables, 1..2, 1..TMax ] of var
105 0..1 : py;
106 var int: obj;
107
108 % stationBusySubjective
109 constraint
110 forall(g in 1..NGroups) (
111 forall (i in 1..group_counts[g]) (
112 forall (n in 1..NSubjective) (
113 forall (t in 1..TMax) (
114 sum (u in 1..alpha_subj[n]) (
115 if(t-u+1 >= 1) then
116 sz[g,i,n,t-u+1]
117 else
118 0
119 endif
120 ) <= sy[g,i,n,t]
121 ))));
122
123 % stationBusyPerformance
124 constraint
125 forall(g in 1..NGroups) (
126 forall(i in 1..group_counts[g]) (
127 forall(b in 1..NTables) (
128 forall(s in 1..2) (
129 forall(t in alpha_perf..TMax) (
130 sum(u in 1..alpha_perf) (
131 if(t-u+1 >= 1) then
132 pz[g,i,b,s,t-u+1]
133 else
134 0
135 endif
136 ) <= py[g,i,b,s,t]
137 )))));
138
139 % stationStartSubjective
140 constraint
141 forall(g in 1..NGroups) (
142 forall (i in 1..group_counts[g]) (
143 forall (n in 1..NSubjective) (
144 forall (t in 2..TMax) (
145 sy[g,i,n,t] - sy[g,i,n,t-1] <= sz[g,i,n,t]
146 ))));
147
148 % stationStartPerformance
149 constraint
150 forall(g in 1..NGroups) (
151 forall (i in 1..group_counts[g]) (
152 forall(b in 1..NTables) (
153 forall(s in 1..2) (
154 forall(t in 2..TMax) (
155 py[g,i,b,s,t] - py[g,i,b,s,t-1] <= pz[g,i,b,s,t]
156 )))));
157
158 % noOverlapSubjective
159 constraint
160 forall(g in 1..NGroups) (
161 forall (t in 1..TMax) (
162 forall (n in 1..NSubjective) (
163 sum(i in 1..group_counts[g]) (sy[g,i,n,t]) <= 1
164 )));
165
166 % noOverlapPerformance
167 constraint
168 forall (t in 1..TMax) (
169 forall (b in 1..NTables) (
170 forall (s in 1..2) (
171 sum(g in 1..NGroups) (sum(i in 1..group_counts[g]) (py[g,i,b,s,t])) <= 1
172 )));
173
174 % teamSubjective
175 constraint
176 forall(g in 1..NGroups) (
177 forall (i in 1..group_counts[g]) (
178 forall (n in 1..NSubjective) (
179 sum (t in 1..TMax) (sz[g,i,n,t]) = 1
180 )));
181
182 % teamPerformance
183 constraint
184 forall(g in 1..NGroups) (
185 forall (i in 1..group_counts[g]) (
186 sum (b in 1..NTables) (
187 sum (t in 1..TMax) (pz[g,i,b,1,t] + pz[g,i,b,2,t])
188 ) = 1
189 ));
190
191 % subjectiveEOS
192 constraint
193 sum(g in 1..NGroups) (
194 sum (i in 1..group_counts[g]) (
195 sum (n in 1..NSubjective) (
196 sum (t in TMax-alpha_subj[n]+1..TMax) (
197 sz[g,i,n,t]
198 )))) = 0;
199
200 % performanceEOS
201 constraint
202 sum(g in 1..NGroups) (
203 sum (i in 1..group_counts[g]) (
204 sum (b in 1..NTables) (
205 sum (t in TMax-alpha_perf+1..TMax) (
206 pz[g,i,b,1,t] + pz[g,i,b,2,t]
207 )))) = 0;
208
209 int: subj_ulimit = ct-1;
210 int: subj_tlimit = TMax-subj_ulimit;
211
212 % subjSubjChangetime
213 constraint
214 forall(g in 1..NGroups) (
215 forall(i in 1..group_counts[g]) (
216 forall(n in 1..NSubjective) (
217 forall(t in 1..subj_tlimit) (
218 forall(d in 1..NSubjective) (
219 forall(u in 0..subj_ulimit) (
220 if(d != n) then
221 sy[g,i,n,t] + sy[g,i,d,t+u] <= 1
222 else
223 true
224 endif
225 ))))));
226
227 % subjPerfChangetime
228 constraint
229 forall(g in 1..NGroups) (
230 forall(i in 1..group_counts[g]) (
231 forall(n in 1..NSubjective) (
232 forall(t in 1..subj_tlimit) (
233 forall(u in 0..subj_ulimit) (
234 forall(b in 1..NTables) (
235 forall(s in 1..2) (
236 sy[g,i,n,t] + py[g,i,b,s,t+u] <= 1
237 )))))));
238
239 int: perf_ulimit = ct-1;
240 int: perf_tlimit = TMax-perf_ulimit;
241
242 % perfPerfChangetime
243 constraint
244 forall(g in 1..NGroups) (
245 forall(i in 1..group_counts[g]) (
246 forall(b in 1..NTables) (
247 forall(s in 1..2) (
248 forall(t in 1..perf_tlimit) (
249 forall(u in 0..perf_ulimit) (
250 forall(d in 1..NTables) (
251 forall(e in 1..2) (
252 if(b != d /\ s != e) then
253 py[g,i,b,s,t] + py[g,i,d,e,t+u] <= 1
254 else
255 true
256 endif
257 ))))))));
258
259 % perfSubjChangetime
260 constraint
261 forall(g in 1..NGroups) (
262 forall(i in 1..group_counts[g]) (
263 forall(b in 1..NTables) (
264 forall(s in 1..2) (
265 forall(t in 1..perf_tlimit) (
266 forall(u in 0..perf_ulimit) (
267 forall(n in 1..NSubjective) (
268 py[g,i,b,s,t] + sy[g,i, n, t+u] <= 1
269 )))))));
270
271 int: perf_pct_ulimit = pct-1;
272 int: perf_pct_tlimit = TMax-perf_pct_ulimit;
273
274 % performanceChangetime
275 constraint
276 forall(g in 1..NGroups) (
277 forall(i in 1..group_counts[g]) (
278 forall(t in 1..perf_pct_tlimit) (
279 forall(u in 1..perf_pct_ulimit) (
280 sum(b in 1..NTables) (
281 py[g,i,b,1,t] + py[g,i,b,2,t] + py[g,i,b,1,t+u] + py[g,i,b,2,t+u]
282 ) <= 1
283 ))));
284
285 % perfUseBothSides
286 constraint
287 forall(b in 1..NTables) (
288 forall(t in 1..TMax) (
289 sum(g in 1..NGroups) (sum(i in 1..group_counts[g]) (py[g,i,b,1,t]))
290 = sum(g in 1..NGroups) (sum(i in 1..group_counts[g]) (py[g,i,b,2,t]))
291 ));
292
293 % teamJudging
294 constraint
295 forall(g in 1..NGroups) (
296 forall(i in 1..group_counts[g]) (
297 sum(t in 1..TMax) (
298 sum(n in 1..NSubjective) (
299 sz[g,i,n,t] +
300 sum(b in 1..NTables) (
301 pz[g,i,b,1,t] + pz[g,i,b,2,t]
302 ))) = NSubjective + NRounds
303 ));
304
305
306 % performanceStart
307 int: perfStartWait = 60 div TInc;
308 constraint
309 sum(g in 1..NGroups) (
310 sum(i in 1..group_counts[g]) (
311 sum(b in 1..NTables) (
312 sum(t in 1..perfStartWait) (
313 pz[g,i,b,1,t] + pz[g,i,b,2,t]
314 )))) = 0;
315
316 % objective
317 constraint
318 sum(t in 1..TMax) (
319 sum(g in 1..NGroups) (
320 sum(i in 1..group_counts[g]) (
321 sum(n in 1..NSubjective) (
322 sy[g,i,n,t] * t
323 ) +
324 sum(b in 1..NTables) (
325 (py[g,i,b,1,t] + py[g,i,b,2,t]) * t
326 )
327 ))) = obj;
328
329
330 solve minimize obj;
331
332 output
333 [ if fix(sz[g,i,n,t]) == 1 then
334 "sz[" ++ show(g) ++ "][" ++ show(i) ++ "][" ++ show(n) ++ "][" ++ show(t) ++ "] = " ++
335 show(sz[g, i, n, t]) ++ "\n"
336 else
337 ""
338 endif
339 | g in 1..NGroups, i in 1..group_counts[g], n in 1..NSubjective, t in 1..TMax
340 ]
341 ++ [
342 if fix(pz[g,i,b,s,t]) == 1 then
343 "pz[" ++ show(g) ++ "][" ++ show(i) ++ "][" ++ show(b) ++ "][" ++ show(s) ++ "][" ++ show(t) ++ "] = "
344 ++ show(pz[g, i, b, s, t]) ++ "\n"
345 else
346 ""
347 endif
348 | g in 1..NGroups, i in 1..group_counts[g], b in 1..NTables, s in 1..2, t in 1..TMax
349 ]
350 ++ ["\n"];
351
352 % Instance data
353
354 TInc = 5;
355 TMax_hours = 8;
356
357 % subjective setup
358 NSubjective = 1;
359 subj_minutes = [20];
360
361 % performance setup
362 NRounds = 1;
363 NTables = 1;
364
365 % judging groups
366 NGroups = 1;
367 group_counts = [2];
368
369 alpha_perf_minutes = 5;
370
371 ct_minutes = 15;
372 pct_minutes = 45;