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