├── CP ├── .DS_Store ├── alldifferent │ ├── monster_defence.mzn │ └── monster_defence_fail.mzn ├── bounds_propagation │ ├── bounds_propagation1.mzn │ ├── bounds_propagation2.mzn │ ├── bounds_propagation3.mzn │ ├── bounds_propagation4.mzn │ └── bounds_propagation5.mzn ├── cumulative │ └── gate_crossing.mzn ├── domain_propagation │ ├── domain_propagation1.mzn │ └── dragon_veins.mzn ├── flattening │ ├── FLATTENING.zip │ ├── flattening1.mzn │ ├── flattening10.mzn │ ├── flattening11.mzn │ ├── flattening12.mzn │ ├── flattening13.mzn │ ├── flattening14.mzn │ ├── flattening2.mzn │ ├── flattening3.mzn │ ├── flattening4.mzn │ ├── flattening5.mzn │ ├── flattening6.mzn │ ├── flattening7.mzn │ ├── flattening8.mzn │ └── flattening9.mzn ├── heavens │ └── heavens.mzn ├── optimization │ ├── 100potions.dzn │ ├── 4potions.dzn │ └── yaocao.mzn ├── propagation_engine │ └── village.mzn ├── restart │ ├── .DS_Store │ ├── archery.mzn │ ├── domwdeg.mzn │ ├── qwh-o30-h374-01.dzn │ ├── qwh-o30-h374-02.dzn │ ├── qwh-o30-h374-03.dzn │ ├── qwh-o30-h374-04.dzn │ ├── qwh-o30-h374-05.dzn │ ├── qwh-o30-h374-06.dzn │ ├── qwh-o30-h374-07.dzn │ ├── qwh-o30-h374-08.dzn │ ├── qwh-o30-h374-09.dzn │ ├── qwh-o30-h374-10.dzn │ ├── qwh-o30-h374-11.dzn │ ├── qwh-o30-h374-12.dzn │ ├── qwh-o30-h374-13.dzn │ ├── qwh-o30-h374-14.dzn │ ├── qwh-o30-h374-15.dzn │ ├── qwh-o30-h374-16.dzn │ ├── qwh-o30-h374-17.dzn │ ├── qwh-o30-h374-18.dzn │ ├── qwh-o30-h374-19.dzn │ ├── qwh-o30-h374-20.dzn │ ├── qwh-o30-h375-01.dzn │ ├── qwh-o30-h375-02.dzn │ ├── qwh-o30-h375-03.dzn │ ├── qwh-o30-h375-04.dzn │ ├── qwh-o30-h375-05.dzn │ ├── qwh-o30-h375-06.dzn │ ├── qwh-o30-h375-07.dzn │ ├── qwh-o30-h375-08.dzn │ ├── qwh-o30-h375-09.dzn │ ├── qwh-o30-h375-10.dzn │ ├── qwh-o30-h375-11.dzn │ ├── qwh-o30-h375-12.dzn │ ├── qwh-o30-h375-13.dzn │ ├── qwh-o30-h375-14.dzn │ ├── qwh-o30-h375-15.dzn │ ├── qwh-o30-h375-16.dzn │ ├── qwh-o30-h375-17.dzn │ ├── qwh-o30-h375-18.dzn │ ├── qwh-o30-h375-19.dzn │ └── qwh-o30-h375-20.dzn └── search │ ├── herbs.mzn │ ├── herbs1.mzn │ ├── herbs2.mzn │ └── revherbs.mzn ├── LS ├── escaping_local_minima │ ├── intestine.mzn │ ├── most_painful.mzn │ └── stomach.mzn ├── firefighting │ ├── fire.mzn │ ├── large.dzn │ └── small.dzn ├── lagrange │ └── beast_search.mzn ├── monkey │ ├── monkey.dzn │ └── monkey.mzn └── princess │ └── princess.mzn ├── MIP ├── .DS_Store ├── linear_programming │ ├── .DS_Store │ ├── initial_BFS.mzn │ └── shield.mzn └── mixed_integer_programming │ ├── NEWSHIELD.zip │ ├── newshield.mzn │ ├── newshield1.mzn │ ├── newshield10.mzn │ ├── newshield11.mzn │ ├── newshield12.mzn │ ├── newshield13.mzn │ ├── newshield14.mzn │ ├── newshield15.mzn │ ├── newshield16.mzn │ ├── newshield17.mzn │ ├── newshield18.mzn │ ├── newshield19.mzn │ ├── newshield2.mzn │ ├── newshield20.mzn │ ├── newshield21.mzn │ ├── newshield22.mzn │ ├── newshield23.mzn │ ├── newshield24.mzn │ ├── newshield25.mzn │ ├── newshield26.mzn │ ├── newshield27.mzn │ ├── newshield28.mzn │ ├── newshield3.mzn │ ├── newshield4.mzn │ ├── newshield5.mzn │ ├── newshield6.mzn │ ├── newshield7.mzn │ ├── newshield8.mzn │ ├── newshield9.mzn │ └── newshield_int.mzn ├── debugging ├── debug │ ├── debug1.mzn │ ├── prod-plan-weapon.dzn │ └── prod-plan.mzn ├── escape │ ├── escape.dzn │ ├── escape-fixed.mzn │ └── escape.mzn ├── parade │ ├── parade.dzn │ ├── parade.mzn │ ├── parade0.dzn │ └── parade1.dzn ├── sneak │ ├── sneak.mzn │ └── sneakFixed.mzn ├── twogenerals │ ├── twogenerals.mzn │ └── twogeneralsFixed.mzn └── wedge │ ├── wedge-corrected.mzn │ ├── wedge-fix1.mzn │ ├── wedge-fixed.mzn │ ├── wedge-trace.mzn │ ├── wedge.dzn │ ├── wedge.mzn │ └── wedgePETER.dzn ├── functions ├── catapult │ ├── catapult.dzn │ ├── catapult.mzn │ └── catapultExact.mzn ├── cellblock │ ├── cellBlock.dzn │ └── cellBlock.mzn ├── lvbu │ ├── lvbu.dzn │ └── lvbu.mzn └── patrol │ ├── patrol.dzn │ ├── patrolChannel.mzn │ ├── patrolSet.mzn │ ├── patrolV1.mzn │ ├── patrolV2.mzn │ ├── patrolV3.mzn │ ├── patrolV4.mzn │ ├── patrolV5.mzn │ └── patrolV6.mzn ├── introduction ├── army │ ├── army.dzn │ ├── army.mzn │ ├── armyd.mzn │ ├── gatheringanarmy-cheap.mzn │ └── gatheringanarmy-strong.mzn ├── banquet │ ├── banquet.mzn │ ├── banquet1.dzn │ └── banquet2.dzn ├── color │ └── color.mzn ├── count │ └── count.mzn ├── loan │ ├── loan.mzn │ ├── loan1.dzn │ ├── loan2.dzn │ └── loan3.dzn ├── production │ ├── prod-plan-army.dzn │ ├── prod-plan-weapon.dzn │ └── prod-plan.mzn └── rods │ └── rods.mzn ├── multiplemodeling ├── acupuncture │ ├── acupuncture.dzn │ └── acupuncture.mzn ├── belt │ ├── belt.dzn │ ├── beltComb.mzn │ ├── beltDig.mzn │ └── beltPos.mzn ├── cookingwine │ ├── combined.mzn │ ├── cookWine.dzn │ ├── foodToWine.mzn │ └── wineToFood.mzn └── tunnel │ ├── tunnel.dzn │ └── tunnel.mzn ├── packing ├── rectangles │ ├── sbpnorotate.dzn │ └── sbpnorotate.mzn ├── rotation │ ├── sbprgeost.dzn │ ├── sbprgeost.mzn │ ├── sbprotate.dzn │ ├── sbprotate.mzn │ └── sbprotategeost.mzn └── squares │ ├── large.dzn │ ├── multisqpack.mzn │ ├── multisqpackimp.mzn │ ├── multisqpacking copy.dzn │ ├── multisqpacking copy.mzn │ ├── small.dzn │ └── testing.mzn ├── predicates ├── armyselect │ ├── armySelect.dzn │ ├── armySelect.mzn │ └── armySelectPred.mzn ├── bandits │ ├── bandits.dzn │ └── bandits.mzn ├── brigades │ ├── brigades.mzn │ └── even.mzn └── tableseating │ ├── table_seating.dzn │ ├── table_seating.mzn │ └── table_seating_imp.mzn ├── scheduling ├── basic │ ├── basic_sched.dzn │ └── basic_sched.mzn ├── cumulative │ ├── cumul_sched.dzn │ └── cumul_sched.mzn ├── disjunctive │ ├── disj_sched_1.dzn │ ├── disj_sched_1.mzn │ ├── disj_sched_2.dzn │ ├── disj_sched_2.mzn │ └── disj_sched_glo.mzn └── seqdependent │ ├── doubleChannel.dzn │ ├── doubleChannel.mzn │ ├── singleChannel.dzn │ └── singleChannel.mzn ├── sets ├── bagua │ ├── bagua-10-8.dzn │ ├── bagua.mzn │ ├── baguaBounded-10-8.dzn │ ├── baguaBoundedInt.mzn │ ├── baguaBoundedIntW.mzn │ ├── baguaBoundedSet.mzn │ ├── baguaCard-10-8.dzn │ ├── baguaCardInt.mzn │ └── baguaCardSet.mzn └── yellowturban │ ├── yellow-data.dzn │ ├── yellow.mzp │ ├── yellow01.mzn │ ├── yellow01Basic.mzn │ ├── yellow01Bool.mzn │ ├── yellow01Set.mzn │ └── yellow01SetConcise.mzn ├── symmetry ├── crossbow │ ├── crossbow-lex.mzn │ ├── crossbow-lib.mzn │ └── crossbow.mzn ├── lamp │ ├── double_lex.mzn │ ├── lamp-dl.mzn │ ├── lamp-sym.mzn │ ├── lamp.dzn │ └── lamp.mzn ├── road │ ├── road.dzn │ ├── road.mzn │ └── roaddom.mzn ├── square │ ├── var_perm_sym.mzn │ └── var_sqr_sym.mzn └── wind │ ├── wind.dzn │ ├── wind.mzn │ ├── windchanvar.mzn │ └── windprec.mzn └── workshops ├── composition_solution.mzn ├── compositiondual_solution.mzn ├── elephant1_solution.mzn ├── feasttrap_solution.mzn ├── plasters_solution.mzn ├── plasters_solution_dominance.mzn ├── poetry_solution.mzn ├── surrender_solution.mzn ├── surrender_solution_set.mzn ├── temperature_solution.mzn ├── visit_zhuge_solution.mzn └── visit_zhuge_solution_output.mzn /CP/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniZinc/specialization-examples/d890155c32b597fbbd560645c4bfd94cb2f0e3e4/CP/.DS_Store -------------------------------------------------------------------------------- /CP/alldifferent/monster_defence.mzn: -------------------------------------------------------------------------------- 1 | var {1,2,3}: X; 2 | var {2,3}: Y; 3 | var {2,3}: Z; 4 | var {1,2,3,4,5}: T; 5 | var {3,4,5,6}: U; 6 | include "alldifferent.mzn"; 7 | constraint alldifferent([X,Y,Z,T,U]); 8 | solve satisfy; 9 | -------------------------------------------------------------------------------- /CP/alldifferent/monster_defence_fail.mzn: -------------------------------------------------------------------------------- 1 | var {1,2}: X; 2 | var {1,2}: Y; 3 | var {1,2}: Z; 4 | var {2,3,4,5}: T; 5 | var {3,4,5,6}: U; 6 | include "alldifferent.mzn"; 7 | constraint alldifferent([X,Y,Z,T,U]); 8 | solve satisfy; 9 | -------------------------------------------------------------------------------- /CP/bounds_propagation/bounds_propagation1.mzn: -------------------------------------------------------------------------------- 1 | var -7..4: X; 2 | var -5..-3: Y; 3 | constraint X = abs(Y); 4 | solve satisfy; 5 | -------------------------------------------------------------------------------- /CP/bounds_propagation/bounds_propagation2.mzn: -------------------------------------------------------------------------------- 1 | var 3..5: X; 2 | var -4..1: Y; 3 | constraint X = abs(Y); 4 | solve satisfy; 5 | -------------------------------------------------------------------------------- /CP/bounds_propagation/bounds_propagation3.mzn: -------------------------------------------------------------------------------- 1 | var 0..9: W; 2 | var 0..9: P; 3 | var 0..9: C; 4 | constraint 4*W + 3*P + 2*C <= 9; 5 | solve satisfy; 6 | -------------------------------------------------------------------------------- /CP/bounds_propagation/bounds_propagation4.mzn: -------------------------------------------------------------------------------- 1 | var 0..5: X; 2 | var -2..3: Y; 3 | var 1..6: Z; 4 | constraint X = Y * Z; 5 | solve satisfy; 6 | -------------------------------------------------------------------------------- /CP/bounds_propagation/bounds_propagation5.mzn: -------------------------------------------------------------------------------- 1 | var 3..5: X; 2 | var -2..3: Y; 3 | var 2..6: Z; 4 | constraint X = Y * Z; 5 | solve satisfy; 6 | -------------------------------------------------------------------------------- /CP/cumulative/gate_crossing.mzn: -------------------------------------------------------------------------------- 1 | var 0..30: H; 2 | var 0..30: Co; 3 | var 0..30: Ca; 4 | var 0..30: T; 5 | constraint H + 15 <= Ca; 6 | constraint H <= 15 /\ Co <= 18 /\ Ca <= 20 /\ T <= 22; 7 | include "cumulative.mzn"; 8 | constraint cumulative([H,Co,Ca,T],[15,12,10,8],[3,1,2,2],4); 9 | solve satisfy; 10 | -------------------------------------------------------------------------------- /CP/domain_propagation/domain_propagation1.mzn: -------------------------------------------------------------------------------- 1 | 2 | var 2..7: X; 3 | var 0..2: Y; 4 | var -1..2: Z; 5 | constraint X = 3*Y + 5*Z; 6 | solve satisfy; 7 | -------------------------------------------------------------------------------- /CP/domain_propagation/dragon_veins.mzn: -------------------------------------------------------------------------------- 1 | var {-20,-11,-5,-2,1,2,7,15}: X; 2 | var {-13,-10,-7,-3,0,8,9}: Y; 3 | constraint abs(X) + abs(Y) = 10; 4 | solve satisfy; 5 | -------------------------------------------------------------------------------- /CP/flattening/FLATTENING.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniZinc/specialization-examples/d890155c32b597fbbd560645c4bfd94cb2f0e3e4/CP/flattening/FLATTENING.zip -------------------------------------------------------------------------------- /CP/flattening/flattening1.mzn: -------------------------------------------------------------------------------- 1 | int: i = 3; int: j = 2; 2 | var int: x; var 0..2: y; var 0..3: z; 3 | constraint x*y + y*z <= i*j; 4 | 5 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening10.mzn: -------------------------------------------------------------------------------- 1 | predicate far_or_equal(var int:x1, var int:y1, 2 | var int:x2, var int:y2)= 3 | man_dist(x1,y1,x2,y2) >= 4 \/ 4 | (x1 = x2 /\ y1 = y2); 5 | 6 | function var int: man_dist(var int:u1, 7 | var int:v1, var int:u2, var int:v2) = 8 | abs(u1 - u2) + abs(v1 - v2); 9 | 10 | var 0..4: a; var 0..4: b; var 0..4: c; var 0..4: d; 11 | constraint far_or_equal(a,b,c,d); 12 | 13 | solve satisfy; 14 | -------------------------------------------------------------------------------- /CP/flattening/flattening11.mzn: -------------------------------------------------------------------------------- 1 | 2 | include "alldifferent.mzn"; 3 | predicate all_different_int_reif( 4 | array[int] of var int: a, var bool: b) = 5 | b <-> forall(i, j in index_set(a) where i < j) 6 | (a[i] != a[j]); 7 | 8 | var 0..3: x; var 0..3: y; var 0..3: z; var 0..3: t; 9 | constraint alldifferent([x,y,z]); 10 | constraint alldifferent([y,z,t]) -> x = 0; 11 | 12 | solve satisfy; 13 | 14 | -------------------------------------------------------------------------------- /CP/flattening/flattening12.mzn: -------------------------------------------------------------------------------- 1 | array[1..2] of var 0..25: a; 2 | 3 | constraint not (8 >= sum(i in 1..2)(sqrt(a[i]))); 4 | function var int:sqrt(var int: x) :: promise_total = 5 | let { var int: y; 6 | constraint y * y = x /\ y >= 0 } in y; 7 | 8 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening13.mzn: -------------------------------------------------------------------------------- 1 | array[1..2] of var 0..25: a; 2 | 3 | constraint 8 < sum(i in 1..2)(sqrt(a[i])); 4 | function var int:sqrt(var int: x) :: promise_total = 5 | let { var int: y; 6 | constraint y * y = x /\ y >= 0 } in y; 7 | 8 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening14.mzn: -------------------------------------------------------------------------------- 1 | var -3..3: y; 2 | constraint (let { var int: x = 9 div y } 3 | in x * y != 9) -> y != 2; 4 | 5 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening2.mzn: -------------------------------------------------------------------------------- 1 | int: i = 3; int: j = 3; 2 | var 0..5: x; var 0..2: y; var 0..3: z; 3 | constraint (x - i) * (x - j) + y + z + i + j >= 0; 4 | 5 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening3.mzn: -------------------------------------------------------------------------------- 1 | var -2..2: x; 2 | var 0..4: y; 3 | constraint x * x + y * y <= 6; 4 | 5 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening4.mzn: -------------------------------------------------------------------------------- 1 | var 0..5: x; var 0..2: y; var 0..3: z; 2 | int: k = 4; 3 | constraint x + 2*(y - x) + z <= k*z; 4 | 5 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening5.mzn: -------------------------------------------------------------------------------- 1 | int: n; set of int: OBJ = 1..n; 2 | array[OBJ] of int: size; 3 | array[OBJ] of int: value; 4 | int: limit; 5 | array[OBJ] of var int: x; 6 | constraint forall(i in OBJ)(x[i] >= 0); 7 | constraint sum(i in OBJ)(size[i]*x[i])<= limit; 8 | solve maximize sum(i in OBJ)(value[i]*x[i]); 9 | n = 4; 10 | size = [5,8,9,12]; 11 | value = [3,5,7,8]; 12 | limit = 29; 13 | -------------------------------------------------------------------------------- /CP/flattening/flattening6.mzn: -------------------------------------------------------------------------------- 1 | array[0..2,0..2] of var 0..2: x; 2 | constraint sum(i in 0..2)(x[i,i]) <= 1; 3 | constraint x[x[1,1],1] = 2; 4 | 5 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening7.mzn: -------------------------------------------------------------------------------- 1 | var -2..2: x; var -1..2: y; var bool: b; 2 | constraint if b then x else y endif >= 0; 3 | 4 | solve satisfy; 5 | -------------------------------------------------------------------------------- /CP/flattening/flattening8.mzn: -------------------------------------------------------------------------------- 1 | var -2..2: x; var -1..2: y; 2 | var -2..2: z; var -1..2: u; var 0..3: t; 3 | constraint x > 0 -> bool2int(y > 0 /\ z > 0) + t >= u; 4 | 5 | solve satisfy; -------------------------------------------------------------------------------- /CP/flattening/flattening9.mzn: -------------------------------------------------------------------------------- 1 | var -2..2: x; var -1..2: y; 2 | var -2..2: z; var -1..2: u; var 0..3: t; 3 | constraint x <= 0 \/ bool2int(y > 0 /\ z > 0) + t >= u; 4 | 5 | solve satisfy; -------------------------------------------------------------------------------- /CP/heavens/heavens.mzn: -------------------------------------------------------------------------------- 1 | include "alldifferent.mzn"; 2 | 3 | set of int: RANGE = 1..9; 4 | 5 | array[RANGE, RANGE] of var RANGE: cell; 6 | 7 | constraint cell[2,1] = 7 /\ cell[2,2] = 8 /\ cell[2,5] = 1 /\ 8 | cell[3,5] = 2 /\ cell[3,8] = 3 /\ 9 | cell[4,4] = 3 /\ cell[4,5] = 4 /\ 10 | cell[5,2] = 6 /\ cell[5,5] = 5 /\ cell[5,8] = 1 /\ 11 | cell[6,5] = 6 /\ 12 | cell[7,5] = 7 /\ 13 | cell[8,1] = 5 /\ cell[8,2] = 4 /\ cell[8,5] = 8 /\ 14 | cell[8,6] = 6 /\ cell[8,7] = 9 /\ cell[8,8] = 7 /\ 15 | cell[9,5] = 9; 16 | 17 | constraint forall(i in RANGE) 18 | (alldifferent([cell[i,j] | j in RANGE])); 19 | constraint forall(j in RANGE) 20 | (alldifferent([cell[i,j] | i in RANGE])); 21 | constraint forall(s in 1..3, t in 1..3)(alldifferent( 22 | [cell[i+(s-1)*3,j+(t-1)*3] | i in 1..3, j in 1..3] ) 23 | ); 24 | 25 | solve satisfy; 26 | 27 | output [show(cell[i,j]) ++ if j = 9 then "\n" else " " endif | i in RANGE, j in RANGE]; -------------------------------------------------------------------------------- /CP/optimization/4potions.dzn: -------------------------------------------------------------------------------- 1 | n = 4; 2 | m = 4; 3 | w = 2; 4 | p = 8; 5 | capacity= 19; 6 | 7 | nutrient = 8 | [|4,2,3,7 9 | |3,8,20,20 10 | |5,4,6,20 11 | |3,6,2,20 12 | |]; 13 | 14 | leave = 15 | [|7,6,4,8 16 | |5,8,0,0 17 | |5,4,7,0 18 | |6,9,3,0 19 | |]; -------------------------------------------------------------------------------- /CP/optimization/yaocao.mzn: -------------------------------------------------------------------------------- 1 | int: n; % number of potions 2 | set of int: POTIONS = 1..n; 3 | int: w; % window size 4 | int: p; % num of leaves in each window 5 | int: capacity; % capacity of nutrients 6 | int: m; % max number of grown segments 7 | set of int: SEGMENTS = 1..m; 8 | 9 | array[POTIONS,SEGMENTS] of int: nutrient; % nutrient required 10 | array[POTIONS,SEGMENTS] of int: leave; % num of leaves to grow 11 | 12 | array[POTIONS] of var SEGMENTS: choice; %Choice of segment for each potion 13 | array[POTIONS] of var int: nutrient_list = 14 | [nutrient[i,choice[i]] | i in POTIONS]; 15 | array[POTIONS] of var int: leave_list = 16 | [leave[i,choice[i]] | i in POTIONS]; 17 | 18 | var int: total_nutrient = sum(nutrient_list); 19 | var int: total_leaves = sum(leave_list); 20 | 21 | constraint assert(n>=w,"Window Size larger than # of steps"); 22 | 23 | %Capacity 24 | constraint total_nutrient <= capacity; 25 | %In each window, leave numbers should be larger than p 26 | constraint forall(tail in w..n) 27 | (sum(i in tail-w+1..tail)(leave_list[i]) >= p); 28 | 29 | solve :: ssearch2 maximize total_leaves; 30 | 31 | ann: search1 = int_search(leave_list, input_order, indomain_min, complete); 32 | ann: search2 = int_search(leave_list, input_order, indomain_max, complete); 33 | ann: search3 = int_search(leave_list, largest, indomain_min, complete); 34 | ann: search4 = int_search(leave_list, largest, indomain_max, complete); 35 | ann: search5 = int_search(leave_list, smallest, indomain_min, complete); 36 | ann: search6 = int_search(leave_list, smallest, indomain_max, complete); 37 | 38 | ann: ssearch1 = seq_search([search1, 39 | int_search([total_leaves], input_order, indomain_max, complete) ]); 40 | ann: ssearch2 = seq_search([ 41 | int_search([total_leaves], input_order, indomain_max, complete), 42 | search1 ]); 43 | 44 | output ["choice = ",show(choice),";\n","total_leaves = ",show(total_leaves),";\n","total_nutrient = ", show(total_nutrient)]; -------------------------------------------------------------------------------- /CP/restart/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniZinc/specialization-examples/d890155c32b597fbbd560645c4bfd94cb2f0e3e4/CP/restart/.DS_Store -------------------------------------------------------------------------------- /CP/restart/archery.mzn: -------------------------------------------------------------------------------- 1 | % Based on model given in Prob 067: Quasigroup Completion on CSPLib 2 | % http://www.csplib.org/Problems/prob067/models/ 3 | 4 | include "alldifferent.mzn"; 5 | 6 | int: N; 7 | int: digs = ceil(log(10.0,int2float(N))); % digits for output 8 | set of int: COLOR = 1..N; 9 | 10 | array[COLOR,COLOR] of 0..N: start; %% initial board 0 = empty 11 | array[COLOR,COLOR] of var COLOR: cell; 12 | array[1..N*N] of var COLOR: celllist = [cell[i,j] | i,j in COLOR]; 13 | 14 | % fill initial board 15 | constraint forall(i,j in COLOR)( 16 | if start[i,j] > 0 then cell[i,j] = start[i,j] else true endif ); 17 | 18 | % All different in rows 19 | constraint forall (i in COLOR) ( 20 | alldifferent( [ cell[i,j] | j in COLOR ] ) )::domain; 21 | 22 | % All different in columns. 23 | constraint forall (j in COLOR) ( 24 | alldifferent( [ cell[i,j] | i in COLOR ] ) )::domain; 25 | 26 | ann: random = int_search(celllist, first_fail, indomain_random, complete); 27 | ann: domwdeg_random = int_search(celllist, dom_w_deg, indomain_random, complete); 28 | 29 | % solve::random satisfy; 30 | % solve::domwdeg_random satisfy; 31 | 32 | ann: search0 = int_search(celllist, input_order, indomain_min, complete); 33 | ann: search1 = int_search(celllist, first_fail, indomain_min, complete); 34 | ann: search2 = int_search(celllist, first_fail, indomain_max, complete); 35 | ann: search3 = int_search(celllist, first_fail, indomain_median, complete); 36 | solve::search0 satisfy; 37 | % solve satisfy; 38 | 39 | 40 | 41 | output [ show_int(digs, cell[i,j]) ++ " " ++ 42 | if j == N /\ i != N then "\n" else "" endif 43 | | i,j in COLOR ] ++ ["\n"]; 44 | -------------------------------------------------------------------------------- /CP/restart/domwdeg.mzn: -------------------------------------------------------------------------------- 1 | array[1..15] of var 0..1: b; 2 | array[1..4] of var 1..100: x; 3 | array[1..19] of var int: vlist = 4 | [b[i] | i in 1..15] ++ [x[i]| i in 1..4]; 5 | 6 | include "alldifferent.mzn"; 7 | constraint sum(b) >= 1; 8 | constraint alldifferent(x) /\ x[1] = x[2]; 9 | 10 | ann: search1 = int_search(vlist, first_fail, indomain_min, complete); 11 | ann: search2 = int_search(vlist, dom_w_deg, indomain_min, complete); 12 | 13 | solve::search1 satisfy; -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h374-11.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 21, 28, 27, 0, 0, 22, 29, 6, 3, 11, 23, 0, 0, 0, 0, 0, 15, 0, 18, 9, 26, 8, 0, 0, 12, 30, 0, 4, 1, 0| 4 | 19, 0, 3, 0, 24, 30, 0, 18, 0, 1, 14, 8, 6, 26, 22, 0, 0, 16, 0, 0, 0, 0, 4, 0, 0, 20, 17, 0, 7, 9| 5 | 30, 0, 20, 14, 0, 17, 25, 3, 22, 2, 0, 9, 8, 24, 0, 0, 28, 15, 0, 23, 0, 0, 29, 4, 26, 0, 0, 27, 0, 0| 6 | 5, 21, 23, 0, 27, 0, 1, 0, 0, 12, 0, 0, 19, 0, 0, 6, 0, 20, 16, 30, 15, 10, 0, 14, 11, 0, 0, 0, 22, 4| 7 | 0, 3, 0, 23, 21, 0, 0, 0, 0, 28, 24, 13, 5, 7, 11, 16, 20, 6, 0, 0, 25, 9, 0, 18, 0, 8, 1, 0, 0, 0| 8 | 22, 0, 4, 1, 0, 6, 0, 12, 18, 0, 29, 23, 30, 13, 0, 24, 25, 0, 28, 0, 10, 0, 0, 0, 21, 0, 26, 0, 15, 2| 9 | 23, 14, 19, 24, 0, 16, 21, 5, 0, 15, 0, 0, 4, 0, 6, 0, 0, 0, 0, 25, 2, 13, 3, 0, 20, 17, 8, 22, 0, 0| 10 | 6, 23, 0, 0, 20, 29, 26, 0, 10, 27, 19, 12, 17, 18, 0, 0, 0, 0, 0, 5, 7, 22, 24, 30, 0, 0, 2, 0, 13, 0| 11 | 9, 29, 7, 11, 17, 0, 0, 27, 0, 0, 30, 25, 0, 5, 0, 0, 6, 0, 21, 20, 4, 0, 0, 8, 19, 13, 0, 0, 23, 18| 12 | 0, 0, 12, 5, 25, 0, 17, 2, 7, 26, 9, 0, 28, 0, 1, 0, 24, 3, 0, 0, 0, 30, 0, 21, 0, 0, 14, 18, 0, 11| 13 | 0, 26, 29, 15, 0, 1, 0, 19, 9, 0, 0, 11, 12, 27, 23, 17, 0, 21, 0, 0, 16, 7, 5, 0, 0, 22, 0, 0, 28, 0| 14 | 28, 0, 0, 0, 13, 0, 4, 0, 0, 0, 0, 17, 1, 0, 0, 25, 0, 29, 30, 21, 19, 24, 15, 3, 6, 0, 18, 14, 5, 0| 15 | 0, 5, 0, 21, 0, 18, 3, 20, 6, 0, 7, 0, 23, 25, 0, 10, 16, 0, 0, 11, 0, 15, 9, 2, 27, 0, 0, 0, 0, 29| 16 | 0, 27, 0, 10, 1, 0, 0, 23, 0, 0, 22, 20, 11, 0, 9, 14, 13, 0, 3, 0, 24, 0, 21, 29, 0, 18, 19, 15, 0, 26| 17 | 0, 0, 17, 4, 0, 0, 9, 7, 11, 3, 0, 16, 10, 21, 26, 0, 0, 19, 0, 0, 0, 0, 27, 5, 0, 1, 23, 20, 8, 28| 18 | 20, 0, 0, 0, 2, 0, 13, 0, 8, 0, 0, 5, 0, 14, 3, 15, 0, 24, 11, 17, 0, 25, 16, 23, 0, 21, 0, 29, 18, 6| 19 | 0, 0, 28, 22, 6, 11, 10, 21, 12, 0, 25, 0, 3, 0, 2, 0, 0, 0, 0, 0, 27, 4, 1, 26, 0, 9, 24, 0, 20, 15| 20 | 0, 16, 18, 0, 0, 0, 27, 0, 30, 8, 4, 15, 0, 6, 0, 22, 0, 17, 26, 0, 0, 20, 0, 1, 23, 29, 10, 9, 0, 0| 21 | 0, 0, 0, 0, 26, 0, 0, 0, 14, 17, 0, 6, 2, 3, 21, 13, 27, 0, 23, 0, 22, 18, 0, 0, 29, 24, 12, 0, 9, 7| 22 | 1, 12, 0, 30, 22, 0, 0, 0, 4, 29, 16, 0, 24, 0, 0, 19, 8, 0, 25, 14, 0, 0, 0, 0, 13, 6, 9, 5, 2, 23| 23 | 25, 0, 9, 0, 0, 28, 6, 29, 0, 30, 0, 18, 16, 11, 0, 27, 10, 7, 5, 0, 0, 0, 0, 15, 4, 0, 20, 0, 0, 13| 24 | 2, 0, 21, 7, 0, 24, 20, 26, 0, 5, 0, 0, 29, 9, 0, 0, 23, 28, 8, 0, 30, 11, 10, 25, 3, 0, 0, 0, 17, 0| 25 | 14, 22, 0, 0, 19, 20, 0, 0, 25, 0, 5, 2, 0, 0, 0, 0, 18, 10, 1, 4, 8, 27, 26, 6, 0, 0, 0, 24, 21, 0| 26 | 0, 9, 10, 0, 3, 0, 19, 0, 16, 0, 18, 4, 0, 1, 29, 21, 22, 5, 7, 27, 0, 0, 0, 0, 17, 0, 11, 12, 0, 0| 27 | 0, 4, 13, 29, 0, 15, 0, 1, 0, 0, 26, 0, 0, 30, 12, 8, 7, 0, 0, 0, 0, 28, 0, 17, 5, 16, 0, 19, 3, 20| 28 | 0, 11, 0, 20, 16, 2, 22, 24, 0, 10, 1, 0, 0, 4, 8, 7, 0, 23, 6, 18, 28, 0, 0, 0, 25, 0, 0, 17, 19, 0| 29 | 10, 17, 14, 0, 5, 23, 0, 30, 21, 18, 0, 0, 0, 0, 27, 0, 4, 0, 0, 7, 0, 1, 19, 0, 0, 2, 29, 3, 0, 12| 30 | 0, 2, 0, 0, 18, 8, 0, 0, 0, 13, 21, 0, 0, 28, 20, 11, 0, 12, 22, 3, 9, 6, 25, 10, 0, 5, 0, 16, 0, 27| 31 | 15, 20, 0, 12, 14, 7, 0, 0, 23, 19, 0, 3, 0, 0, 13, 30, 11, 8, 4, 16, 0, 0, 17, 0, 28, 25, 0, 0, 0, 24| 32 | 24, 0, 0, 9, 0, 26, 11, 0, 29, 0, 3, 10, 0, 0, 14, 0, 19, 25, 0, 22, 6, 0, 30, 0, 18, 7, 27, 1, 0, 16|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h374-13.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 0, 13, 6, 0, 16, 0, 0, 17, 12, 19, 0, 5, 20, 0, 0, 3, 0, 22, 25, 27, 0, 18, 1, 0, 10, 30, 11, 23, 0, 0| 4 | 8, 5, 19, 21, 0, 2, 0, 0, 0, 0, 0, 0, 18, 12, 23, 14, 7, 0, 0, 0, 27, 3, 0, 0, 15, 13, 0, 26, 29, 17| 5 | 0, 0, 14, 0, 27, 6, 1, 20, 26, 0, 4, 29, 12, 0, 19, 0, 13, 0, 0, 0, 0, 16, 5, 2, 7, 0, 0, 0, 10, 21| 6 | 24, 0, 0, 22, 0, 25, 0, 4, 1, 0, 0, 0, 21, 11, 0, 13, 10, 0, 27, 6, 0, 29, 26, 0, 3, 15, 18, 2, 30, 0| 7 | 0, 20, 8, 0, 26, 30, 3, 0, 0, 0, 0, 6, 14, 0, 0, 0, 18, 13, 23, 1, 0, 21, 0, 10, 0, 11, 19, 5, 24, 16| 8 | 30, 0, 27, 4, 0, 0, 5, 9, 0, 1, 16, 0, 0, 8, 20, 0, 0, 10, 19, 15, 6, 0, 0, 17, 13, 0, 0, 24, 12, 28| 9 | 0, 9, 10, 26, 20, 7, 15, 18, 0, 0, 0, 0, 24, 0, 17, 4, 1, 12, 3, 0, 16, 28, 0, 5, 0, 0, 0, 0, 23, 0| 10 | 0, 1, 0, 15, 0, 23, 18, 16, 6, 13, 0, 0, 7, 0, 30, 9, 27, 11, 28, 0, 0, 0, 2, 14, 0, 5, 22, 0, 0, 26| 11 | 28, 0, 0, 10, 1, 0, 0, 15, 2, 6, 22, 30, 9, 4, 21, 5, 0, 0, 0, 0, 26, 0, 0, 12, 0, 0, 24, 3, 16, 8| 12 | 0, 23, 0, 0, 0, 27, 6, 24, 0, 2, 0, 16, 0, 20, 11, 12, 0, 0, 22, 0, 0, 0, 13, 0, 17, 7, 1, 15, 26, 30| 13 | 0, 12, 24, 30, 0, 1, 10, 0, 23, 0, 25, 0, 8, 16, 0, 0, 17, 5, 6, 11, 0, 0, 15, 27, 19, 0, 0, 0, 9, 14| 14 | 4, 2, 0, 23, 24, 16, 30, 5, 0, 21, 11, 10, 0, 17, 3, 28, 0, 0, 14, 19, 0, 0, 0, 0, 0, 0, 29, 22, 15, 0| 15 | 21, 19, 0, 0, 14, 24, 0, 2, 4, 0, 18, 0, 0, 27, 22, 0, 5, 17, 0, 13, 7, 25, 0, 0, 30, 29, 0, 16, 0, 0| 16 | 22, 24, 29, 0, 3, 0, 23, 28, 19, 5, 10, 0, 0, 7, 27, 0, 0, 0, 0, 4, 8, 0, 21, 0, 2, 0, 16, 14, 18, 0| 17 | 0, 0, 20, 9, 19, 0, 8, 0, 18, 0, 24, 1, 0, 30, 0, 6, 21, 0, 10, 5, 3, 15, 7, 0, 0, 0, 14, 0, 0, 27| 18 | 17, 3, 12, 24, 0, 14, 0, 19, 0, 23, 0, 18, 15, 22, 0, 20, 0, 29, 9, 26, 5, 0, 0, 8, 21, 0, 0, 0, 0, 13| 19 | 1, 10, 0, 0, 8, 28, 29, 0, 30, 18, 5, 27, 0, 0, 2, 0, 15, 3, 0, 0, 22, 0, 0, 13, 0, 0, 25, 0, 7, 11| 20 | 0, 0, 0, 0, 2, 10, 7, 0, 11, 9, 14, 0, 0, 0, 0, 29, 19, 0, 18, 0, 23, 4, 27, 25, 12, 17, 21, 20, 0, 5| 21 | 5, 0, 15, 7, 0, 8, 25, 0, 0, 4, 0, 9, 0, 0, 24, 0, 0, 26, 0, 0, 1, 27, 19, 21, 14, 0, 0, 18, 11, 3| 22 | 3, 16, 7, 0, 0, 19, 0, 27, 0, 8, 30, 20, 0, 26, 0, 0, 22, 6, 0, 24, 10, 23, 11, 4, 0, 0, 0, 0, 14, 0| 23 | 20, 17, 2, 6, 9, 0, 12, 0, 13, 0, 0, 26, 1, 0, 0, 30, 0, 8, 0, 0, 0, 10, 0, 18, 25, 16, 0, 11, 0, 15| 24 | 0, 15, 0, 0, 0, 0, 9, 3, 5, 7, 6, 19, 10, 14, 25, 0, 0, 0, 24, 29, 0, 0, 17, 0, 16, 28, 0, 8, 0, 23| 25 | 14, 0, 13, 27, 10, 0, 0, 0, 20, 0, 3, 0, 0, 2, 12, 25, 8, 18, 0, 0, 28, 0, 24, 1, 0, 23, 15, 30, 0, 0| 26 | 2, 0, 0, 0, 0, 0, 20, 0, 27, 0, 0, 14, 17, 9, 6, 21, 0, 24, 4, 25, 18, 19, 8, 0, 22, 1, 0, 0, 0, 29| 27 | 16, 0, 9, 28, 0, 0, 24, 25, 0, 26, 0, 22, 29, 0, 0, 11, 0, 0, 8, 21, 14, 30, 12, 20, 0, 6, 13, 0, 5, 0| 28 | 9, 7, 11, 8, 25, 0, 0, 23, 0, 0, 20, 0, 27, 13, 5, 0, 24, 21, 2, 0, 30, 0, 0, 0, 28, 4, 0, 0, 1, 18| 29 | 0, 0, 18, 0, 0, 0, 0, 30, 16, 28, 29, 4, 0, 25, 0, 0, 0, 15, 1, 10, 0, 0, 22, 6, 0, 26, 5, 17, 2, 7| 30 | 0, 0, 0, 16, 15, 18, 0, 10, 29, 30, 7, 21, 0, 0, 4, 0, 14, 1, 0, 17, 0, 2, 0, 0, 11, 25, 3, 13, 20, 0| 31 | 11, 6, 1, 25, 21, 0, 13, 0, 0, 15, 27, 0, 30, 0, 0, 23, 2, 19, 0, 22, 0, 17, 20, 29, 18, 0, 4, 0, 0, 0| 32 | 0, 0, 0, 0, 4, 9, 0, 0, 14, 11, 1, 3, 23, 6, 13, 10, 30, 0, 15, 20, 12, 26, 25, 0, 0, 8, 28, 0, 0, 0|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h374-15.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 0, 2, 0, 1, 0, 10, 0, 17, 16, 11, 27, 0, 21, 0, 3, 0, 4, 0, 24, 0, 0, 19, 7, 14, 0, 30, 15, 22, 0, 12| 4 | 0, 0, 9, 15, 6, 24, 4, 16, 20, 0, 25, 7, 0, 23, 1, 28, 0, 0, 27, 0, 22, 0, 3, 0, 26, 0, 8, 0, 0, 0| 5 | 4, 0, 0, 14, 19, 28, 29, 0, 0, 0, 0, 0, 1, 5, 13, 17, 16, 0, 0, 9, 0, 10, 30, 6, 7, 2, 21, 20, 0, 0| 6 | 14, 0, 5, 22, 4, 23, 8, 0, 0, 16, 0, 26, 6, 0, 0, 2, 12, 19, 9, 0, 0, 21, 15, 0, 0, 28, 0, 0, 1, 20| 7 | 0, 20, 8, 0, 13, 9, 3, 0, 30, 12, 17, 1, 15, 26, 16, 0, 0, 27, 29, 6, 0, 0, 0, 24, 0, 0, 0, 0, 0, 5| 8 | 0, 24, 0, 5, 7, 19, 25, 12, 29, 0, 4, 0, 0, 0, 0, 21, 23, 0, 30, 26, 0, 0, 0, 28, 2, 22, 13, 0, 15, 18| 9 | 22, 1, 4, 0, 23, 0, 5, 0, 14, 0, 7, 24, 0, 18, 0, 25, 20, 12, 0, 13, 11, 0, 0, 19, 27, 0, 0, 2, 16, 0| 10 | 0, 16, 24, 13, 0, 0, 0, 0, 0, 23, 8, 0, 0, 21, 6, 0, 2, 5, 0, 22, 0, 3, 12, 0, 20, 9, 7, 11, 0, 17| 11 | 6, 13, 0, 0, 24, 5, 12, 23, 0, 7, 21, 0, 0, 0, 0, 15, 11, 30, 0, 3, 29, 0, 0, 2, 0, 0, 10, 1, 0, 4| 12 | 18, 0, 13, 0, 0, 30, 11, 0, 5, 25, 23, 20, 0, 24, 0, 3, 0, 14, 0, 0, 12, 0, 29, 26, 15, 19, 1, 4, 0, 0| 13 | 0, 0, 20, 2, 0, 16, 17, 0, 0, 0, 0, 29, 11, 1, 19, 27, 0, 0, 0, 12, 30, 4, 0, 5, 21, 0, 0, 24, 25, 15| 14 | 24, 0, 7, 16, 14, 0, 0, 2, 23, 0, 3, 30, 0, 29, 0, 0, 17, 26, 5, 0, 0, 15, 22, 0, 0, 0, 0, 8, 10, 11| 15 | 0, 26, 0, 0, 10, 27, 2, 30, 0, 13, 29, 25, 0, 12, 0, 19, 0, 7, 1, 11, 5, 18, 16, 0, 0, 0, 0, 0, 23, 28| 16 | 16, 18, 15, 6, 11, 17, 0, 0, 4, 20, 2, 0, 25, 0, 0, 0, 19, 0, 0, 0, 27, 29, 0, 0, 23, 8, 3, 30, 28, 0| 17 | 0, 3, 0, 7, 0, 0, 24, 29, 0, 0, 19, 0, 8, 6, 23, 0, 0, 4, 11, 20, 15, 16, 18, 9, 14, 0, 0, 0, 17, 0| 18 | 9, 6, 0, 11, 0, 29, 20, 7, 0, 18, 0, 0, 12, 0, 17, 0, 8, 0, 28, 1, 0, 13, 19, 10, 25, 0, 26, 0, 21, 0| 19 | 15, 0, 26, 0, 9, 0, 0, 0, 7, 29, 22, 0, 2, 28, 4, 12, 10, 3, 8, 0, 0, 0, 0, 23, 1, 27, 0, 18, 13, 0| 20 | 3, 8, 0, 20, 0, 0, 0, 24, 6, 0, 0, 0, 16, 27, 18, 14, 9, 15, 25, 28, 10, 11, 0, 0, 0, 1, 0, 0, 0, 22| 21 | 23, 0, 29, 21, 0, 0, 0, 10, 22, 1, 15, 14, 0, 0, 7, 0, 3, 0, 0, 2, 18, 0, 17, 20, 12, 0, 5, 19, 6, 0| 22 | 17, 29, 23, 0, 2, 0, 13, 1, 0, 4, 0, 6, 20, 0, 0, 0, 0, 0, 3, 5, 14, 0, 11, 16, 0, 24, 25, 10, 0, 0| 23 | 0, 0, 0, 0, 0, 8, 0, 3, 13, 28, 0, 19, 27, 0, 22, 24, 0, 21, 0, 0, 1, 9, 0, 12, 0, 6, 16, 7, 11, 26| 24 | 0, 23, 0, 17, 1, 0, 28, 19, 9, 0, 0, 4, 18, 0, 0, 5, 26, 6, 20, 10, 0, 0, 21, 3, 0, 7, 27, 0, 0, 13| 25 | 12, 0, 10, 9, 0, 0, 21, 5, 19, 0, 0, 16, 22, 14, 27, 20, 0, 0, 17, 0, 0, 28, 0, 8, 0, 13, 4, 0, 0, 25| 26 | 21, 14, 28, 0, 0, 15, 1, 4, 0, 27, 0, 8, 7, 30, 11, 0, 5, 0, 0, 0, 25, 12, 2, 0, 18, 29, 22, 0, 0, 0| 27 | 0, 0, 17, 0, 27, 0, 0, 25, 0, 0, 16, 13, 0, 9, 10, 11, 0, 22, 14, 29, 3, 0, 4, 7, 0, 20, 0, 5, 24, 2| 28 | 28, 0, 0, 0, 0, 22, 0, 0, 11, 0, 18, 23, 19, 4, 0, 0, 0, 25, 0, 24, 2, 5, 0, 17, 13, 15, 30, 6, 0, 16| 29 | 30, 4, 21, 0, 20, 0, 18, 0, 27, 9, 0, 0, 0, 25, 0, 0, 0, 0, 26, 19, 8, 0, 5, 0, 6, 17, 2, 16, 22, 3| 30 | 0, 12, 18, 30, 15, 20, 0, 28, 2, 0, 0, 0, 0, 0, 8, 0, 7, 29, 4, 0, 17, 0, 1, 0, 19, 0, 0, 9, 14, 21| 31 | 1, 0, 0, 3, 0, 13, 14, 0, 8, 10, 5, 0, 29, 0, 28, 18, 15, 24, 6, 23, 0, 17, 0, 0, 4, 26, 0, 0, 12, 0| 32 | 0, 10, 25, 0, 16, 1, 0, 11, 0, 24, 0, 22, 23, 2, 9, 26, 14, 0, 0, 0, 21, 27, 0, 0, 0, 0, 18, 28, 5, 0|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h374-16.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 26, 0, 0, 0, 13, 5, 9, 4, 0, 0, 0, 1, 3, 0, 0, 6, 17, 0, 30, 19, 29, 0, 25, 12, 20, 21, 0, 10, 22, 0| 4 | 10, 0, 22, 18, 26, 0, 0, 21, 0, 0, 20, 0, 30, 5, 7, 19, 0, 0, 0, 0, 1, 3, 23, 0, 24, 9, 0, 17, 4, 0| 5 | 6, 21, 0, 0, 19, 11, 28, 0, 0, 10, 0, 0, 0, 8, 0, 16, 2, 3, 5, 13, 14, 0, 26, 0, 22, 0, 0, 30, 12, 0| 6 | 29, 23, 0, 6, 8, 0, 0, 14, 24, 0, 0, 0, 0, 26, 0, 25, 27, 22, 20, 7, 0, 0, 4, 28, 0, 0, 11, 21, 18, 30| 7 | 0, 8, 2, 19, 16, 6, 7, 0, 0, 0, 0, 0, 0, 30, 9, 0, 23, 24, 13, 18, 26, 0, 0, 4, 5, 11, 0, 1, 27, 0| 8 | 0, 0, 30, 22, 29, 3, 17, 0, 19, 0, 24, 0, 0, 23, 4, 18, 10, 0, 0, 6, 0, 0, 21, 13, 0, 1, 28, 0, 7, 5| 9 | 0, 11, 0, 28, 0, 0, 29, 0, 0, 9, 30, 16, 7, 4, 21, 0, 0, 18, 2, 3, 0, 22, 24, 0, 17, 6, 5, 0, 0, 25| 10 | 2, 0, 4, 29, 0, 20, 14, 0, 17, 7, 0, 0, 25, 0, 18, 0, 0, 26, 10, 0, 3, 0, 0, 0, 27, 13, 21, 8, 23, 1| 11 | 15, 16, 19, 26, 0, 0, 0, 5, 0, 29, 0, 4, 22, 0, 8, 0, 0, 28, 0, 1, 23, 13, 17, 0, 0, 3, 12, 0, 0, 27| 12 | 20, 0, 0, 0, 0, 13, 0, 8, 26, 30, 0, 25, 2, 14, 0, 10, 7, 17, 0, 0, 18, 28, 11, 19, 0, 0, 0, 12, 29, 23| 13 | 0, 0, 5, 0, 0, 7, 20, 15, 6, 0, 3, 18, 24, 28, 19, 0, 8, 27, 14, 0, 10, 0, 22, 25, 0, 0, 4, 0, 17, 0| 14 | 11, 0, 9, 23, 0, 10, 0, 12, 8, 18, 1, 0, 26, 7, 0, 29, 0, 0, 4, 0, 0, 16, 0, 0, 0, 15, 25, 0, 24, 19| 15 | 0, 0, 0, 0, 1, 0, 0, 10, 25, 2, 27, 0, 0, 20, 23, 24, 4, 21, 0, 14, 0, 9, 0, 30, 8, 0, 6, 15, 13, 11| 16 | 0, 0, 11, 0, 25, 0, 23, 27, 28, 4, 14, 22, 13, 0, 0, 0, 15, 0, 0, 9, 0, 29, 3, 0, 19, 17, 2, 6, 0, 18| 17 | 21, 0, 0, 30, 28, 8, 13, 23, 0, 20, 0, 0, 0, 0, 27, 4, 25, 0, 0, 16, 0, 0, 29, 14, 15, 0, 0, 18, 3, 9| 18 | 1, 27, 29, 0, 0, 21, 3, 0, 14, 24, 0, 17, 8, 0, 0, 0, 9, 0, 25, 22, 5, 20, 10, 0, 0, 0, 7, 0, 0, 13| 19 | 24, 19, 0, 15, 18, 0, 0, 22, 0, 26, 7, 0, 12, 13, 3, 0, 0, 0, 8, 2, 27, 0, 1, 6, 25, 4, 0, 0, 0, 0| 20 | 0, 14, 0, 0, 24, 15, 16, 0, 0, 0, 10, 0, 1, 3, 0, 27, 0, 13, 0, 0, 9, 2, 0, 8, 0, 5, 29, 22, 25, 26| 21 | 19, 12, 0, 0, 0, 24, 1, 16, 22, 11, 6, 10, 28, 2, 29, 15, 0, 0, 0, 5, 25, 0, 9, 0, 0, 0, 27, 0, 14, 0| 22 | 28, 15, 0, 1, 14, 22, 2, 18, 0, 0, 23, 9, 0, 17, 0, 0, 0, 19, 12, 26, 4, 0, 0, 0, 0, 24, 30, 16, 6, 0| 23 | 9, 0, 15, 14, 2, 0, 19, 0, 0, 28, 17, 13, 20, 0, 0, 12, 18, 0, 0, 0, 7, 0, 30, 21, 3, 8, 0, 0, 0, 22| 24 | 0, 0, 18, 0, 0, 0, 0, 0, 12, 25, 26, 23, 21, 0, 20, 5, 13, 7, 0, 29, 0, 19, 27, 11, 9, 10, 17, 0, 0, 3| 25 | 25, 13, 20, 12, 0, 17, 0, 30, 0, 0, 0, 28, 0, 10, 0, 0, 5, 1, 0, 24, 0, 4, 0, 29, 14, 0, 23, 3, 0, 8| 26 | 14, 26, 3, 0, 0, 16, 0, 0, 0, 5, 0, 0, 0, 0, 28, 0, 19, 15, 21, 23, 0, 8, 20, 18, 12, 30, 10, 0, 11, 0| 27 | 0, 7, 6, 0, 3, 27, 0, 2, 18, 0, 0, 8, 0, 0, 15, 1, 0, 9, 22, 17, 20, 30, 0, 23, 16, 12, 0, 24, 0, 0| 28 | 0, 0, 0, 3, 10, 26, 27, 13, 1, 0, 19, 30, 0, 15, 5, 0, 0, 4, 23, 0, 11, 14, 0, 16, 7, 0, 0, 9, 0, 2| 29 | 0, 2, 16, 25, 12, 0, 18, 0, 5, 3, 13, 0, 10, 22, 14, 9, 0, 0, 29, 0, 0, 26, 0, 0, 28, 0, 15, 4, 0, 20| 30 | 8, 24, 7, 2, 30, 0, 0, 0, 13, 0, 12, 27, 4, 0, 6, 17, 21, 0, 26, 0, 28, 0, 0, 3, 0, 18, 0, 0, 1, 0| 31 | 0, 18, 0, 0, 4, 28, 0, 0, 16, 12, 8, 21, 0, 0, 0, 23, 6, 30, 11, 0, 0, 10, 0, 5, 0, 27, 1, 2, 15, 0| 32 | 0, 20, 13, 4, 0, 0, 12, 3, 9, 17, 0, 15, 0, 24, 2, 22, 11, 16, 7, 0, 6, 27, 0, 0, 0, 0, 0, 5, 0, 0|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h374-20.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 25, 14, 9, 0, 0, 0, 23, 20, 13, 7, 30, 0, 0, 6, 3, 4, 8, 0, 0, 29, 28, 19, 0, 22, 0, 0, 0, 24, 0, 21| 4 | 9, 0, 0, 0, 19, 0, 6, 2, 0, 26, 0, 0, 28, 23, 0, 18, 0, 0, 30, 15, 10, 25, 22, 0, 20, 17, 0, 16, 7, 14| 5 | 2, 0, 24, 30, 10, 0, 25, 4, 0, 21, 0, 0, 0, 18, 22, 1, 0, 9, 0, 28, 0, 26, 5, 17, 0, 0, 0, 6, 20, 7| 6 | 30, 25, 1, 14, 9, 12, 2, 0, 26, 8, 0, 0, 19, 17, 27, 0, 0, 18, 15, 0, 21, 13, 0, 0, 0, 0, 0, 0, 24, 4| 7 | 0, 17, 0, 19, 3, 0, 7, 0, 0, 2, 16, 4, 0, 14, 0, 25, 6, 8, 0, 0, 0, 0, 27, 0, 28, 0, 21, 26, 18, 5| 8 | 0, 30, 0, 22, 27, 0, 3, 0, 2, 10, 12, 15, 0, 0, 0, 19, 0, 13, 1, 18, 16, 7, 0, 0, 25, 0, 20, 8, 0, 0| 9 | 0, 15, 0, 7, 16, 0, 5, 0, 0, 0, 0, 28, 0, 0, 24, 0, 4, 23, 19, 21, 25, 0, 0, 0, 29, 12, 14, 10, 30, 27| 10 | 0, 22, 0, 0, 26, 29, 0, 10, 1, 28, 11, 0, 7, 0, 18, 23, 0, 6, 13, 0, 19, 0, 21, 30, 0, 3, 0, 4, 0, 0| 11 | 15, 26, 0, 0, 0, 7, 0, 29, 0, 30, 0, 0, 0, 10, 12, 24, 2, 0, 0, 4, 0, 27, 8, 11, 9, 25, 17, 28, 14, 0| 12 | 8, 12, 0, 13, 5, 19, 29, 9, 10, 6, 22, 23, 21, 0, 0, 0, 0, 20, 0, 0, 17, 0, 11, 0, 7, 4, 0, 0, 27, 0| 13 | 16, 0, 6, 3, 0, 28, 8, 24, 17, 22, 0, 27, 0, 2, 20, 0, 1, 0, 0, 13, 15, 0, 0, 12, 0, 10, 0, 19, 0, 9| 14 | 17, 21, 7, 0, 6, 15, 10, 0, 18, 0, 0, 13, 25, 0, 30, 0, 0, 5, 0, 0, 0, 29, 2, 0, 24, 22, 3, 0, 12, 0| 15 | 0, 2, 29, 0, 4, 14, 0, 16, 11, 3, 0, 5, 0, 0, 13, 0, 9, 17, 7, 0, 12, 28, 10, 0, 0, 24, 0, 0, 22, 25| 16 | 23, 20, 27, 0, 18, 9, 1, 19, 0, 29, 26, 0, 5, 25, 6, 10, 0, 0, 8, 0, 2, 0, 13, 0, 0, 0, 15, 0, 0, 11| 17 | 0, 19, 0, 0, 23, 26, 27, 15, 4, 0, 0, 10, 16, 11, 0, 6, 18, 0, 0, 2, 30, 0, 17, 1, 0, 0, 8, 0, 21, 3| 18 | 28, 0, 0, 5, 17, 20, 19, 0, 15, 0, 3, 12, 26, 0, 0, 0, 0, 2, 24, 7, 0, 9, 0, 6, 13, 0, 0, 0, 11, 29| 19 | 0, 0, 8, 0, 0, 0, 28, 0, 7, 20, 21, 0, 0, 0, 9, 16, 0, 0, 2, 0, 26, 24, 23, 13, 1, 15, 10, 14, 4, 0| 20 | 0, 9, 22, 28, 11, 27, 0, 17, 0, 0, 10, 6, 8, 20, 0, 2, 7, 16, 0, 0, 14, 5, 0, 4, 0, 0, 26, 30, 0, 0| 21 | 0, 16, 0, 27, 0, 13, 0, 0, 29, 12, 2, 0, 0, 0, 10, 20, 19, 26, 28, 3, 0, 0, 0, 15, 0, 21, 5, 0, 6, 1| 22 | 0, 0, 20, 10, 14, 0, 0, 0, 6, 17, 24, 9, 0, 8, 0, 30, 5, 0, 18, 0, 4, 0, 0, 2, 3, 0, 22, 11, 25, 23| 23 | 5, 0, 0, 12, 0, 6, 0, 28, 0, 0, 13, 0, 1, 0, 11, 27, 10, 7, 22, 30, 8, 0, 3, 21, 16, 0, 25, 0, 0, 0| 24 | 6, 0, 4, 23, 30, 17, 14, 0, 19, 0, 0, 24, 29, 13, 0, 0, 3, 28, 20, 0, 18, 8, 0, 0, 0, 11, 0, 0, 0, 22| 25 | 13, 24, 12, 0, 28, 16, 26, 0, 0, 27, 15, 0, 0, 0, 7, 17, 0, 0, 0, 1, 0, 0, 30, 14, 0, 23, 0, 29, 5, 20| 26 | 0, 0, 19, 16, 20, 0, 0, 13, 0, 0, 0, 17, 22, 5, 0, 8, 23, 0, 0, 10, 0, 12, 24, 0, 15, 14, 29, 7, 9, 0| 27 | 7, 4, 5, 0, 0, 0, 0, 25, 14, 0, 18, 20, 12, 29, 0, 0, 11, 24, 26, 0, 0, 21, 0, 0, 27, 2, 16, 22, 17, 0| 28 | 0, 0, 11, 20, 0, 0, 9, 26, 5, 16, 4, 30, 15, 0, 0, 0, 0, 1, 0, 12, 0, 17, 19, 24, 8, 18, 0, 3, 0, 0| 29 | 10, 29, 3, 4, 0, 30, 0, 0, 8, 0, 7, 18, 20, 12, 26, 0, 22, 0, 11, 24, 0, 0, 0, 5, 0, 13, 0, 21, 0, 2| 30 | 22, 6, 13, 26, 0, 0, 15, 1, 0, 0, 0, 0, 11, 16, 2, 21, 24, 0, 0, 0, 0, 23, 0, 8, 5, 28, 30, 27, 0, 19| 31 | 4, 0, 0, 0, 0, 0, 0, 5, 0, 0, 1, 21, 10, 22, 25, 0, 28, 30, 29, 9, 23, 15, 26, 27, 18, 0, 2, 0, 0, 0| 32 | 0, 0, 26, 2, 0, 4, 0, 21, 28, 0, 27, 0, 14, 15, 0, 7, 0, 12, 5, 17, 0, 18, 29, 0, 22, 8, 1, 0, 0, 10|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h375-03.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 5, 23, 0, 9, 0, 0, 0, 0, 29, 0, 0, 0, 25, 6, 7, 21, 0, 0, 16, 0, 18, 1, 0, 19, 22, 28, 13, 20, 30, 17| 4 | 10, 0, 21, 0, 3, 0, 30, 8, 22, 0, 0, 28, 2, 26, 0, 0, 0, 0, 0, 11, 25, 5, 0, 0, 18, 24, 27, 0, 19, 7| 5 | 27, 12, 2, 0, 4, 9, 3, 0, 0, 0, 7, 13, 18, 17, 0, 0, 29, 26, 5, 0, 0, 0, 22, 24, 0, 21, 15, 0, 0, 8| 6 | 19, 10, 0, 6, 0, 30, 0, 11, 15, 0, 26, 0, 0, 13, 12, 4, 0, 21, 2, 23, 0, 0, 20, 27, 24, 0, 0, 5, 1, 0| 7 | 30, 2, 0, 1, 0, 0, 24, 0, 0, 10, 13, 25, 0, 5, 0, 0, 6, 7, 15, 21, 17, 0, 0, 0, 11, 29, 0, 9, 14, 0| 8 | 0, 0, 28, 0, 0, 0, 9, 0, 8, 17, 15, 12, 1, 29, 26, 30, 0, 0, 10, 13, 22, 23, 0, 20, 0, 3, 0, 0, 18, 5| 9 | 0, 24, 19, 21, 23, 28, 29, 2, 12, 0, 0, 4, 0, 0, 1, 0, 0, 17, 0, 14, 26, 30, 3, 0, 0, 8, 0, 0, 7, 0| 10 | 24, 0, 0, 0, 0, 16, 27, 0, 25, 0, 29, 0, 11, 9, 4, 23, 17, 0, 0, 12, 5, 21, 15, 0, 10, 26, 0, 13, 0, 2| 11 | 1, 11, 0, 24, 26, 14, 6, 7, 28, 8, 23, 0, 0, 30, 0, 0, 0, 2, 3, 29, 0, 0, 0, 4, 0, 16, 0, 0, 12, 0| 12 | 9, 0, 13, 0, 11, 12, 0, 17, 27, 25, 10, 0, 0, 0, 0, 15, 14, 8, 23, 22, 3, 7, 16, 0, 2, 0, 0, 0, 0, 19| 13 | 13, 1, 0, 0, 0, 29, 18, 0, 0, 0, 0, 9, 4, 24, 0, 2, 7, 15, 26, 0, 27, 19, 0, 22, 3, 0, 21, 11, 0, 6| 14 | 0, 0, 26, 0, 1, 6, 0, 0, 0, 27, 25, 24, 22, 0, 0, 7, 28, 5, 21, 0, 2, 0, 13, 16, 19, 11, 0, 18, 0, 0| 15 | 0, 25, 0, 0, 9, 0, 16, 0, 0, 24, 6, 0, 5, 0, 0, 0, 15, 19, 0, 0, 0, 12, 27, 14, 8, 13, 2, 3, 29, 23| 16 | 21, 0, 16, 2, 18, 0, 0, 26, 0, 0, 28, 14, 0, 0, 24, 29, 22, 0, 13, 7, 23, 0, 6, 9, 4, 0, 10, 1, 0, 0| 17 | 0, 16, 25, 0, 30, 7, 0, 20, 0, 26, 0, 0, 0, 0, 5, 24, 19, 3, 4, 0, 9, 2, 0, 15, 29, 0, 23, 0, 0, 18| 18 | 18, 27, 0, 10, 21, 3, 0, 0, 0, 28, 0, 2, 0, 0, 16, 20, 11, 0, 0, 0, 0, 17, 7, 30, 1, 0, 5, 8, 0, 22| 19 | 0, 0, 0, 19, 22, 24, 25, 18, 0, 0, 8, 3, 0, 10, 13, 5, 21, 0, 0, 15, 20, 0, 4, 2, 0, 12, 30, 0, 27, 0| 20 | 0, 0, 7, 30, 0, 0, 0, 14, 6, 0, 21, 0, 0, 16, 17, 0, 26, 0, 22, 9, 29, 13, 2, 0, 15, 4, 11, 0, 5, 1| 21 | 0, 5, 27, 11, 0, 0, 26, 19, 20, 21, 0, 0, 15, 0, 25, 10, 16, 12, 0, 18, 0, 0, 8, 0, 0, 0, 14, 30, 9, 4| 22 | 6, 0, 0, 18, 27, 0, 0, 5, 21, 0, 0, 20, 14, 0, 2, 0, 0, 10, 0, 26, 12, 29, 17, 13, 9, 0, 0, 19, 24, 25| 23 | 4, 20, 29, 3, 0, 23, 0, 0, 1, 11, 0, 26, 19, 15, 0, 0, 0, 0, 9, 0, 0, 24, 0, 28, 0, 6, 8, 10, 0, 12| 24 | 20, 8, 10, 12, 6, 0, 7, 23, 0, 0, 4, 0, 27, 2, 19, 0, 0, 0, 0, 0, 30, 16, 0, 1, 13, 0, 0, 26, 25, 0| 25 | 3, 0, 0, 13, 14, 20, 28, 6, 19, 0, 1, 10, 0, 12, 30, 27, 0, 22, 8, 0, 0, 0, 0, 21, 0, 23, 25, 24, 0, 0| 26 | 0, 15, 5, 0, 19, 4, 0, 25, 10, 3, 24, 0, 0, 0, 6, 9, 0, 1, 0, 0, 13, 20, 21, 0, 0, 0, 18, 27, 28, 0| 27 | 0, 4, 18, 23, 0, 0, 0, 0, 0, 14, 0, 6, 9, 0, 15, 12, 13, 11, 0, 0, 0, 28, 25, 0, 17, 1, 7, 0, 20, 26| 28 | 22, 0, 0, 8, 0, 5, 0, 9, 0, 29, 2, 0, 13, 28, 20, 0, 12, 0, 0, 24, 14, 4, 26, 7, 0, 0, 17, 16, 23, 0| 29 | 0, 17, 15, 29, 8, 18, 23, 0, 16, 13, 0, 22, 0, 0, 0, 1, 27, 20, 24, 10, 6, 0, 0, 0, 0, 0, 19, 0, 26, 28| 30 | 15, 0, 0, 0, 13, 0, 11, 30, 7, 18, 0, 21, 29, 22, 0, 3, 0, 24, 0, 25, 0, 9, 0, 0, 0, 10, 1, 28, 6, 0| 31 | 0, 28, 1, 0, 0, 27, 17, 12, 26, 9, 5, 8, 21, 20, 22, 0, 30, 23, 6, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 14| 32 | 7, 0, 11, 0, 20, 0, 1, 3, 2, 30, 0, 17, 8, 14, 0, 16, 0, 0, 25, 27, 0, 0, 23, 26, 28, 0, 0, 0, 0, 29|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h375-05.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 0, 18, 27, 5, 0, 0, 0, 20, 0, 12, 6, 7, 2, 0, 9, 0, 1, 14, 10, 0, 26, 4, 0, 8, 0, 3, 0, 15, 19, 0| 4 | 17, 12, 16, 0, 3, 8, 11, 0, 28, 6, 13, 22, 1, 0, 0, 0, 0, 21, 0, 5, 0, 9, 29, 30, 0, 0, 0, 0, 4, 14| 5 | 0, 0, 23, 0, 0, 15, 19, 5, 0, 14, 22, 6, 9, 25, 0, 0, 13, 12, 0, 0, 11, 27, 0, 2, 0, 30, 1, 0, 0, 3| 6 | 0, 0, 13, 23, 22, 1, 0, 0, 24, 0, 0, 16, 0, 9, 20, 0, 15, 0, 0, 8, 30, 0, 3, 18, 11, 28, 25, 21, 0, 17| 7 | 0, 7, 0, 22, 18, 3, 24, 29, 0, 1, 30, 0, 0, 0, 0, 28, 0, 20, 0, 0, 0, 0, 0, 5, 17, 23, 21, 10, 12, 15| 8 | 2, 8, 4, 0, 19, 18, 0, 0, 9, 0, 28, 0, 0, 11, 7, 0, 14, 0, 15, 29, 13, 0, 10, 6, 24, 5, 0, 0, 27, 0| 9 | 0, 0, 2, 0, 0, 9, 30, 19, 0, 4, 0, 12, 23, 0, 0, 16, 28, 0, 6, 3, 5, 0, 1, 25, 0, 21, 20, 0, 22, 26| 10 | 9, 0, 24, 15, 27, 0, 0, 14, 0, 10, 20, 11, 0, 26, 0, 19, 0, 0, 22, 0, 0, 0, 0, 13, 21, 2, 18, 5, 0, 7| 11 | 10, 11, 12, 0, 0, 0, 6, 0, 0, 0, 7, 27, 4, 21, 0, 0, 2, 0, 24, 14, 19, 3, 0, 20, 0, 9, 0, 30, 26, 5| 12 | 30, 0, 18, 0, 23, 0, 9, 0, 0, 2, 0, 5, 12, 6, 28, 21, 0, 0, 17, 13, 0, 19, 15, 0, 0, 22, 0, 4, 10, 0| 13 | 0, 20, 0, 24, 0, 14, 26, 15, 3, 0, 9, 30, 0, 0, 0, 29, 0, 17, 13, 23, 0, 22, 8, 0, 0, 0, 5, 12, 25, 27| 14 | 0, 19, 29, 8, 21, 0, 0, 0, 13, 0, 5, 28, 15, 0, 2, 0, 22, 9, 14, 0, 25, 0, 0, 0, 7, 26, 16, 0, 0, 10| 15 | 25, 0, 0, 0, 28, 0, 0, 1, 0, 8, 14, 0, 13, 24, 6, 3, 19, 2, 0, 22, 27, 29, 12, 0, 0, 0, 10, 0, 7, 0| 16 | 13, 14, 0, 6, 0, 0, 5, 21, 0, 0, 0, 19, 0, 12, 0, 30, 16, 26, 0, 2, 9, 0, 23, 10, 0, 4, 7, 8, 20, 0| 17 | 0, 30, 0, 27, 0, 0, 25, 7, 12, 0, 2, 15, 8, 20, 21, 0, 0, 0, 0, 18, 23, 13, 16, 26, 4, 0, 11, 0, 0, 0| 18 | 16, 27, 6, 7, 17, 0, 10, 3, 18, 0, 0, 0, 0, 0, 30, 1, 0, 4, 9, 0, 0, 0, 0, 0, 25, 14, 26, 28, 0, 8| 19 | 3, 26, 15, 14, 1, 0, 0, 0, 8, 18, 4, 0, 0, 16, 11, 20, 27, 6, 0, 25, 10, 21, 0, 29, 0, 0, 19, 0, 0, 0| 20 | 28, 21, 0, 9, 8, 17, 15, 0, 6, 0, 26, 25, 0, 0, 24, 0, 4, 10, 29, 7, 0, 0, 0, 22, 16, 0, 0, 23, 0, 18| 21 | 27, 1, 21, 0, 29, 20, 0, 10, 0, 22, 23, 0, 26, 0, 13, 4, 25, 0, 3, 0, 7, 11, 6, 0, 12, 0, 0, 0, 24, 0| 22 | 26, 0, 0, 20, 0, 0, 7, 24, 29, 11, 0, 0, 14, 0, 17, 12, 10, 5, 19, 16, 0, 30, 21, 0, 0, 8, 0, 18, 0, 2| 23 | 0, 4, 0, 0, 30, 0, 16, 9, 27, 19, 0, 18, 3, 23, 8, 0, 0, 0, 28, 0, 24, 25, 0, 0, 13, 0, 12, 17, 0, 29| 24 | 0, 22, 20, 0, 13, 5, 0, 8, 0, 7, 0, 29, 11, 10, 0, 0, 0, 16, 12, 26, 14, 2, 0, 0, 28, 17, 0, 6, 0, 0| 25 | 1, 0, 25, 12, 0, 0, 0, 0, 17, 0, 21, 0, 20, 7, 5, 10, 3, 0, 0, 0, 15, 26, 2, 4, 19, 0, 30, 0, 11, 0| 26 | 0, 24, 8, 30, 0, 13, 4, 0, 0, 3, 0, 0, 0, 0, 22, 25, 0, 0, 0, 12, 0, 23, 5, 14, 26, 20, 0, 9, 15, 21| 27 | 11, 0, 0, 18, 24, 7, 0, 0, 2, 25, 0, 0, 0, 8, 0, 22, 21, 23, 0, 0, 0, 28, 27, 12, 29, 0, 0, 14, 5, 1| 28 | 0, 0, 28, 13, 20, 16, 3, 0, 0, 26, 8, 14, 0, 22, 18, 15, 12, 0, 5, 27, 0, 17, 0, 0, 10, 6, 0, 0, 29, 0| 29 | 21, 0, 5, 0, 0, 6, 2, 4, 23, 0, 0, 1, 0, 14, 27, 0, 0, 28, 7, 0, 12, 0, 22, 0, 20, 0, 3, 19, 17, 13| 30 | 18, 0, 0, 2, 11, 30, 0, 25, 5, 29, 0, 0, 19, 3, 0, 14, 9, 0, 23, 0, 4, 6, 0, 24, 0, 15, 0, 0, 0, 16| 31 | 23, 5, 0, 17, 0, 2, 13, 0, 16, 0, 0, 21, 18, 0, 26, 11, 29, 30, 0, 10, 20, 0, 4, 0, 6, 0, 14, 0, 28, 0| 32 | 5, 0, 0, 0, 2, 25, 0, 22, 1, 20, 3, 0, 16, 30, 0, 0, 0, 13, 0, 4, 0, 0, 7, 15, 0, 10, 8, 26, 23, 0|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h375-07.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 22, 15, 19, 0, 0, 0, 21, 28, 0, 29, 0, 20, 8, 0, 11, 0, 2, 10, 0, 9, 18, 0, 0, 0, 16, 6, 30, 27, 0, 4| 4 | 4, 0, 12, 5, 24, 18, 0, 9, 17, 20, 21, 30, 0, 0, 0, 25, 0, 0, 26, 0, 29, 0, 15, 7, 0, 13, 0, 3, 0, 16| 5 | 0, 0, 0, 15, 12, 0, 14, 0, 23, 27, 0, 6, 2, 10, 26, 0, 0, 0, 16, 22, 21, 0, 3, 18, 9, 0, 11, 30, 0, 0| 6 | 12, 9, 13, 0, 0, 6, 8, 27, 0, 0, 24, 0, 0, 0, 28, 18, 0, 4, 11, 23, 26, 0, 2, 20, 0, 5, 0, 0, 0, 21| 7 | 0, 27, 0, 14, 11, 15, 30, 0, 0, 0, 5, 2, 0, 0, 17, 10, 21, 25, 0, 0, 28, 9, 0, 1, 3, 19, 0, 12, 0, 0| 8 | 0, 0, 0, 10, 28, 21, 2, 7, 20, 0, 0, 5, 0, 1, 12, 6, 23, 0, 14, 16, 0, 29, 0, 24, 13, 0, 0, 0, 26, 0| 9 | 0, 21, 0, 8, 6, 0, 9, 0, 24, 0, 0, 25, 0, 16, 29, 27, 0, 15, 0, 0, 14, 5, 10, 0, 1, 30, 17, 23, 3, 0| 10 | 0, 0, 7, 0, 19, 0, 4, 25, 3, 2, 0, 0, 0, 0, 6, 5, 20, 0, 13, 24, 0, 18, 0, 28, 0, 21, 8, 0, 11, 1| 11 | 5, 0, 0, 27, 0, 0, 16, 0, 1, 0, 19, 17, 21, 29, 0, 24, 25, 26, 0, 8, 0, 28, 30, 14, 7, 2, 0, 0, 0, 22| 12 | 17, 0, 9, 4, 0, 22, 0, 13, 27, 19, 18, 3, 1, 0, 21, 23, 26, 0, 0, 0, 2, 0, 0, 0, 0, 16, 5, 10, 0, 14| 13 | 0, 29, 6, 28, 25, 0, 0, 0, 0, 0, 22, 15, 3, 0, 10, 0, 14, 0, 12, 0, 17, 4, 0, 0, 26, 7, 13, 8, 5, 2| 14 | 0, 4, 0, 0, 26, 0, 18, 19, 0, 14, 3, 13, 0, 20, 0, 12, 29, 17, 7, 21, 15, 8, 11, 0, 22, 0, 0, 2, 0, 0| 15 | 6, 0, 0, 9, 7, 8, 0, 0, 0, 0, 17, 12, 18, 22, 27, 0, 10, 0, 0, 15, 0, 14, 4, 0, 0, 28, 29, 11, 20, 23| 16 | 0, 0, 10, 0, 8, 11, 25, 17, 4, 13, 0, 0, 29, 2, 16, 15, 19, 20, 0, 0, 23, 0, 0, 0, 30, 0, 3, 0, 1, 0| 17 | 9, 25, 0, 0, 0, 29, 0, 22, 0, 7, 16, 0, 27, 12, 15, 0, 0, 8, 20, 0, 0, 24, 21, 11, 5, 0, 0, 0, 23, 26| 18 | 15, 10, 20, 22, 0, 1, 5, 14, 29, 0, 0, 16, 26, 17, 0, 11, 0, 0, 24, 30, 12, 0, 19, 0, 0, 0, 27, 0, 0, 0| 19 | 0, 0, 24, 0, 2, 19, 0, 0, 28, 16, 15, 23, 0, 0, 3, 22, 4, 13, 0, 0, 8, 0, 14, 21, 0, 0, 1, 29, 10, 0| 20 | 21, 19, 22, 3, 0, 30, 1, 5, 0, 26, 0, 0, 0, 0, 4, 0, 18, 12, 0, 0, 7, 0, 0, 13, 6, 27, 16, 0, 24, 8| 21 | 13, 18, 8, 26, 0, 16, 0, 0, 0, 23, 27, 0, 15, 7, 0, 0, 0, 6, 4, 0, 0, 20, 0, 0, 2, 0, 25, 28, 9, 24| 22 | 2, 0, 17, 0, 0, 0, 26, 0, 16, 22, 7, 0, 5, 9, 14, 3, 0, 0, 29, 0, 0, 0, 23, 8, 21, 0, 24, 6, 0, 30| 23 | 29, 24, 0, 18, 5, 0, 0, 0, 0, 0, 25, 0, 0, 0, 0, 0, 7, 22, 23, 27, 0, 26, 16, 0, 8, 1, 2, 17, 30, 28| 24 | 0, 8, 16, 0, 0, 7, 0, 23, 11, 15, 0, 0, 14, 0, 0, 0, 0, 0, 5, 4, 0, 1, 6, 2, 17, 9, 26, 18, 28, 0| 25 | 30, 3, 0, 17, 14, 0, 0, 0, 22, 0, 0, 1, 24, 0, 19, 8, 12, 21, 0, 25, 0, 0, 13, 23, 27, 29, 0, 0, 16, 20| 26 | 19, 0, 26, 0, 22, 0, 7, 20, 14, 0, 9, 0, 13, 11, 0, 1, 24, 0, 0, 0, 0, 23, 27, 6, 0, 8, 0, 4, 12, 15| 27 | 7, 22, 0, 0, 0, 0, 27, 15, 2, 0, 10, 9, 17, 18, 0, 16, 28, 29, 30, 6, 24, 0, 0, 0, 25, 0, 0, 5, 13, 0| 28 | 0, 2, 0, 11, 20, 13, 0, 0, 25, 10, 30, 0, 0, 19, 0, 14, 0, 23, 0, 26, 6, 17, 0, 3, 24, 0, 28, 7, 0, 27| 29 | 25, 0, 4, 6, 9, 26, 0, 10, 8, 11, 0, 0, 0, 28, 2, 0, 0, 0, 1, 3, 16, 0, 17, 19, 0, 0, 18, 0, 29, 0| 30 | 0, 12, 2, 0, 0, 4, 0, 29, 0, 1, 0, 19, 23, 6, 9, 0, 0, 24, 27, 11, 30, 10, 18, 0, 0, 14, 0, 0, 25, 13| 31 | 0, 30, 25, 0, 0, 20, 3, 0, 5, 24, 4, 8, 28, 14, 0, 29, 11, 9, 19, 0, 0, 7, 0, 22, 0, 17, 0, 0, 0, 0| 32 | 23, 0, 18, 29, 1, 0, 28, 12, 0, 5, 14, 0, 11, 0, 0, 0, 8, 16, 2, 7, 0, 6, 26, 0, 0, 22, 19, 0, 0, 10|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h375-10.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 0, 25, 6, 26, 2, 0, 0, 23, 7, 21, 0, 11, 0, 17, 0, 0, 0, 0, 3, 18, 0, 15, 0, 0, 13, 9, 22, 0, 14, 1| 4 | 19, 0, 12, 17, 26, 0, 18, 0, 10, 0, 0, 28, 3, 0, 4, 21, 0, 20, 0, 6, 2, 0, 24, 27, 14, 0, 25, 0, 9, 0| 5 | 0, 20, 9, 23, 16, 0, 0, 0, 19, 8, 10, 0, 6, 0, 18, 22, 0, 0, 4, 0, 0, 11, 29, 12, 1, 30, 0, 15, 0, 14| 6 | 0, 0, 0, 3, 12, 0, 7, 18, 0, 0, 16, 0, 2, 9, 28, 1, 0, 11, 0, 29, 23, 0, 0, 0, 27, 22, 10, 19, 8, 30| 7 | 15, 0, 0, 22, 27, 24, 0, 28, 8, 1, 0, 21, 11, 0, 0, 0, 18, 0, 7, 0, 0, 6, 23, 0, 30, 13, 9, 0, 16, 0| 8 | 5, 7, 0, 0, 0, 0, 20, 6, 0, 15, 0, 13, 0, 23, 0, 30, 8, 10, 0, 11, 0, 9, 27, 29, 0, 1, 2, 18, 0, 0| 9 | 13, 14, 0, 0, 0, 0, 28, 4, 21, 0, 0, 29, 26, 0, 1, 0, 30, 25, 2, 8, 0, 3, 0, 0, 12, 0, 5, 24, 6, 10| 10 | 8, 21, 15, 1, 0, 30, 5, 0, 0, 2, 29, 0, 0, 26, 0, 0, 0, 0, 27, 19, 17, 24, 25, 0, 0, 3, 13, 0, 22, 11| 11 | 6, 29, 0, 7, 30, 15, 14, 0, 0, 0, 24, 0, 8, 21, 17, 23, 5, 16, 20, 0, 26, 0, 0, 3, 0, 0, 0, 22, 0, 27| 12 | 0, 3, 27, 0, 17, 0, 0, 0, 16, 0, 7, 2, 0, 15, 26, 25, 14, 0, 0, 10, 22, 29, 0, 0, 0, 0, 20, 1, 13, 4| 13 | 28, 26, 20, 0, 0, 3, 30, 0, 0, 0, 17, 4, 0, 22, 14, 0, 6, 24, 0, 9, 1, 0, 18, 25, 0, 7, 0, 21, 0, 0| 14 | 30, 0, 0, 10, 1, 8, 0, 7, 13, 28, 0, 0, 0, 27, 20, 16, 0, 0, 15, 0, 0, 22, 6, 14, 24, 23, 0, 0, 25, 5| 15 | 0, 6, 29, 0, 0, 26, 23, 0, 0, 7, 3, 22, 0, 30, 27, 18, 0, 8, 16, 17, 0, 19, 10, 0, 0, 28, 0, 5, 2, 0| 16 | 24, 13, 19, 11, 0, 12, 27, 0, 28, 0, 23, 0, 0, 8, 0, 0, 17, 0, 21, 7, 0, 2, 5, 26, 22, 0, 0, 0, 0, 18| 17 | 0, 0, 0, 0, 8, 20, 10, 22, 12, 18, 0, 0, 24, 0, 0, 2, 27, 15, 29, 0, 16, 21, 3, 0, 9, 11, 0, 23, 0, 0| 18 | 22, 0, 0, 16, 0, 0, 0, 27, 14, 12, 0, 0, 5, 2, 0, 9, 26, 7, 17, 1, 0, 20, 21, 11, 0, 0, 3, 0, 24, 19| 19 | 1, 4, 30, 0, 18, 19, 0, 2, 0, 16, 0, 8, 12, 13, 23, 0, 7, 6, 0, 0, 10, 0, 17, 0, 0, 26, 28, 0, 0, 9| 20 | 18, 24, 23, 0, 0, 0, 0, 0, 0, 26, 20, 6, 0, 19, 2, 8, 0, 0, 14, 28, 13, 0, 7, 22, 5, 0, 11, 29, 27, 0| 21 | 2, 22, 26, 8, 0, 0, 0, 0, 23, 0, 28, 1, 0, 0, 30, 7, 21, 13, 18, 0, 0, 0, 0, 10, 4, 0, 24, 16, 0, 29| 22 | 29, 0, 0, 0, 0, 14, 4, 9, 0, 0, 13, 0, 23, 3, 22, 20, 0, 0, 0, 0, 15, 18, 2, 24, 10, 16, 12, 30, 0, 0| 23 | 0, 0, 22, 24, 15, 1, 25, 0, 0, 0, 30, 0, 0, 20, 0, 29, 0, 18, 8, 12, 0, 27, 0, 21, 0, 17, 0, 4, 19, 26| 24 | 0, 0, 3, 0, 6, 2, 0, 12, 29, 9, 22, 7, 30, 1, 21, 0, 0, 26, 0, 15, 14, 0, 8, 17, 0, 0, 0, 0, 5, 25| 25 | 10, 30, 0, 12, 25, 0, 21, 0, 4, 29, 11, 16, 19, 0, 0, 0, 0, 1, 0, 0, 8, 23, 0, 9, 6, 0, 7, 20, 0, 0| 26 | 0, 0, 5, 25, 20, 0, 0, 17, 0, 4, 0, 15, 10, 0, 29, 0, 24, 9, 0, 22, 0, 0, 13, 0, 8, 18, 21, 0, 11, 3| 27 | 20, 0, 0, 29, 10, 7, 0, 0, 15, 11, 0, 0, 17, 0, 3, 27, 1, 0, 6, 25, 28, 4, 0, 0, 16, 19, 18, 0, 0, 0| 28 | 25, 12, 0, 2, 14, 0, 6, 29, 0, 13, 9, 3, 22, 0, 0, 24, 0, 0, 0, 0, 5, 0, 0, 4, 18, 0, 0, 27, 20, 21| 29 | 0, 28, 25, 0, 7, 5, 8, 3, 24, 23, 18, 0, 0, 0, 0, 15, 22, 0, 0, 16, 9, 0, 11, 0, 20, 0, 6, 0, 1, 13| 30 | 0, 1, 2, 19, 0, 4, 24, 10, 20, 30, 0, 0, 15, 28, 0, 5, 9, 23, 13, 21, 0, 26, 0, 0, 0, 0, 0, 14, 29, 0| 31 | 12, 0, 28, 14, 0, 29, 0, 24, 27, 0, 26, 5, 18, 0, 6, 0, 16, 2, 11, 0, 25, 0, 30, 19, 0, 10, 23, 0, 0, 0| 32 | 0, 0, 0, 0, 9, 21, 26, 20, 6, 0, 0, 18, 14, 0, 19, 0, 3, 4, 0, 0, 11, 16, 0, 5, 29, 27, 0, 2, 0, 24|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h375-12.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 23, 3, 1, 17, 0, 19, 0, 13, 11, 12, 0, 8, 16, 0, 28, 0, 7, 0, 5, 0, 0, 25, 30, 0, 0, 26, 21, 0, 0, 24| 4 | 0, 16, 3, 0, 26, 0, 10, 2, 28, 1, 0, 0, 12, 0, 29, 0, 27, 4, 0, 9, 0, 0, 15, 0, 0, 20, 6, 11, 7, 0| 5 | 21, 8, 0, 0, 4, 15, 14, 12, 0, 0, 16, 17, 9, 19, 10, 0, 0, 7, 0, 0, 18, 0, 0, 11, 0, 27, 20, 26, 6, 0| 6 | 0, 7, 0, 0, 0, 11, 19, 0, 0, 0, 21, 6, 8, 17, 0, 0, 30, 28, 15, 0, 0, 9, 18, 5, 20, 1, 0, 24, 23, 0| 7 | 22, 19, 23, 6, 8, 28, 0, 3, 10, 15, 0, 0, 2, 30, 26, 0, 11, 0, 0, 0, 27, 24, 0, 0, 0, 0, 0, 0, 4, 18| 8 | 13, 0, 15, 20, 0, 2, 0, 9, 0, 0, 22, 0, 0, 0, 19, 11, 8, 24, 21, 14, 0, 0, 17, 26, 23, 0, 0, 12, 27, 0| 9 | 0, 17, 16, 0, 0, 0, 0, 19, 13, 5, 3, 22, 7, 24, 0, 0, 0, 26, 25, 8, 0, 28, 0, 10, 0, 30, 23, 29, 0, 0| 10 | 0, 24, 0, 0, 16, 0, 6, 22, 17, 0, 11, 3, 0, 0, 7, 0, 28, 2, 4, 0, 30, 27, 25, 0, 14, 0, 0, 9, 21, 19| 11 | 0, 6, 11, 0, 12, 9, 1, 16, 0, 0, 0, 0, 0, 0, 0, 26, 29, 20, 0, 4, 24, 17, 0, 30, 22, 0, 3, 8, 14, 21| 12 | 26, 0, 20, 0, 0, 0, 0, 0, 21, 22, 10, 27, 17, 0, 2, 23, 3, 5, 0, 25, 0, 29, 0, 8, 9, 18, 30, 19, 0, 0| 13 | 3, 0, 18, 1, 13, 0, 26, 0, 24, 23, 0, 0, 28, 10, 0, 20, 21, 0, 11, 17, 0, 2, 0, 0, 4, 12, 29, 0, 0, 8| 14 | 0, 12, 0, 25, 3, 24, 11, 0, 0, 17, 0, 23, 0, 6, 5, 19, 0, 9, 1, 28, 0, 0, 7, 18, 0, 8, 0, 0, 0, 10| 15 | 29, 0, 0, 30, 14, 0, 23, 0, 3, 9, 2, 25, 0, 16, 0, 27, 1, 0, 19, 0, 13, 18, 4, 0, 21, 0, 0, 10, 24, 0| 16 | 0, 15, 28, 7, 0, 0, 16, 20, 5, 6, 0, 0, 11, 0, 23, 0, 17, 0, 8, 0, 22, 0, 0, 3, 0, 4, 18, 14, 0, 13| 17 | 8, 23, 0, 14, 7, 13, 0, 0, 0, 2, 26, 0, 0, 4, 0, 25, 24, 17, 0, 0, 12, 6, 1, 0, 19, 0, 27, 0, 0, 11| 18 | 4, 0, 0, 9, 30, 10, 18, 0, 23, 21, 8, 20, 0, 0, 0, 0, 0, 11, 27, 13, 6, 0, 0, 17, 16, 0, 5, 0, 0, 29| 19 | 0, 0, 4, 10, 0, 17, 5, 0, 0, 0, 0, 0, 0, 8, 30, 21, 12, 18, 14, 0, 2, 13, 6, 22, 0, 29, 1, 27, 0, 15| 20 | 27, 1, 0, 0, 0, 12, 3, 17, 18, 29, 13, 21, 0, 0, 22, 5, 0, 0, 28, 0, 7, 0, 0, 23, 24, 16, 0, 0, 25, 4| 21 | 6, 0, 5, 0, 20, 0, 8, 26, 4, 0, 17, 1, 13, 22, 16, 24, 18, 0, 0, 30, 0, 0, 12, 21, 25, 0, 0, 0, 0, 0| 22 | 0, 4, 0, 29, 0, 14, 0, 24, 26, 0, 0, 5, 0, 9, 20, 0, 0, 10, 6, 0, 21, 30, 8, 12, 15, 3, 11, 0, 0, 25| 23 | 11, 0, 21, 22, 0, 27, 20, 0, 9, 0, 0, 19, 23, 15, 18, 10, 16, 0, 0, 0, 0, 0, 3, 0, 26, 0, 2, 30, 0, 17| 24 | 17, 0, 8, 27, 0, 0, 0, 1, 0, 0, 0, 4, 10, 5, 0, 18, 0, 12, 0, 22, 0, 14, 0, 15, 6, 9, 0, 23, 3, 16| 25 | 0, 20, 26, 11, 22, 0, 21, 25, 0, 0, 24, 28, 0, 29, 0, 8, 14, 23, 30, 0, 4, 0, 5, 0, 2, 0, 0, 0, 9, 7| 26 | 0, 26, 27, 0, 5, 0, 0, 30, 22, 24, 28, 0, 21, 0, 0, 12, 0, 0, 23, 7, 19, 0, 10, 25, 0, 2, 14, 16, 8, 0| 27 | 14, 11, 30, 0, 0, 8, 0, 29, 25, 7, 5, 0, 1, 0, 0, 28, 6, 0, 0, 26, 0, 3, 16, 9, 0, 15, 0, 13, 20, 0| 28 | 0, 0, 2, 12, 27, 0, 17, 28, 0, 16, 18, 7, 15, 0, 1, 4, 0, 0, 0, 11, 25, 0, 29, 14, 3, 0, 0, 0, 5, 20| 29 | 12, 13, 0, 15, 28, 7, 4, 8, 0, 0, 9, 2, 26, 20, 0, 0, 0, 0, 3, 5, 0, 16, 14, 0, 1, 23, 0, 0, 0, 0| 30 | 1, 0, 0, 18, 11, 23, 24, 0, 6, 4, 0, 14, 3, 13, 25, 0, 0, 27, 0, 20, 8, 5, 0, 0, 0, 0, 9, 17, 15, 0| 31 | 0, 0, 7, 0, 2, 21, 0, 0, 0, 30, 19, 0, 25, 0, 24, 9, 0, 0, 0, 27, 14, 0, 0, 16, 13, 5, 8, 6, 29, 26| 32 | 30, 5, 0, 21, 0, 22, 0, 0, 0, 26, 0, 0, 0, 11, 3, 15, 20, 19, 2, 29, 28, 8, 0, 0, 0, 0, 10, 0, 13, 14|]; 33 | -------------------------------------------------------------------------------- /CP/restart/qwh-o30-h375-14.dzn: -------------------------------------------------------------------------------- 1 | N=30; 2 | start=[| 3 | 8, 30, 0, 0, 0, 11, 0, 0, 19, 0, 28, 13, 0, 9, 27, 22, 20, 0, 26, 7, 0, 0, 12, 25, 10, 4, 1, 0, 0, 3| 4 | 0, 21, 2, 15, 25, 8, 18, 24, 22, 11, 0, 16, 0, 0, 12, 0, 29, 0, 0, 26, 0, 6, 0, 7, 0, 0, 9, 0, 19, 0| 5 | 9, 0, 23, 26, 0, 0, 0, 3, 0, 6, 30, 0, 22, 0, 13, 24, 2, 16, 19, 0, 4, 28, 0, 0, 18, 0, 12, 5, 11, 0| 6 | 26, 19, 8, 27, 22, 29, 0, 0, 0, 1, 0, 28, 13, 6, 0, 25, 0, 21, 7, 0, 0, 0, 11, 0, 12, 0, 0, 18, 0, 9| 7 | 0, 28, 15, 20, 12, 5, 0, 21, 0, 0, 0, 0, 29, 26, 6, 0, 11, 1, 25, 4, 0, 2, 24, 30, 0, 0, 13, 0, 0, 0| 8 | 0, 0, 0, 2, 19, 0, 11, 15, 16, 0, 3, 0, 5, 4, 0, 8, 0, 23, 28, 25, 0, 0, 0, 24, 1, 6, 7, 0, 22, 0| 9 | 7, 1, 0, 0, 15, 14, 0, 0, 26, 29, 10, 0, 0, 12, 22, 0, 0, 11, 0, 0, 2, 23, 13, 0, 16, 17, 5, 0, 20, 8| 10 | 0, 0, 6, 13, 18, 26, 12, 28, 15, 10, 0, 0, 0, 0, 0, 14, 19, 8, 0, 0, 0, 7, 5, 29, 17, 16, 0, 3, 24, 0| 11 | 29, 20, 27, 24, 0, 0, 25, 7, 11, 23, 8, 0, 21, 10, 0, 0, 0, 19, 0, 0, 12, 9, 1, 15, 0, 18, 0, 16, 0, 0| 12 | 5, 11, 1, 8, 4, 0, 0, 14, 20, 0, 0, 24, 3, 2, 0, 0, 0, 7, 15, 6, 19, 0, 17, 0, 0, 28, 16, 23, 0, 0| 13 | 0, 8, 0, 9, 0, 28, 0, 22, 0, 3, 23, 0, 0, 0, 14, 0, 0, 0, 27, 13, 7, 4, 0, 17, 25, 2, 0, 11, 6, 26| 14 | 0, 26, 0, 0, 10, 2, 0, 0, 7, 0, 21, 0, 23, 13, 15, 9, 27, 29, 0, 8, 0, 14, 6, 18, 0, 24, 0, 0, 0, 4| 15 | 30, 0, 12, 4, 0, 23, 22, 8, 0, 0, 2, 1, 0, 0, 0, 27, 13, 0, 0, 20, 29, 3, 0, 0, 0, 5, 28, 0, 10, 14| 16 | 0, 6, 0, 0, 17, 0, 19, 0, 27, 24, 18, 15, 30, 0, 8, 13, 22, 26, 0, 0, 0, 21, 20, 0, 14, 10, 0, 0, 1, 7| 17 | 13, 0, 22, 0, 0, 25, 0, 1, 0, 0, 0, 3, 28, 0, 17, 30, 0, 2, 24, 16, 0, 15, 14, 0, 21, 0, 8, 26, 0, 20| 18 | 20, 15, 0, 17, 14, 0, 13, 19, 0, 4, 0, 0, 0, 28, 0, 21, 8, 9, 10, 27, 25, 1, 23, 0, 0, 0, 6, 0, 0, 16| 19 | 12, 0, 13, 0, 0, 17, 0, 5, 1, 18, 25, 10, 9, 0, 0, 0, 6, 0, 0, 11, 16, 0, 0, 3, 4, 0, 30, 15, 28, 0| 20 | 19, 27, 10, 30, 2, 0, 20, 12, 0, 0, 0, 0, 0, 0, 7, 5, 4, 15, 0, 24, 0, 0, 0, 0, 0, 13, 14, 25, 21, 17| 21 | 0, 0, 0, 0, 0, 30, 15, 0, 13, 0, 5, 8, 18, 23, 1, 28, 9, 14, 21, 29, 20, 0, 0, 6, 0, 11, 2, 0, 0, 0| 22 | 27, 10, 0, 18, 0, 13, 17, 0, 0, 19, 0, 11, 7, 21, 0, 1, 0, 25, 12, 28, 3, 16, 29, 0, 0, 0, 15, 0, 0, 30| 23 | 0, 0, 19, 0, 13, 3, 26, 20, 0, 15, 6, 25, 4, 16, 0, 0, 21, 10, 0, 9, 22, 0, 0, 0, 0, 0, 0, 17, 18, 1| 24 | 28, 0, 0, 0, 24, 21, 10, 9, 0, 27, 0, 0, 14, 7, 11, 0, 3, 22, 29, 0, 6, 0, 0, 0, 30, 1, 25, 0, 23, 18| 25 | 1, 17, 30, 0, 0, 0, 29, 0, 0, 12, 0, 7, 10, 3, 21, 2, 0, 27, 5, 0, 13, 0, 4, 0, 0, 22, 0, 14, 9, 0| 26 | 14, 0, 7, 0, 0, 0, 0, 18, 24, 0, 22, 27, 19, 0, 25, 0, 26, 0, 1, 0, 9, 17, 30, 4, 3, 0, 0, 29, 8, 6| 27 | 0, 24, 14, 29, 1, 6, 4, 0, 0, 0, 0, 12, 0, 8, 19, 0, 0, 0, 0, 15, 18, 0, 0, 20, 13, 21, 26, 10, 7, 25| 28 | 6, 0, 28, 0, 21, 0, 0, 26, 4, 5, 27, 20, 0, 19, 0, 0, 0, 0, 3, 14, 0, 30, 0, 9, 7, 0, 11, 8, 29, 0| 29 | 0, 0, 16, 6, 0, 24, 7, 0, 10, 17, 9, 18, 0, 0, 4, 12, 0, 0, 23, 0, 5, 19, 25, 28, 20, 0, 27, 21, 0, 0| 30 | 0, 18, 3, 1, 20, 16, 5, 4, 14, 25, 0, 2, 0, 22, 0, 6, 23, 0, 0, 0, 0, 0, 7, 10, 11, 0, 0, 24, 0, 21| 31 | 25, 0, 0, 23, 16, 0, 9, 0, 3, 0, 14, 29, 0, 0, 20, 11, 0, 0, 8, 18, 15, 13, 0, 19, 5, 7, 0, 0, 0, 2| 32 | 3, 22, 0, 19, 0, 0, 0, 0, 29, 16, 26, 0, 17, 0, 0, 23, 12, 0, 13, 0, 10, 27, 8, 14, 0, 15, 0, 2, 4, 24|]; 33 | -------------------------------------------------------------------------------- /CP/search/herbs.mzn: -------------------------------------------------------------------------------- 1 | int: r = 3; 2 | int: c = 2; 3 | 4 | %int: r = 10; 5 | %int: c = 10; 6 | 7 | enum ELEMENTS = {Metal, Wood, Water, Fire, Earth}; 8 | 9 | array[1..r,1..c] of var ELEMENTS: herb; 10 | 11 | array[int,1..2] of ELEMENTS: compat = 12 | [| Water, Wood | Water, Fire | Wood, Fire | Wood, Earth | Earth, Metal | 13 | Fire, Earth | Fire, Metal | Metal, Water| Metal, Wood | Earth, Water |]; 14 | 15 | 16 | include "table.mzn"; 17 | constraint forall(i in 1..r,j in 1..c-1)(table([herb[i,j],herb[i,j+1]], compat)); 18 | 19 | include "global_cardinality_low_up.mzn"; 20 | constraint forall(j in 1..c)( 21 | global_cardinality_low_up([herb[i,j]|i in 1..r], [Metal,Earth], [1,1], [2,2])) :: domain; 22 | 23 | constraint herb[1,1] != Metal; 24 | 25 | % solve satisfy; 26 | 27 | solve::int_search(array1d(herb), input_order, indomain_min, complete) satisfy; 28 | % solve::int_search(array1d(herb), smallest, indomain_min, complete) satisfy; 29 | % solve::int_search(array1d(herb), first_fail, indomain_min, complete) satisfy; 30 | % solve::int_search(array1d(herb), largest, indomain_min, complete) satisfy; 31 | % solve::int_search(array1d(herb), largest, indomain_max, complete) satisfy; 32 | 33 | % solve::int_search(array1d(herb), input_order, indomain_min, complete) satisfy; 34 | % solve::int_search(array1d(herb), input_order, indomain_max, complete) satisfy; 35 | % solve::int_search(array1d(herb), input_order, indomain_median, complete) satisfy; 36 | % solve::int_search(array1d(herb), input_order, indomain_random, complete) satisfy; 37 | 38 | 39 | output[if j < c then 40 | show(herb[i,j])++"\t" 41 | else 42 | show(herb[i,j])++"\n" endif 43 | | i in 1..r, j in 1..c]; -------------------------------------------------------------------------------- /CP/search/herbs1.mzn: -------------------------------------------------------------------------------- 1 | int: n = 20; 2 | 3 | enum ELEMENTS = {Gold, Wood, Water, Fire, Earth}; 4 | enum SEASONS = {Spring, Summer, Autumn, Winter}; 5 | 6 | var ELEMENTS: x; 7 | var SEASONS: y; 8 | 9 | array[1..n div 2] of var ELEMENTS: oHerbs; 10 | array[1..n div 2] of var SEASONS: eHerbs; 11 | 12 | array[int,1..2] of ELEMENTS: eCompat = 13 | [| Water, Wood | Water, Fire | Wood, Fire | Wood, Earth | Earth, Gold | 14 | Fire, Earth | Fire, Gold | Gold, Water| Gold, Wood | Earth, Water |]; 15 | 16 | array[int,1..2] of int: esCompat = 17 | [| Wood, Summer | Wood, Autumn | Wood, Winter | 18 | Fire, Spring | Fire, Autumn | Fire, Winter | 19 | Gold, Spring | Gold, Summer | Gold, Winter | 20 | Water, Spring| Water, Summer| Water, Autumn| 21 | Earth, Spring| Earth, Summer| Earth, Autumn| Earth, Winter|]; 22 | 23 | include "table.mzn"; 24 | constraint forall(i in 1..(n div 2 - 1))(table([oHerbs[i],oHerbs[i+1]], eCompat)); 25 | constraint forall(i in 1..(n div 2 - 1))( 26 | % trace("table([oHerbs[\(i)],eHerbs[\(i)]], esCompat) and table([eHerbs[\(i)],oHerbs[\(i+1)]], esCompat)\n", 27 | table([oHerbs[i],eHerbs[i]], esCompat) /\ table([oHerbs[i+1],eHerbs[i]], esCompat) ); 28 | 29 | 30 | constraint if n mod 2 = 0 then table([oHerbs[n div 2],eHerbs[n div 2]], esCompat) else true endif; 31 | 32 | solve satisfy; 33 | 34 | output[if i mod 2 = 1 then show(oHerbs[i div 2 + 1]) else show(eHerbs[i div 2]) endif++" " | i in 1..n]; 35 | -------------------------------------------------------------------------------- /CP/search/herbs2.mzn: -------------------------------------------------------------------------------- 1 | int: n = 20; 2 | 3 | enum ELEMENTS = {Gold, Wood, Water, Fire, Earth}; 4 | 5 | array[1..n] of var ELEMENTS: herb; 6 | 7 | array[int,1..2] of ELEMENTS: eCompat = 8 | [| Water, Wood | Water, Fire | Wood, Fire | Wood, Earth | Earth, Gold | 9 | Fire, Earth | Fire, Gold | Gold, Water| Gold, Wood | Earth, Water |]; 10 | 11 | 12 | include "table.mzn"; 13 | constraint forall(i in 1..(n - 1))(table([herb[i],herb[i+1]], eCompat)); 14 | 15 | constraint forall(i in 1..n-3)(herb[i] != herb[i+3]); 16 | 17 | include "globals.mzn"; 18 | int: k = 4; 19 | constraint forall(i in 1..n-k+1)( 20 | global_cardinality_low_up([herb[i+j-1]|j in 1..k],[Gold,Earth],[1,1],[2,2]) 21 | ); 22 | constraint herb[1] != Gold; 23 | 24 | % constraint forall(i in 1..n-4)(herb[i] != herb[i+4]); 25 | % constraint global_cardinality_low_up(herb,[Gold],[0],[n div 4]); 26 | 27 | % solve::int_search(herb, input_order, indomain_min, complete) satisfy; 28 | solve::int_search(herb, first_fail, indomain_min, complete) satisfy; 29 | % solve::int_search(herb, largest, indomain_min, complete) satisfy; 30 | 31 | % solve satisfy; 32 | 33 | output[show(herb)]; -------------------------------------------------------------------------------- /CP/search/revherbs.mzn: -------------------------------------------------------------------------------- 1 | int: r = 3; 2 | int: c = 2; 3 | 4 | % int: r = 10; 5 | % int: c = 10; 6 | 7 | enum ELEMENTS = {Metal, Wood, Water, Fire, Earth}; 8 | 9 | array[1..r,1..c] of var ELEMENTS: herb; 10 | array[1..r*c] of var ELEMENTS: rherb; 11 | 12 | constraint rherb = [array1d(herb)[r*c-i+1] | i in 1..r*c]; 13 | 14 | array[int,1..2] of ELEMENTS: compat = 15 | [| Water, Wood | Water, Fire | Wood, Fire | Wood, Earth | Earth, Metal | 16 | Fire, Earth | Fire, Metal | Metal, Water| Metal, Wood | Earth, Water |]; 17 | 18 | 19 | include "table.mzn"; 20 | constraint forall(i in 1..r,j in 1..c-1)(table([herb[i,j],herb[i,j+1]], compat)); 21 | 22 | include "global_cardinality_low_up.mzn"; 23 | constraint forall(j in 1..c)( 24 | global_cardinality_low_up([herb[i,j]|i in 1..r], [Metal,Earth], [1,1], [2,2])); 25 | 26 | constraint herb[1,1] != Metal; 27 | 28 | % solve satisfy; 29 | 30 | solve::int_search(rherb, input_order, indomain_min, complete) satisfy; 31 | % solve::int_search(array1d(herb), smallest, indomain_min, complete) satisfy; 32 | % solve::int_search(array1d(herb), first_fail, indomain_min, complete) satisfy; 33 | % solve::int_search(array1d(herb), largest, indomain_min, complete) satisfy; 34 | % solve::int_search(array1d(herb), largest, indomain_max, complete) satisfy; 35 | 36 | % solve::int_search(array1d(herb), input_order, indomain_min, complete) satisfy; 37 | % solve::int_search(array1d(herb), input_order, indomain_max, complete) satisfy; 38 | % solve::int_search(array1d(herb), input_order, indomain_median, complete) satisfy; 39 | % solve::int_search(array1d(herb), input_order, indomain_random, complete) satisfy; 40 | 41 | 42 | output[if j < c then 43 | show(herb[i,j])++" " 44 | else 45 | show(herb[i,j])++"\n" endif 46 | | i in 1..r, j in 1..c]; -------------------------------------------------------------------------------- /LS/escaping_local_minima/intestine.mzn: -------------------------------------------------------------------------------- 1 | var -4 .. 4: x; 2 | var -4 .. 4: y; 3 | 4 | constraint abs(x) != abs(y); 5 | 6 | % t[x,y] = 5*sin(x)*cos(y) 7 | array[-4..4,-4..4] of float: t = 8 | array2d(-4..4,-4..4, 9 | [-2.4733956165584545,-3.746143958816714,-1.5747048215668895,2.0445106665081783,3.7840124765396412,2.0445106665081783,-1.5747048215668895,-3.746143958816714,-2.4733956165584545,0.46121096522276855,0.6985387454973147,0.29363322463810493,-0.38123732879438366,-0.7056000402993361,-0.38123732879438366,0.29363322463810493,0.6985387454973147,0.46121096522276855,2.971782312561519,4.500988148677587,1.8920062382698208,-2.4564774821694098,-4.546487134128409,-2.4564774821694098,1.8920062382698208,4.500988148677587,2.971782312561519,2.7501107068075146,4.165249805334025,1.7508774418700734,-2.2732435670642044,-4.207354924039483,-2.2732435670642044,1.7508774418700734,4.165249805334025,2.7501107068075146,-0.0,-0.0,-0.0,0.0,0.0,0.0,-0.0,-0.0,-0.0,-2.7501107068075146,-4.165249805334025,-1.7508774418700734,2.2732435670642044,4.207354924039483,2.2732435670642044,-1.7508774418700734,-4.165249805334025,-2.7501107068075146,-2.971782312561519,-4.500988148677587,-1.8920062382698208,2.4564774821694098,4.546487134128409,2.4564774821694098,-1.8920062382698208,-4.500988148677587,-2.971782312561519,-0.46121096522276855,-0.6985387454973147,-0.29363322463810493,0.38123732879438366,0.7056000402993361,0.38123732879438366,-0.29363322463810493,-0.6985387454973147,-0.46121096522276855,2.4733956165584545,3.746143958816714,1.5747048215668895,-2.0445106665081783,-3.7840124765396412,-2.0445106665081783,1.5747048215668895,3.746143958816714,2.4733956165584545]); 10 | 11 | var -100.0 .. 100.0: obj; 12 | constraint obj = t[x,y] + abs(x) + abs(y); 13 | solve minimize obj; 14 | 15 | -------------------------------------------------------------------------------- /LS/escaping_local_minima/most_painful.mzn: -------------------------------------------------------------------------------- 1 | var -2 .. 6: x; 2 | var -4 .. 4: y; 3 | 4 | constraint abs(x) != abs(y); 5 | 6 | % t1[x] = cos(x); 7 | array[-8..24] of float: t1 = 8 | array1d(-8..24, 9 | [-0.14550003380861354,0.7539022543433046,0.9601702866503661,0.2836621854632263,-0.6536436208636119,-0.9899924966004454,-0.4161468365471424,0.5403023058681398,1.0,0.5403023058681398,-0.4161468365471424,-0.9899924966004454,-0.6536436208636119,0.2836621854632263,0.9601702866503661,0.7539022543433046,-0.14550003380861354,-0.9111302618846769,-0.8390715290764524,4.425697988050786e-3,0.8438539587324921,0.9074467814501962,0.1367372182078336,-0.7596879128588212,-0.9576594803233847,-0.27516333805159693,0.6603167082440802,0.9887046181866692,0.40808206181339196,-0.5477292602242685,-0.9999608263946371,-0.5328330203333975,0.4241790073369969]); 10 | % t2[x,y] = sin(x)*cos(y) 11 | array[-2..6,-4..4] of float: t2 = 12 | array2d(-2..6,-4..4, 13 | [0.5943564625123038,0.9001976297355174,0.37840124765396416,-0.49129549643388193,-0.9092974268256817,-0.49129549643388193,0.37840124765396416,0.9001976297355174,0.5943564625123038,0.5500221413615028,0.833049961066805,0.35017548837401463,-0.4546487134128409,-0.8414709848078965,-0.4546487134128409,0.35017548837401463,0.833049961066805,0.5500221413615028,-0.0,-0.0,-0.0,0.0,0.0,0.0,-0.0,-0.0,-0.0,-0.5500221413615028,-0.833049961066805,-0.35017548837401463,0.4546487134128409,0.8414709848078965,0.4546487134128409,-0.35017548837401463,-0.833049961066805,-0.5500221413615028,-0.5943564625123038,-0.9001976297355174,-0.37840124765396416,0.49129549643388193,0.9092974268256817,0.49129549643388193,-0.37840124765396416,-0.9001976297355174,-0.5943564625123038,-9.224219304455371e-2,-0.13970774909946293,-5.872664492762098e-2,7.624746575887673e-2,0.1411200080598672,7.624746575887673e-2,-5.872664492762098e-2,-0.13970774909946293,-9.224219304455371e-2,0.4946791233116909,0.7492287917633427,0.3149409643133779,-0.4089021333016356,-0.7568024953079282,-0.4089021333016356,0.3149409643133779,0.7492287917633427,0.4946791233116909,0.6267947350248265,0.9493278367245317,0.39905330338932815,-0.5181089967534271,-0.9589242746631385,-0.5181089967534271,0.39905330338932815,0.9493278367245317,0.6267947350248265,0.18263815796815594,0.2766192466508119,0.11627787565772676,-0.1509688379721747,-0.27941549819892586,-0.1509688379721747,0.11627787565772676,0.2766192466508119,0.18263815796815594]); 14 | 15 | var -100.0 .. 100.0: obj; 16 | constraint obj = -10 * (t1[x*y] - x * t2[x,y]); 17 | 18 | solve minimize obj; 19 | 20 | -------------------------------------------------------------------------------- /LS/escaping_local_minima/stomach.mzn: -------------------------------------------------------------------------------- 1 | var -4 .. 4: x; 2 | var -4 .. 4: y; 3 | 4 | constraint abs(x) != abs(y); 5 | 6 | % t1 = 10*cos^7(x) 7 | array[-4..4] of float: t1 = 8 | array1d(-4..4,[-0.5097851610099855,-9.320158989192159,-2.1613553878067307e-2,0.1344180983377226,10.0,0.1344180983377226,-2.1613553878067307e-2,-9.320158989192159,-0.5097851610099855]); 9 | % t2 = 20*sin^5(x) 10 | array[-4..4] of float: t2 = 11 | array1d(-4..4,[4.96526889043685,-1.1193681837577975e-3,-12.4325383104526,-8.437731916395613,0.0,8.437731916395613,12.4325383104526,1.1193681837577975e-3,-4.96526889043685]); 12 | % t3 = 20*sin^3(x) 13 | array[-4..4] of float: t3 = 14 | array1d(-4..4,[8.669172839616747,-5.620769468922548e-2,-15.036538893379856,-11.916464731819111,0.0,11.916464731819111,15.036538893379856,5.620769468922548e-2,-8.669172839616747]); 15 | % t4 = 10*cos(x) 16 | array[-4..4] of float: t4 = 17 | array1d(-4..4,[-6.536436208636119,-9.899924966004454,-4.161468365471424,5.403023058681398,10.0,5.403023058681398,-4.161468365471424,-9.899924966004454,-6.536436208636119]); 18 | 19 | var -100.0 .. 100.0: obj; 20 | constraint obj = t1[x] + t2[y] + t3[x] + t4[y]; 21 | solve minimize t1[x] + t2[y] + t3[x] + t4[y]; 22 | 23 | -------------------------------------------------------------------------------- /LS/firefighting/fire.mzn: -------------------------------------------------------------------------------- 1 | int: w; % number of Wukongs 2 | 3 | int: n; % number of spot fires 4 | set of int: FIRE = 1..n; 5 | array[FIRE] of int: d; % duration 6 | array[FIRE] of int: reqW; % #Wukongs required 7 | array[FIRE] of int: best; % best time 8 | 9 | int: m; % number of precedence pairs 10 | set of int: PREC = 1..m; 11 | array[PREC] of FIRE: pre; % put out this 12 | array[PREC] of FIRE: post; % before this 13 | 14 | int: maxt = sum(f in FIRE)(d[f]); % max time 15 | 16 | array[FIRE] of var 0..maxt: s; % start time 17 | array[FIRE] of var 0..maxt: 18 | e = [s[f] + d[f] | f in FIRE]; % end time 19 | 20 | constraint forall(i in PREC) 21 | (e[pre[i]] <= s[post[i]]); 22 | 23 | include "cumulative.mzn"; 24 | constraint cumulative(s, d, reqW, w); 25 | 26 | var int: obj = sum(f in FIRE)(abs(s[f] - best[f])); 27 | solve :: relax_and_reconstruct(s, 70) 28 | minimize obj; 29 | 30 | annotation relax_and_reconstruct(array[int] of var int: x, int:c); 31 | 32 | output["Start = \(s)\n" ++ 33 | "End = \(e)\n" ++ 34 | "Obj = \(obj)\n"]; 35 | 36 | -------------------------------------------------------------------------------- /LS/firefighting/large.dzn: -------------------------------------------------------------------------------- 1 | w = 43; 2 | 3 | n = 100; 4 | d = [29, 78, 9, 36, 49, 11, 62, 56, 44, 21, 43, 90, 75, 11, 69, 28, 46, 46, 72, 30, 91, 85, 39, 74, 90, 10, 12, 89, 45, 33, 81, 95, 71, 99, 9, 52, 85, 98, 22, 43, 14, 6, 22, 61, 26, 69, 21, 49, 72, 53, 84, 2, 52, 95, 48, 72, 47, 65, 6, 25, 46, 37, 61, 13, 32, 21, 32, 89, 30, 55, 31, 86, 46, 74, 32, 88, 19, 48, 36, 79, 76, 69, 76, 51, 85, 11, 40, 89, 26, 74, 85, 13, 61, 7, 64, 76, 47, 52, 90, 45]; 5 | reqW = [23, 14, 3, 27, 19, 23, 22, 4, 31, 8, 6 | 10, 11, 21, 21, 19, 12, 7, 11, 9, 5, 7 | 15, 29, 23, 17, 20, 11, 2, 3, 18, 5, 8 | 6, 13, 30, 9, 19, 6, 2, 8, 12, 19, 9 | 22, 35, 26, 7, 4, 6, 16, 19, 7, 3, 10 | 13, 25, 3, 28, 10, 23, 3, 3, 4, 25, 11 | 4, 15, 16, 8, 24, 16, 13, 9, 7, 7, 12 | 29, 20, 21, 12, 12, 10, 2, 8, 11, 13, 13 | 26, 6, 6, 18, 23, 11, 10, 17, 3, 19, 14 | 34, 26, 18, 7, 10, 1, 2, 13, 26, 29]; 15 | best = [ 159, 268, 3, 798, 29, 5, 16, 22, 76, 98, 16 | 0, 759, 1345, 1068, 3, 1368, 1047, 1327, 36, 124, 17 | 329, 56, 1163, 964, 478, 23, 734, 541, 899, 998, 18 | 123, 33, 264, 79, 681, 371, 524, 1039, 1425, 98, 19 | 456, 1134, 1268, 899, 79, 364, 689, 777, 723, 23, 20 | 1245, 124, 1341, 79, 670, 591, 234, 42, 69, 786, 21 | 893, 1231, 151, 324, 920, 83, 375, 745, 925, 648, 22 | 1269, 211, 753, 349, 749, 43, 98, 134, 134, 62, 23 | 528, 612, 722, 421, 81, 1022, 826, 1433, 1154, 672, 24 | 314, 1170, 478, 33, 72, 689, 124, 425, 628, 830]; 25 | 26 | m = 90; 27 | pre = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99]; 28 | post = [2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99, 100]; 29 | -------------------------------------------------------------------------------- /LS/firefighting/small.dzn: -------------------------------------------------------------------------------- 1 | w = 8; 2 | 3 | n = 10; 4 | d = [1, 5, 8, 2, 4, 9, 6, 3, 1, 6]; 5 | reqW = [2, 3, 1, 4, 3, 2, 5, 1, 2, 4]; 6 | best = [2, 4, 2, 5, 10, 4, 0, 0, 11, 12]; 7 | 8 | m = 6; 9 | pre = [1,5,8,3,4,4]; 10 | post = [4,6,7,4,2,10]; 11 | -------------------------------------------------------------------------------- /LS/lagrange/beast_search.mzn: -------------------------------------------------------------------------------- 1 | var -4 .. 4: x; 2 | var -4 .. 4: y; 3 | 4 | constraint abs(x) != abs(y); 5 | constraint abs(x) + abs(y) < 7; 6 | constraint abs(x * y) > 1; 7 | 8 | % t[x,y] = objective in terms of x and y 9 | array[-4..4,-4..4] of float: t = 10 | array2d(-4..4,-4..4, 11 | [3.986702124977125,0.5117395865616867,3.7472207583471207,0.9847787409105191,3.397289222091853,1.5461403949287984,2.947783242787258,2.132569589632322,2.4181541946331944,-2.202100300696472,-9.068539744126152,-0.5693818968230779,-7.619107113939965,-1.3490686462942278,-6.002742599325405,-2.3937587459253535,-4.423421104618612,-3.6915062220139134,3.623531549039619,1.767048638666779,6.275859229022471,4.0434833704180715,5.995119969369563,4.500140880392461,5.633629308087887,4.975541762243516,5.206449465587349,-1.2266979994597627,-6.957942000364049,2.4360165703944876,0.18202577182963608,4.037831044785493,1.1589770383925657,3.382855734566224,2.124844463793753,2.5763070666860006,3.0782740096125263,0.910400683037766,5.847863984121835,5.299872716361968,8.692276738248587,7.582621564272189,8.425675068849038,7.937528125083786,8.109221532827581,-0.13030797844047193,-4.7451931699163765,3.3104954939467994,1.600686416963855,6.867265956951437,7.442761069721872,8.56394127952078,7.925700006311087,8.153533361962076,2.351181930495727,-0.2756126123292191,5.275700887745128,4.515259863000175,8.283740659393928,9.008393954936551,11.49032832920493,11.210688191452213,11.309366093496646,0.9498721115791184,-2.7140550945543893,4.168320611585319,2.9169619242446956,7.48811183496292,8.144739797354594,11.053464105452854,12.84816662864548,12.911584851211172,1.4534859930607649,-1.8134062240736952,4.567008684694777,3.5049864996570115,7.775314153281986,8.46103426963047,11.211701843353111,12.941912536101341,15.0]); 12 | 13 | var -100.0 .. 100.0: obj; 14 | constraint obj = t[x,y]; 15 | 16 | solve minimize obj; 17 | 18 | -------------------------------------------------------------------------------- /LS/monkey/monkey.dzn: -------------------------------------------------------------------------------- 1 | MONKEY = {Abby,Bell,Cam,Don,Eddy,Fay}; 2 | coop = [| 0, 1, 3, 4, -2, 4 3 | | 1, 0, -2, 3, -1, 3 4 | | 3, -2, 0, -5, 1, 3 5 | | 4, 3, -5, 0, 2, -3 6 | |-2, -1, 1, 2, 0, -2 7 | | 4, 3, 3, -3, -2, 0 |]; 8 | -------------------------------------------------------------------------------- /LS/monkey/monkey.mzn: -------------------------------------------------------------------------------- 1 | enum MONKEY; 2 | array[MONKEY,MONKEY] of int: coop; 3 | int: n = card(MONKEY); 4 | set of int: POS = 1..n; 5 | array[POS] of var MONKEY: monkey; 6 | include "alldifferent.mzn"; 7 | constraint alldifferent(monkey); 8 | solve maximize sum(i in 1..n-1) 9 | (coop[monkey[i],monkey[i+1]]); 10 | -------------------------------------------------------------------------------- /LS/princess/princess.mzn: -------------------------------------------------------------------------------- 1 | solve minimize X*X + X*Y + Y*Y - 3*X - 2*Y; 2 | 3 | var -4..4: X; 4 | var -4..4: Y; 5 | -------------------------------------------------------------------------------- /MIP/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniZinc/specialization-examples/d890155c32b597fbbd560645c4bfd94cb2f0e3e4/MIP/.DS_Store -------------------------------------------------------------------------------- /MIP/linear_programming/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniZinc/specialization-examples/d890155c32b597fbbd560645c4bfd94cb2f0e3e4/MIP/linear_programming/.DS_Store -------------------------------------------------------------------------------- /MIP/linear_programming/initial_BFS.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 1.0*x - 1.0*y + 1.0*z; 10 | constraint 2.0*x - 1.0*y + 2.0*z <= 4.0; 11 | constraint 2.0*x - 3.0*y + 1.0*z <= -5.0; 12 | constraint -1.0*x + 1.0*y - 2.0*z <= -1.0; 13 | -------------------------------------------------------------------------------- /MIP/linear_programming/shield.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.0*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/NEWSHIELD.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniZinc/specialization-examples/d890155c32b597fbbd560645c4bfd94cb2f0e3e4/MIP/mixed_integer_programming/NEWSHIELD.zip -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | % x = 7.777777777777779 17 | % y = -0.0 18 | % z = 4.444444444444443 19 | % obj = 36.66666666666666 20 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield1.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | 18 | % x = 7.0 19 | % y = -0.0 20 | % z = 4.833333333333332 21 | % obj = 35.5 -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield10.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | constraint z >= 3; 22 | constraint x <= 6; 23 | 24 | % x = 6.0 25 | % y = 3.5 26 | % z = 3.0 27 | % obj = 30.5 28 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield11.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | constraint z >= 3; 22 | constraint x <= 6; 23 | constraint y <= 3; 24 | 25 | % x = 6.0 26 | % y = 3.0 27 | % z = 3.0 28 | % obj = 30.0 29 | % WORSE THAN 34 => BACKTRACK 30 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield12.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | constraint z >= 3; 22 | constraint x <= 6; 23 | constraint y >= 4; 24 | 25 | % x = 5.333333333333333 26 | % y = 4.0 27 | % z = 3.0 28 | % obj = 29.0 29 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield13.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | constraint z >= 3; 22 | constraint x <= 6; 23 | constraint y >= 4; 24 | constraint x <= 5; 25 | 26 | % x = 5.0 27 | % y = 4.25 28 | % z = 3.0 29 | % obj = 28.25 30 | % ... => BACKTRACK 31 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield14.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | constraint z >= 3; 22 | constraint x <= 6; 23 | constraint y >= 4; 24 | constraint x >= 6; 25 | 26 | % =====UNSATISFIABLE===== 27 | % => BACKTRACK 28 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield15.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | constraint z >= 3; 22 | constraint x >= 7; 23 | 24 | % =====UNSATISFIABLE===== 25 | % => BACKTRACK 26 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield16.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z >= 4; 20 | 21 | % x = 6.0 22 | % y = 2.0 23 | % z = 4.0 24 | % obj = 32.0 25 | % WORSE 34 => BACKTRACK 26 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield17.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | 19 | % x = 6.666666666666664 20 | % y = -0.0 21 | % z = 5.0 22 | % obj = 34.99999999999999 23 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield18.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | 20 | % x = 6.0 21 | % y = -0.0 22 | % z = 5.333333333333332 23 | % obj = 34.0 24 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield19.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | constraint z <= 5; 20 | 21 | % x = 6.0 22 | % y = 0.5 23 | % z = 5.0 24 | % obj = 33.5 25 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield2.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | 10 | solve maximize 3.0*x + 1.0*y + 3.0*z; 11 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 12 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 13 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 14 | 15 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 16 | 17 | constraint x <= 7; 18 | constraint z <= 4; 19 | 20 | % x = 7.0 21 | % y = 1.249999999999998 22 | % z = 4.0 23 | % obj = 34.25 -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield20.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | constraint z <= 5; 20 | constraint y <= 0; 21 | 22 | % x = 6.0 23 | % y = -0.0 24 | % z = 5.0 25 | % obj = 33.0 26 | % WORSE THAN 34 => BACKTRACK 27 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield21.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | constraint z <= 5; 20 | constraint y >= 1; 21 | 22 | % x = 5.333333333333333 23 | % y = 1.0 24 | % z = 5.0 25 | % obj = 32.0 26 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield22.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | constraint z <= 5; 20 | constraint y >= 1; 21 | constraint x <= 5; 22 | 23 | % x = 5.0 24 | % y = 1.25 25 | % z = 5.0 26 | % obj = 31.25 27 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield23.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | constraint z <= 5; 20 | constraint y >= 1; 21 | constraint x <= 5; 22 | constraint y <= 1; 23 | 24 | % x = 5.0 25 | % y = 1.0 26 | % z = 5.0 27 | % obj = 31.0 28 | % WORSE THAN 34 => BACKTRACK 29 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield24.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | constraint z <= 5; 20 | constraint y >= 1; 21 | constraint x <= 5; 22 | constraint y >= 2; 23 | 24 | % x = 4.0 25 | % y = 2.0 26 | % z = 5.0 27 | % obj = 29.0 28 | % WORSE THAN 34 => BACKTRACK 29 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield25.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | constraint z <= 5; 20 | constraint y >= 1; 21 | constraint x >= 6; 22 | 23 | % =====UNSATISFIABLE===== 24 | % => BACKTRACK 25 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield26.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x <= 6; 19 | constraint z >= 6; 20 | 21 | % x = 4.666666666666664 22 | % y = -0.0 23 | % z = 6.0 24 | % obj = 31.99999999999999 25 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield27.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z >= 5; 18 | constraint x >= 7; 19 | 20 | % =====UNSATISFIABLE===== 21 | % => BACKTRACK 22 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield28.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x >= 8; 17 | 18 | % x = 8.0 19 | % y = -0.0 20 | % z = 4.0 21 | % obj = 36.0 22 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield3.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y <= 1; 19 | 20 | % x = 7.0 21 | % y = 1.0 22 | % z = 4.0 23 | % obj = 34.0 24 | % BEST SOLN SO FAR 25 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield4.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | 20 | % x = 7.0 21 | % y = 2.0 22 | % z = 3.499999999999999 23 | % obj = 33.5 24 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield5.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | 21 | % x = 7.0 22 | % y = 2.749999999999998 23 | % z = 3.0 24 | % obj = 32.75 25 | 26 | 27 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield6.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y <= 2; 21 | 22 | % x = 7.0 23 | % y = 2.0 24 | % z = 3.0 25 | % obj = 32.0 26 | % WORSE THAN 34 => BACKTRACK 27 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield7.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | 22 | % x = 7.0 23 | % y = 3.0 24 | % z = 2.833333333333332 25 | % obj = 32.5 26 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield8.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | constraint z <= 2; 22 | 23 | % x = 7.0 24 | % y = 4.0 25 | % z = 2.0 26 | % obj = 31.0 27 | % WORSE THAN 34 => BACKTRACK 28 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield9.mzn: -------------------------------------------------------------------------------- 1 | var float: x; 2 | var float: y; 3 | var float: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | 16 | constraint x <= 7; 17 | constraint z <= 4; 18 | constraint y >= 2; 19 | constraint z <= 3; 20 | constraint y >= 3; 21 | constraint z >= 3; 22 | 23 | % x = 6.666666666666666 24 | % y = 3.0 25 | % z = 3.0 26 | % obj = 32.0 27 | -------------------------------------------------------------------------------- /MIP/mixed_integer_programming/newshield_int.mzn: -------------------------------------------------------------------------------- 1 | var int: x; 2 | var int: y; 3 | var int: z; 4 | 5 | constraint x >= 0; 6 | constraint y >= 0; 7 | constraint z >= 0; 8 | 9 | solve maximize 3.0*x + 1.0*y + 3.0*z; 10 | constraint 2.0*x + 2.0*y + 1.0*z <= 30.0; 11 | constraint 1.5*x + 2.0*y + 3.0*z <= 25.0; 12 | constraint 2.0*x + 1.0*y + 1.0*z <= 20.0; 13 | 14 | output["x = \(x)\ny = \(y)\nz = \(z)\nobj = \(3.0*x + 1.0*y + 3.0*z)"]; 15 | -------------------------------------------------------------------------------- /debugging/debug/debug1.mzn: -------------------------------------------------------------------------------- 1 | int: n = 5; 2 | array[1..n] of var 1..n: a; 3 | array[1..n] of 1..n: b = [3,5,2,3,1]; 4 | 5 | % constraint forall(j in 1..n, i in b[n-j]..n)(a[j] < i); 6 | constraint forall(j in 1..n) 7 | (assert(n-j in 1..n, "b[\(n-j)]")); 8 | 9 | solve satisfy; -------------------------------------------------------------------------------- /debugging/debug/prod-plan-weapon.dzn: -------------------------------------------------------------------------------- 1 | PRODUCT = {PIKE, SWORD, AXE, SPEAR, CLUB}; 2 | profit = [20.0, 18.0, 3.0, 4.0, 2.0]; 3 | RESOURCE = {IRON, WOOD, SMITH, CARPENTER}; 4 | capacity = [5000, 7500, -2000, 10000]; 5 | consumption = [| 1.5, 1.0, 0.5, 2.0 6 | | 1.0, 0.0, 1.0, 1.0 7 | | 0.0, 1.0, 0.0, 1.0 8 | | 0.1, 1.0, 0.0, 1.0 9 | | 0.0, 0.5, 0.0, 1.0 |]; -------------------------------------------------------------------------------- /debugging/debug/prod-plan.mzn: -------------------------------------------------------------------------------- 1 | % products 2 | enum PRODUCT; 3 | % Profit per unit for each product 4 | array[PRODUCT] of float: profit; 5 | constraint forall(p in PRODUCT) 6 | (assert(profit[p] >= 0, "profit[\(p)] < 0!")); 7 | 8 | % resources 9 | enum RESOURCE; 10 | % Amount of each resource available 11 | array[RESOURCE] of float: capacity; 12 | constraint forall(r in RESOURCE) 13 | (assert(capacity[r] >= 0, "capacity[\(r)] < 0!")); 14 | 15 | 16 | % Units of each resource required to produce 17 | % 1 unit of product 18 | array[PRODUCT,RESOURCE] of float: consumption; 19 | constraint forall(p in PRODUCT, r in RESOURCE) 20 | (assert(consumption[p, r] >= 0, "consumption[\(p),\(r)] < 0!")); 21 | 22 | % Variables: how much should we make of each product 23 | array[PRODUCT] of var int: produce; 24 | 25 | % Must produce a non-negative amount 26 | constraint forall(p in PRODUCT) 27 | (produce[p] >= 0); 28 | 29 | % Production can only use the available resources: 30 | constraint forall(r in RESOURCE) 31 | (sum(p in PRODUCT)(consumption[p, r] * produce[p]) 32 | <= capacity[r]); 33 | 34 | % Maximize profit 35 | solve maximize sum(p in PRODUCT)(profit[p]*produce[p]); 36 | 37 | output [ "\(p): \(produce[p])\n" | p in PRODUCT ]++["PROFIT: \(sum(p in PRODUCT)(profit[p]*produce[p]))"]; -------------------------------------------------------------------------------- /debugging/escape/ escape.dzn: -------------------------------------------------------------------------------- 1 | n = 16; 2 | guard = [0, 8, 3, 5, 0, 3, 9, 8, 0, 4, 0, 0, 10, 8, 14, 8]; 3 | m = 27; 4 | %m = 26; 5 | edge = [| 1,2 6 | | 1,10 7 | | 2,3 8 | % | 2,6 9 | | 2,7 10 | | 3,4 11 | | 3,8 12 | | 3,11 13 | % | 3,15 14 | | 4,5 15 | | 4,8 16 | | 4,16 17 | | 5,16 18 | % | 5,11 19 | | 6,10 20 | | 6,11 21 | | 7,8 22 | | 7,12 23 | | 8,10 24 | | 8,12 25 | | 9,9 26 | | 9,15 27 | | 9,16 28 | | 11,14 29 | | 12,13 30 | | 12,14 31 | | 12,15 32 | | 13,15 33 | | 13,16 34 | | 14,15 |]; 35 | rest = 3; 36 | start = 1; 37 | dest = 9; 38 | maxstep = 10; 39 | -------------------------------------------------------------------------------- /debugging/escape/escape-fixed.mzn: -------------------------------------------------------------------------------- 1 | int: n; 2 | set of int: NODE = 1..n; 3 | array[NODE] of int: guard; 4 | int: m; % number of edges 5 | set of int: EDGE = 1..m; 6 | array[EDGE,1..2] of NODE: edge; 7 | 8 | array[1..2*m, 1..2] of NODE: uedge = 9 | array2d(1..2*m,1..2, [ edge[i,j] | i in EDGE, j in 1..2 ] ++ 10 | [ edge[i,3-j] | i in EDGE, j in 1..2 ]); 11 | 12 | NODE: start; 13 | NODE: dest; 14 | int: rest; % resting every rest junctions 15 | 16 | int: maxstep; 17 | set of int: STEP = 1..maxstep; 18 | var STEP: step; 19 | array[STEP] of var NODE: path; 20 | 21 | include "table.mzn"; 22 | include "sliding_sum.mzn"; 23 | constraint path[1] = start; 24 | constraint forall(i in STEP)(i >= step -> path[i] = dest); 25 | constraint forall(i in 1..maxstep-1) 26 | (table([path[i],path[i+1]],uedge)); 27 | constraint sliding_sum(1,rest,rest, 28 | [guard[path[i]] = 0| i in STEP]); 29 | 30 | solve minimize sum(i in STEP)(guard[path[i]]); -------------------------------------------------------------------------------- /debugging/escape/escape.mzn: -------------------------------------------------------------------------------- 1 | int: n; 2 | set of int: NODE = 1..n; 3 | array[NODE] of int: guard; 4 | int: m; % number of edges 5 | set of int: EDGE = 1..m; 6 | array[EDGE,1..2] of NODE: edge; 7 | NODE: start; 8 | NODE: dest; 9 | int: rest; % resting every rest junctions 10 | 11 | int: maxstep; 12 | set of int: STEP = 1..maxstep; 13 | var STEP: step; 14 | array[STEP] of var NODE: path; 15 | 16 | include "table.mzn"; 17 | include "sliding_sum.mzn"; 18 | constraint path[1] = start; 19 | constraint forall(i in STEP)(i >= step -> path[i] = dest); 20 | constraint forall(i in 1..maxstep-1) 21 | ( 22 | % trace("table([\(path[i]),\(path[i+1])],edge)\n", 23 | table([path[i],path[i+1]],edge)) 24 | % ) 25 | ; 26 | constraint sliding_sum(1,rest,rest, 27 | [guard[path[i]] = 0| i in STEP]); 28 | 29 | solve minimize sum(i in STEP)(guard[path[i]]); 30 | 31 | % path = [1,10,6,11,14,15,9,9,9,9]; 32 | % step = 7; -------------------------------------------------------------------------------- /debugging/parade/parade.dzn: -------------------------------------------------------------------------------- 1 | nsoldier = 14; 2 | height = [7,6,9,6,4,8,3,10,12,13,9,7,8,11]; 3 | strawheight = 6; 4 | 5 | 6 | maxr = 8; 7 | maxc = 8; -------------------------------------------------------------------------------- /debugging/parade/parade0.dzn: -------------------------------------------------------------------------------- 1 | nsoldier = 6; 2 | height = [7,6,9,6,4,8]; 3 | strawheight = 6; 4 | 5 | maxr = 3; 6 | maxc = 3; 7 | -------------------------------------------------------------------------------- /debugging/parade/parade1.dzn: -------------------------------------------------------------------------------- 1 | nsoldier = 9; 2 | height = [7,6,9,6,4,8,5,11,8]; 3 | strawheight = 8; 4 | 5 | maxr = 4; 6 | maxc = 5; 7 | -------------------------------------------------------------------------------- /debugging/sneak/sneak.mzn: -------------------------------------------------------------------------------- 1 | set of int: PATH = 1..10; 2 | set of int: POST = 1..4; 3 | 4 | array[PATH] of int: time; 5 | array[POST] of int: guard; 6 | 7 | var 0..2: weather; 8 | % 0 = storm, 1 = rain, 2 = sun 9 | var PATH: path; 10 | 11 | var int: t = time[path] div weather + 12 | guard[path] * weather; 13 | 14 | solve minimize t; 15 | 16 | time = [ 2, 4, 4, 4, 14, 10, 8, 14, 12, 10]; 17 | guard = [10, 8, 2, 4]; -------------------------------------------------------------------------------- /debugging/sneak/sneakFixed.mzn: -------------------------------------------------------------------------------- 1 | set of int: PATH = 1..10; 2 | set of int: POST = 1..4; 3 | 4 | array[PATH] of int: time; 5 | array[POST] of int: guard; 6 | 7 | var 0..2: weather; 8 | % 0 = storm, 1 = rain, 2 = sun 9 | var PATH: path; 10 | 11 | var int: t = time[path] div weather + 12 | extra * weather; 13 | var int: extra; 14 | constraint path in POST -> extra = guard[path]; 15 | constraint not(path in POST) -> extra = 0; 16 | 17 | solve minimize t; 18 | 19 | time = [ 2, 4, 4, 4, 14, 10, 8, 14, 12, 10]; 20 | guard = [10, 8, 2, 4]; -------------------------------------------------------------------------------- /debugging/twogenerals/twogenerals.mzn: -------------------------------------------------------------------------------- 1 | enum HERO; 2 | enum SPOT; 3 | set of SPOT: LO = {TIANSHU, YONGQUAN}; 4 | set of SPOT: HI = SPOT diff LO; 5 | array[HERO,SPOT] of int: damage; 6 | 7 | array[HERO] of var SPOT: pos1; 8 | array[HERO] of var SPOT: pos2; 9 | 10 | solve maximize sum(h in HERO)(damage[h,pos1[h]] + damage[h,pos2[h]]); 11 | 12 | include "alldifferent.mzn"; 13 | constraint alldifferent(pos1); 14 | constraint alldifferent(pos2); 15 | constraint forall(h in HERO) 16 | (pos1[h] != BAIHUI /\ 17 | pos1[h] in LO -> pos2[h] in HI); 18 | 19 | 20 | HERO = { GUANYU, ZHANGLIAO, XUHUANG } ; 21 | SPOT = { BAIHUI, DANZHONG, QUCHI, TIANSHU, YONGQUAN }; 22 | damage = [| 9,7,6,5,8 23 | | 8,2,5,1,4 24 | | 4,3,7,2,5 |]; 25 | -------------------------------------------------------------------------------- /debugging/twogenerals/twogeneralsFixed.mzn: -------------------------------------------------------------------------------- 1 | enum HERO; 2 | enum SPOT; 3 | set of SPOT: LO = {TIANSHU,YONGQUAN}; 4 | set of SPOT: HI = SPOT diff LO; 5 | array[HERO,SPOT] of int: damage; 6 | 7 | array[HERO] of var SPOT: pos1; 8 | array[HERO] of var SPOT: pos2; 9 | 10 | solve maximize sum(h in HERO)(damage[h,pos1[h]] + damage[h,pos2[h]]); 11 | 12 | include "alldifferent.mzn"; 13 | constraint alldifferent(pos1); 14 | constraint alldifferent(pos2); 15 | constraint forall(h in HERO) 16 | (pos1[h] != BAIHUI /\ 17 | (pos1[h] in LO -> pos2[h] in HI)); 18 | 19 | 20 | HERO = { GUANYU, ZHANGLIAO, XUHUANG } ; 21 | SPOT = { BAIHUI, DANZHONG, QUCHI, TIANSHU, YONGQUAN }; 22 | damage = [| 9,7,6,5,8 23 | | 8,2,5,1,4 24 | | 4,3,7,2,5 |]; 25 | -------------------------------------------------------------------------------- /debugging/wedge/wedge-corrected.mzn: -------------------------------------------------------------------------------- 1 | % cavalry wedge 2 | enum HORSE; % set of horses 3 | enum RIDER; % set of riders 4 | array[HORSE] of int: speed; 5 | array[RIDER] of int: endur; 6 | array[RIDER] of int: strength; 7 | 8 | array[HORSE] of set of RIDER: compatible; 9 | 10 | int: n; % wedge size 11 | set of int: POS = 1..n; 12 | 13 | array[POS] of var HORSE: h; % horse at each position 14 | array[POS] of var RIDER: r; % rider at each position 15 | 16 | constraint forall(i in 1..n div 2-1)(speed[h[i]] < speed[h[i+1]] /\ 17 | endur[r[i]] < endur[r[i+1]]); 18 | constraint forall(i in n div 2..n-1)(speed[h[i]] > speed[h[i+1]] /\ 19 | endur[r[i]] > endur[r[i+1]]); 20 | 21 | include "alldifferent.mzn"; 22 | constraint alldifferent(r); 23 | constraint alldifferent(h); 24 | 25 | constraint forall(p in POS)(r[p] in compatible[h[p]]); 26 | 27 | solve maximize sum(p in POS)(strength[r[p]]); 28 | 29 | output["h = \(h)\nr = \(r)\n"]; -------------------------------------------------------------------------------- /debugging/wedge/wedge-fix1.mzn: -------------------------------------------------------------------------------- 1 | % cavalry wedge 2 | enum HORSE; % set of horses 3 | enum RIDER; % set of riders 4 | array[HORSE] of int: speed; 5 | array[RIDER] of int: endur; 6 | array[RIDER] of int: strength; 7 | 8 | array[HORSE] of set of RIDER: compatible; 9 | 10 | int: n; % wedge size 11 | set of int: POS = 1..n; 12 | 13 | array[POS] of var HORSE: h; % horse at each position 14 | array[POS] of var RIDER: r; % rider at each position 15 | 16 | constraint forall(i in 1..n div 2)(trace("speed[h[\(i)]] < speed[h[\(i+1)]]\n" ++ 17 | "endur[r[\(i)]] < endur[r[\(i+1)]]\n", 18 | speed[h[i]] < speed[h[i+1]] /\ 19 | endur[r[i]] < endur[r[i+1]] 20 | )); 21 | constraint forall(i in n div 2..n-1)(trace("speed[h[\(i)]] > speed[h[\(i+1)]]\n" ++ 22 | "endur[r[\(i)]] > endur[r[\(i+1)]]\n", 23 | speed[h[i]] > speed[h[i+1]] /\ 24 | endur[r[i]] > endur[r[i+1]] 25 | )); 26 | 27 | include "alldifferent.mzn"; 28 | constraint alldifferent(r); 29 | constraint alldifferent(h); 30 | 31 | constraint forall(p in POS)(r[p] in compatible[h[p]]); 32 | 33 | solve maximize sum(p in POS)(strength[r[p]]); 34 | 35 | output["h = \(h)\nr = \(r)\n"]; -------------------------------------------------------------------------------- /debugging/wedge/wedge-fixed.mzn: -------------------------------------------------------------------------------- 1 | % cavalry wedge 2 | enum HORSE; % set of horses 3 | enum RIDER; % set of riders 4 | array[HORSE] of int: speed; 5 | array[RIDER] of int: endur; 6 | array[RIDER] of int: strength; 7 | 8 | array[HORSE] of set of RIDER: compatible; 9 | 10 | int: n; % wedge size 11 | set of int: POS = 1..n; 12 | 13 | array[POS] of var HORSE: h; % horse at each position 14 | array[POS] of var RIDER: r; % rider at each position 15 | 16 | constraint forall(i in 1..n div 2)(trace("speed[h[\(i)]] < speed[h[\(i+1)]]\n" ++ 17 | "endur[r[\(i)]] < endur[r[\(i+1)]]\n", 18 | speed[h[i]] < speed[h[i+1]] /\ 19 | endur[r[i]] < endur[r[i+1]] 20 | )); 21 | constraint forall(i in n div 2+1..n-1)(trace("speed[h[\(i)]] > speed[h[\(i+1)]]\n" ++ 22 | "endur[r[\(i)]] > endur[r[\(i+1)]]\n", 23 | speed[h[i]] > speed[h[i+1]] /\ 24 | endur[r[i]] > endur[r[i+1]] 25 | )); 26 | 27 | include "alldifferent.mzn"; 28 | constraint alldifferent(r); 29 | constraint alldifferent(h); 30 | 31 | constraint forall(p in POS)(r[p] in compatible[h[p]]); 32 | 33 | solve maximize sum(p in POS)(strength[r[p]]); 34 | 35 | output["h = \(h)\nr = \(r)\n"]; -------------------------------------------------------------------------------- /debugging/wedge/wedge-trace.mzn: -------------------------------------------------------------------------------- 1 | % cavalry wedge 2 | enum HORSE; % set of horses 3 | enum RIDER; % set of riders 4 | array[HORSE] of int: speed; 5 | array[RIDER] of int: endur; 6 | array[RIDER] of int: strength; 7 | 8 | array[HORSE] of set of RIDER: compatible; 9 | 10 | int: n; % wedge size 11 | set of int: POS = 1..n; 12 | 13 | array[POS] of var HORSE: h; % horse at each position 14 | array[POS] of var RIDER: r; % rider at each position 15 | 16 | constraint forall(i in 1..n div 2)(trace("speed[h[\(i)]] < speed[h[\(i+1)]]\n" ++ 17 | "endur[r[\(i)]] < endur[r[\(i+1)]]\n", 18 | speed[h[i]] < speed[h[i+1]] /\ 19 | endur[r[i]] < endur[r[i+1]] 20 | )); 21 | constraint forall(i in n div 2..n)(trace("speed[h[\(i)]] > speed[h[\(i+1)]]\n" ++ 22 | "endur[r[\(i)]] > endur[r[\(i+1)]]\n", 23 | speed[h[i]] > speed[h[i+1]] /\ 24 | endur[r[i]] > endur[r[i+1]] 25 | )); 26 | 27 | include "alldifferent.mzn"; 28 | constraint alldifferent(r); 29 | constraint alldifferent(h); 30 | 31 | constraint forall(p in POS)(r[p] in compatible[h[p]]); 32 | 33 | solve maximize sum(p in POS)(strength[r[p]]); 34 | 35 | output["h = \(h)\nr = \(r)\n"]; -------------------------------------------------------------------------------- /debugging/wedge/wedge.dzn: -------------------------------------------------------------------------------- 1 | HORSE = { H1, H2, H3, H4, H5, H6, H7, H8, H9, H10 }; 2 | RIDER = { R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11 }; 3 | 4 | speed = [ 10, 9, 8, 7, 6, 5, 7, 4, 3, 2 ]; 5 | endur = [ 8, 4, 3, 2, 6, 4, 2, 6, 7, 5, 3 ]; 6 | strength = [ 5, 2, 8, 9, 4, 2, 1, 3, 4, 5, 9 ]; 7 | 8 | compatible = [ {R2, R3, R11}, {R5, R6}, {R8}, {R1, R5}, {R4}, {R2, R7}, {R1, R3}, {R9, R1, R10}, {R11, R3}, {R9, R10, R7} ]; 9 | 10 | n = 5; -------------------------------------------------------------------------------- /debugging/wedge/wedge.mzn: -------------------------------------------------------------------------------- 1 | % cavalry wedge 2 | enum HORSE; % set of horses 3 | enum RIDER; % set of riders 4 | array[HORSE] of int: speed; 5 | array[RIDER] of int: endur; 6 | array[RIDER] of int: strength; 7 | 8 | array[HORSE] of set of RIDER: compatible; 9 | 10 | int: n; % wedge size 11 | set of int: POS = 1..n; 12 | 13 | array[POS] of var HORSE: h; % horse at each position 14 | array[POS] of var RIDER: r; % rider at each position 15 | 16 | constraint forall(i in 1..n div 2)(speed[h[i]] < speed[h[i+1]] /\ 17 | endur[r[i]] < endur[r[i+1]]); 18 | constraint forall(i in n div 2..n)(speed[h[i]] > speed[h[i+1]] /\ 19 | endur[r[i]] > endur[r[i+1]]); 20 | 21 | include "alldifferent.mzn"; 22 | constraint alldifferent(r); 23 | constraint alldifferent(h); 24 | 25 | constraint forall(p in POS)(r[p] in compatible[h[p]]); 26 | 27 | solve maximize sum(p in POS)(strength[r[p]]); 28 | 29 | output["h = \(h)\nr = \(r)\n"]; -------------------------------------------------------------------------------- /debugging/wedge/wedgePETER.dzn: -------------------------------------------------------------------------------- 1 | HORSE = { H1, H2, H3, H4, H5, H6, H7 }; 2 | RIDER = { R1, R2, R3, R4, R5, R6, R7, R8 }; 3 | 4 | speed = [ 10, 9, 8, 7, 6, 5, 7 ]; 5 | endur = [ 8, 4, 3, 2, 6, 4, 2, 6]; 6 | strength = [ 5, 2, 8, 9, 4, 2, 1, 3]; 7 | 8 | compatible = [ {R2, R3}, {R5, R6}, { R8}, {R1, R5}, {R4}, {R2, R7}, {R1, R3} ]; 9 | 10 | n = 4; 11 | 12 | %h = [5,1,7,6]; 13 | %r = [4,2,3,7]; -------------------------------------------------------------------------------- /functions/catapult/catapult.dzn: -------------------------------------------------------------------------------- 1 | nSpot = 8; 2 | k = 3; % number of stones 3 | 4 | maxSep = 5.0; 5 | 6 | dist = 7 | [|0.000, 1.414, 2.236, 3.606, 5.831, 6.403, 6.325, 7.616 | 8 | 1.414, 0.000, 1.000, 4.123, 6.325, 6.708, 5.831, 7.211 | 9 | 2.236, 1.000, 0.000, 4.000, 6.083, 6.325, 5.000, 6.403 | 10 | 3.606, 4.123, 4.000, 0.000, 2.236, 2.828, 4.123, 5.000 | 11 | 5.831, 6.325, 6.083, 2.236, 0.000, 1.000, 4.243, 4.472 | 12 | 6.403, 6.708, 6.325, 2.828, 1.000, 0.000, 3.606, 3.606 | 13 | 6.325, 5.831, 5.000, 4.123, 4.243, 3.606, 0.000, 1.414 | 14 | 7.616, 7.211, 6.403, 5.000, 4.472, 3.606, 1.414, 0.000 |]; -------------------------------------------------------------------------------- /functions/catapult/catapult.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | int: nSpot; 4 | set of int: SPOT = 1..nSpot; 5 | 6 | int: k; 7 | set of int: CLUSTER = 1..k; 8 | 9 | float: maxSep; 10 | array[SPOT, SPOT] of float: dist; 11 | 12 | array[SPOT] of var CLUSTER: shot; % clustering decisions 13 | 14 | constraint forall(i,j in SPOT where shot[i] = shot[j])(dist[i, j] <= maxSep); % intra-cluster 15 | 16 | constraint value_precede_chain([i | i in CLUSTER], shot); 17 | 18 | float: maxdist = max([dist[i, j] | i, j in SPOT]); % auxiliary variable 19 | var float :obj = min(i, j in SPOT where i < j)(if shot[i] = shot[j] then maxdist else dist[i, j] endif); % inter-cluster 20 | solve maximize obj; 21 | 22 | output[show(shot), ", obj = ", show(obj)]; -------------------------------------------------------------------------------- /functions/catapult/catapultExact.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | int: nSpot; 4 | set of int: SPOT = 1..nSpot; 5 | 6 | int: k; 7 | set of int: CLUSTER = 1..k; 8 | 9 | float: maxSep; 10 | array[SPOT, SPOT] of float: dist; 11 | 12 | array[SPOT] of var CLUSTER: shot; % clustering decisions 13 | 14 | constraint forall(i,j in SPOT where shot[i] = shot[j])(dist[i, j] <= maxSep); % intra-cluster 15 | 16 | constraint value_precede_chain([i | i in CLUSTER], shot); 17 | 18 | constraint global_cardinality_low_up_closed(shot, 19 | [i | i in CLUSTER], [1 | i in CLUSTER], 20 | [nSpot-k+1 | i in CLUSTER]); 21 | 22 | float: maxdist = max([dist[i, j] | i, j in SPOT]); % auxiliary variable 23 | var float :obj = min(i, j in SPOT where i < j)(if shot[i] = shot[j] then maxdist else dist[i, j] endif); % inter-cluster 24 | solve maximize obj; 25 | 26 | output[show(shot), ", obj = ", show(obj)]; -------------------------------------------------------------------------------- /functions/cellblock/cellBlock.dzn: -------------------------------------------------------------------------------- 1 | PRISONER = {P1, P2, P3, P4, P5, P6, P7, P8, P9, P10}; 2 | 3 | n =4 ; 4 | m = 6; 5 | 6 | cost = [|2, 4, 3, 5, 1, 6 | 6, 2, 3, 1, 5, 4 | 3, 5, 6, 4, 2, 1 | 1, 2, 6, 4, 5, 3|]; 7 | 8 | danger = {P1, P4, P8}; 9 | female = {P1, P6, P7, P10}; 10 | -------------------------------------------------------------------------------- /functions/cellblock/cellBlock.mzn: -------------------------------------------------------------------------------- 1 | % cell block problem (2d model) 2 | include "alldifferent.mzn"; 3 | 4 | enum PRISONER; 5 | 6 | int: n; % number of rows in prison grid 7 | set of int: ROW = 1..n; 8 | 9 | int: m; % number of columns in prison grid 10 | set of int: COL = 1..m; 11 | 12 | array[ROW,COL] of int: cost; 13 | set of PRISONER: danger; 14 | set of PRISONER: female; 15 | set of PRISONER: male = PRISONER diff female; 16 | 17 | array[PRISONER] of var ROW: r; 18 | array[PRISONER] of var COL: c; 19 | 20 | constraint alldifferent([r[p]*m + c[p] | p in PRISONER]); 21 | 22 | constraint forall (p in female) (r[p] <= ((n + 1) div 2)); 23 | constraint forall (p in male) (r[p] > ((n + 1) div 2)); 24 | 25 | constraint forall (d in danger, p in PRISONER where d != p) ((abs(r[d] - r[p]) + abs(c[d] - c[p])) > 1); 26 | 27 | var int: tCost = sum (p in PRISONER) (cost[r[p],c[p]]); 28 | solve minimize tCost; 29 | 30 | output["Female: "++show(p)++" in cell["++show(r[p])++","++show(c[p])++"]\n" | 31 | p in female] 32 | ++ ["\n"]++["Male: "++show(p)++" in cell["++show(r[p])++","++show(c[p])++"]\n" | 33 | p in male] 34 | ++ ["\nTotal Cost: ",show(tCost)]; 35 | 36 | -------------------------------------------------------------------------------- /functions/lvbu/lvbu.dzn: -------------------------------------------------------------------------------- 1 | HERO = {LIU, GUAN, ZHANG}; 2 | SPOT = {BAIHUI, DANZHONG, QUCHI, TIANSHU, YONGQUAN}; 3 | 4 | damage = [|7, 1, 3, 4, 6| 8, 2, 5, 1, 4| 4, 3, 7, 2, 5|]; -------------------------------------------------------------------------------- /functions/lvbu/lvbu.mzn: -------------------------------------------------------------------------------- 1 | % Three heroes combating Lü Bu 2 | include "alldifferent.mzn"; 3 | 4 | enum HERO; 5 | enum SPOT; 6 | 7 | array[HERO,SPOT] of int: damage; 8 | array[HERO] of var SPOT: pos; 9 | 10 | constraint alldifferent(pos); 11 | 12 | var int: tDamages = sum(h in HERO)(damage[h,pos[h]]); 13 | solve maximize tDamages; 14 | 15 | output ["\(h): \(pos[h])\n" | h in HERO] ++ ["Total Damages: \(tDamages)"]; 16 | -------------------------------------------------------------------------------- /functions/patrol/patrol.dzn: -------------------------------------------------------------------------------- 1 | SOLDIER = {S1,S2,S3,S4,S5,S6}; 2 | nDays = 8; 3 | o = 3; 4 | l = 1; 5 | u = 2; -------------------------------------------------------------------------------- /functions/patrol/patrolChannel.mzn: -------------------------------------------------------------------------------- 1 | % Patrol Scheduling 2 | include "globals.mzn"; 3 | 4 | enum SOLDIER; 5 | enum SHIFT = {OFF, EVE, NIGHT}; 6 | 7 | int: nDays; % length of the period 8 | set of int: DAY = 1..nDays; 9 | 10 | int: o; 11 | int: l; 12 | int: u; 13 | 14 | array[SHIFT, DAY] of var set of SOLDIER: rosterShift; 15 | 16 | constraint forall(d in DAY)(card(rosterShift[NIGHT,d]) = o); 17 | constraint forall(d in DAY)(card(rosterShift[EVE,d]) >= l); 18 | constraint forall(d in DAY)(card(rosterShift[EVE,d]) <= u); 19 | 20 | % every soldier has a shift everyday 21 | constraint forall(d in DAY)(rosterShift[OFF,d] union rosterShift[EVE,d] union rosterShift[NIGHT,d] = SOLDIER); 22 | % no soldiers can be in more than one shift 23 | constraint forall(d in DAY)(rosterShift[OFF,d] intersect rosterShift[EVE,d] = {}); 24 | constraint forall(d in DAY)(rosterShift[OFF,d] intersect rosterShift[NIGHT,d] = {}); 25 | constraint forall(d in DAY)(rosterShift[EVE,d] intersect rosterShift[NIGHT,d] = {}); 26 | 27 | % temporal implications 28 | constraint forall (d in 1..(nDays-1), s in SOLDIER) ((s in rosterShift[EVE, d]) -> (not(s in rosterShift[NIGHT, d+1]))); 29 | constraint forall (d in 1..(nDays-2), s in SOLDIER) 30 | ((s in rosterShift[NIGHT, d]) /\ (s in rosterShift[NIGHT, d+1]) -> (not(s in rosterShift[NIGHT, d+2]))); 31 | 32 | %var int: tOnEve = sum(d in DAY)(card(rosterShift[EVE,d])); 33 | %solve maximize (tOnEve); 34 | % solve satisfy; 35 | 36 | % output[show(roster)]; 37 | output ["Shift "++show(s)++" on Day "++show(d)++" takes soldiers "++show(rosterShift[s,d])++"\n" ++ if s == max(SHIFT) then "\n" else "" endif | d in DAY, s in SHIFT]++[show(tOnEve)]; 38 | 39 | array[SOLDIER, DAY] of var SHIFT: rosterSoldier; 40 | 41 | array[DAY] of var l..u: onEve; 42 | constraint forall(d in DAY)(global_cardinality([rosterSoldier[s,d] | s in SOLDIER], [NIGHT, EVE], [o, onEve[d]])); 43 | 44 | 45 | % temporal implications 46 | constraint forall (d in 1..(nDays-1), s in SOLDIER) ((rosterSoldier[s, d] = EVE) -> (rosterSoldier[s, d+1] != NIGHT)); 47 | constraint forall (d in 1..(nDays-2), s in SOLDIER) 48 | ((rosterSoldier[s, d] = NIGHT) /\ (rosterSoldier[s, d+1] = NIGHT) -> (rosterSoldier[s, d+2] != NIGHT)); 49 | 50 | 51 | % constraint forall(d in DAY, so in SOLDIER, sh in SHIFT)(rosterSoldier[so,d] = sh <-> so in rosterShift[sh,d]); 52 | constraint forall(d in DAY) 53 | (int_set_channel([ rosterSoldier[so,d] | so in SOLDIER ], 54 | [ rosterShift[sh,d] | sh in SHIFT ])); 55 | 56 | var int: tOnEve = sum(d in DAY)(onEve[d]); 57 | solve maximize (tOnEve); 58 | 59 | % output[show(roster)]; 60 | output ["Soldier "++show(s)++" on Day "++show(d)++" takes the "++show(rosterSoldier[s,d])++" shift\n" ++ if s == max(SOLDIER) then show(onEve[d])++"\n" else "" endif | d in DAY, s in SOLDIER]++[show(tOnEve)]; -------------------------------------------------------------------------------- /functions/patrol/patrolSet.mzn: -------------------------------------------------------------------------------- 1 | % Patrol Scheduling 2 | 3 | enum SOLDIER; 4 | enum SHIFT = {OFF, EVE, NIGHT}; 5 | 6 | int: nDays; % length of the period 7 | set of int: DAY = 1..nDays; 8 | 9 | int: o; 10 | int: l; 11 | int: u; 12 | 13 | array[SHIFT, DAY] of var set of SOLDIER: roster; 14 | 15 | constraint forall(d in DAY)(card(roster[NIGHT,d]) = o); 16 | constraint forall(d in DAY)(card(roster[EVE,d]) >= l); 17 | constraint forall(d in DAY)(card(roster[EVE,d]) <= u); 18 | 19 | % every soldier has a shift everyday 20 | constraint forall(d in DAY)(roster[OFF,d] union roster[EVE,d] union roster[NIGHT,d] = SOLDIER); 21 | % no soldiers can be in more than one shift 22 | constraint forall(d in DAY)(roster[OFF,d] intersect roster[EVE,d] = {}); 23 | constraint forall(d in DAY)(roster[OFF,d] intersect roster[NIGHT,d] = {}); 24 | constraint forall(d in DAY)(roster[EVE,d] intersect roster[NIGHT,d] = {}); 25 | 26 | % temporal implications 27 | constraint forall (d in 1..(nDays-1), s in SOLDIER) ((s in roster[EVE, d]) -> (not(s in roster[NIGHT, d+1]))); 28 | constraint forall (d in 1..(nDays-2), s in SOLDIER) 29 | ((s in roster[NIGHT, d]) /\ (s in roster[NIGHT, d+1]) -> (not(s in roster[NIGHT, d+2]))); 30 | 31 | var int: tOnEve = sum(d in DAY)(card(roster[EVE,d])); 32 | solve maximize (tOnEve); 33 | % solve satisfy; 34 | 35 | % output[show(roster)]; 36 | output ["Shift "++show(s)++" on Day "++show(d)++" takes soldiers "++show(roster[s,d])++"\n" ++ if s == max(SHIFT) then "\n" else "" endif | d in DAY, s in SHIFT]++[show(tOnEve)]; -------------------------------------------------------------------------------- /functions/patrol/patrolV1.mzn: -------------------------------------------------------------------------------- 1 | enum SOLDIER; 2 | enum SHIFT = { OFF, EVE, NIGHT }; 3 | 4 | int: nDays; 5 | set of int: DAY = 1..nDays; 6 | 7 | int: o; 8 | int: l; 9 | int: u; 10 | 11 | array[SOLDIER,DAY] of var SHIFT: roster; 12 | 13 | constraint forall(d in 1..(nDays-2), s in SOLDIER)((roster[s,d] = NIGHT) /\ (roster[s,d+1] = NIGHT) -> (roster[s,d+2] != NIGHT)); 14 | constraint forall(d in 1..(nDays-1), s in SOLDIER)((roster[s,d] = EVE) -> (roster[s,d+1] != NIGHT)); 15 | 16 | constraint forall(d in DAY)(sum (s in SOLDIER)((roster[s,d] = NIGHT)) = o); 17 | constraint forall(d in DAY)(sum (s in SOLDIER)((roster[s,d] = EVE)) >= l); 18 | constraint forall(d in DAY)(sum (s in SOLDIER)((roster[s,d] = EVE)) <= u); 19 | 20 | var int: tOnEve = sum(d in DAY)(sum(s in SOLDIER)(roster[s,d] = EVE)); 21 | solve maximize (tOnEve); 22 | 23 | output ["Soldier \(s) on Day \(d) takes the \(roster[s,d]) shift\n" 24 | ++ if s == max(SOLDIER) then "\n" else "" endif | d in DAY, s in SOLDIER]++[show(tOnEve)]; 25 | -------------------------------------------------------------------------------- /functions/patrol/patrolV2.mzn: -------------------------------------------------------------------------------- 1 | % Patrol Scheduling 2 | 3 | enum SOLDIER; 4 | enum SHIFT = { OFF, EVE, NIGHT }; 5 | 6 | int: nDays; % length of the period 7 | set of int: DAY = 1..nDays; 8 | 9 | int: o; 10 | int: l; 11 | int: u; 12 | 13 | array[SOLDIER, DAY] of var SHIFT: roster; 14 | 15 | constraint forall (d in 1..(nDays-2), s in SOLDIER) ((roster[s,d] = NIGHT) /\ (roster[s,d+1] = NIGHT) -> (roster[s,d+2] != NIGHT)); 16 | constraint forall (d in 1..(nDays-1), s in SOLDIER) ((roster[s,d] = EVE) -> (roster[s,d+1] != NIGHT)); 17 | 18 | constraint forall (d in DAY) (sum (s in SOLDIER) ((roster[s,d] = NIGHT)) = o); 19 | array[DAY] of var l..u: onEve; 20 | constraint onEve = [sum (s in SOLDIER) (roster[s,d]=EVE) | d in DAY]; 21 | 22 | solve maximize sum(onEve); 23 | 24 | output ["Soldier \(s) on Day \(d) takes the \(roster[s,d]) shift\n" 25 | ++ if s == max(SOLDIER) then "\(onEve[d])\n" else "" endif | d in DAY, s in SOLDIER] 26 | ++[show(sum(onEve))]; 27 | -------------------------------------------------------------------------------- /functions/patrol/patrolV3.mzn: -------------------------------------------------------------------------------- 1 | % Patrol Scheduling 2 | include "globals.mzn"; 3 | 4 | enum SOLDIER; 5 | enum SHIFT = {OFF, EVE, NIGHT}; 6 | 7 | int: nDays; % length of the period 8 | set of int: DAY = 1..nDays; 9 | 10 | int: o; 11 | int: l; 12 | int: u; 13 | 14 | array[SOLDIER, DAY] of var SHIFT: roster; 15 | 16 | constraint forall (d in 1..(nDays-2), s in SOLDIER) ((roster[s,d] = NIGHT) /\ (roster[s,d+1] = NIGHT) -> (roster[s,d+2] != NIGHT)); 17 | constraint forall (d in 1..(nDays-1), s in SOLDIER) ((roster[s,d] = EVE) -> (roster[s,d+1] != NIGHT)); 18 | 19 | array[DAY] of var l..u: onEve; 20 | constraint forall (d in DAY) (global_cardinality([roster[s,d] | s in SOLDIER], [NIGHT, EVE], [o, onEve[d]])); 21 | 22 | solve maximize sum(onEve); 23 | 24 | 25 | output ["Soldier \(s) on Day \(d) takes the \(roster[s,d]) shift\n" 26 | ++ if s == max(SOLDIER) then "\(onEve[d])\n" else "" endif | d in DAY, s in SOLDIER]++[show(sum(onEve))]; 27 | -------------------------------------------------------------------------------- /functions/patrol/patrolV4.mzn: -------------------------------------------------------------------------------- 1 | % Patrol Scheduling 2 | include "globals.mzn"; 3 | 4 | enum SOLDIER; 5 | enum SHIFT = {OFF, EVE, NIGHT}; 6 | 7 | int: nDays; % length of the period 8 | set of int: DAY = 1..nDays; 9 | 10 | int: o; 11 | int: l; 12 | int: u; 13 | 14 | array[SOLDIER, DAY] of var SHIFT: roster; 15 | 16 | constraint forall (d in 1..(nDays-1), s in SOLDIER) ((roster[s, d] = EVE) -> (roster[s, d+1] != NIGHT)); 17 | constraint forall (d in 1..(nDays-2), s in SOLDIER) 18 | ((roster[s, d] = NIGHT) /\ (roster[s, d+1] = NIGHT) -> (roster[s, d+2] != NIGHT)); 19 | 20 | array[DAY] of var l..u: onEve; 21 | constraint forall(d in DAY)(global_cardinality([roster[s,d] | s in SOLDIER], [NIGHT, EVE], [o, onEve[d]])); 22 | constraint forall(d in DAY)(global_cardinality_low_up([roster[s,d] | s in SOLDIER], [NIGHT, EVE], [o,l], [o,u])); 23 | 24 | var int: tOnEve = sum(d in DAY)(onEve[d]); 25 | solve maximize (tOnEve); 26 | 27 | output ["Soldier "++show(s)++" on Day "++show(d)++" takes the "++show(roster[s,d])++" shift\n" ++ if s == max(SOLDIER) then show(onEve[d])++"\n" else "" endif | d in DAY, s in SOLDIER]++[show(tOnEve)]; -------------------------------------------------------------------------------- /functions/patrol/patrolV5.mzn: -------------------------------------------------------------------------------- 1 | % Patrol Scheduling 2 | include "globals.mzn"; 3 | 4 | enum SOLDIER; 5 | enum SHIFT = {OFF, EVE, NIGHT}; 6 | 7 | int: nDays; % length of the period 8 | set of int: DAY = 1..nDays; 9 | 10 | int: o; 11 | int: l; 12 | int: u; 13 | 14 | array[SOLDIER, DAY] of var SHIFT: roster; 15 | 16 | constraint forall (d in 1..(nDays-1), s in SOLDIER) ((roster[s, d] = EVE) -> (roster[s, d+1] != NIGHT)); 17 | constraint forall (d in 1..(nDays-2), s in SOLDIER) 18 | ((roster[s, d] = NIGHT) /\ (roster[s, d+1] = NIGHT) -> (roster[s, d+2] != NIGHT)); 19 | 20 | constraint forall(d in DAY)(global_cardinality_low_up([roster[s,d] | s in SOLDIER], [NIGHT, EVE], [o,l], [o,u])); 21 | 22 | var int: tOnEve = sum(d in DAY)(sum(s in SOLDIER)(roster[s,d] = EVE)); 23 | solve maximize (tOnEve); 24 | 25 | output ["Soldier "++show(s)++" on Day "++show(d)++" takes the "++show(roster[s,d])++" shift\n" ++ if s == max(SOLDIER) then "\n" else "" endif | d in DAY, s in SOLDIER]++[show(tOnEve)]; -------------------------------------------------------------------------------- /functions/patrol/patrolV6.mzn: -------------------------------------------------------------------------------- 1 | % Patrol Scheduling 2 | include "globals.mzn"; 3 | 4 | enum SOLDIER; 5 | enum SHIFT = {OFF, EVE, NIGHT}; 6 | 7 | int: nDays; % length of the period 8 | set of int: DAY = 1..nDays; 9 | 10 | int: o; 11 | int: l; 12 | int: u; 13 | 14 | array[SOLDIER, DAY] of var SHIFT: roster; 15 | 16 | constraint forall (d in 1..(nDays-1), s in SOLDIER) ((roster[s, d] = EVE) -> (roster[s, d+1] != NIGHT)); 17 | constraint forall (d in 1..(nDays-2), s in SOLDIER) 18 | ((roster[s, d] = NIGHT) /\ (roster[s, d+1] = NIGHT) -> (roster[s, d+2] != NIGHT)); 19 | 20 | constraint forall(d in DAY)(global_cardinality_low_up([roster[s,d] | s in SOLDIER], [NIGHT, EVE], [o,l], [o,u])); 21 | array[DAY] of var l..u: onEve; 22 | constraint onEve = [sum (s in SOLDIER) (roster[s,d]=EVE) | d in DAY]; 23 | 24 | var int: tOnEve; 25 | constraint tOnEve = sum(d in DAY)(onEve[d]); 26 | solve maximize (tOnEve); 27 | 28 | output ["Soldier "++show(s)++" on Day "++show(d)++" takes the "++show(roster[s,d])++" shift\n" ++ if s == max(SOLDIER) then "\n" else "" endif | d in DAY, s in SOLDIER]++[show(tOnEve)]; -------------------------------------------------------------------------------- /introduction/army/army.dzn: -------------------------------------------------------------------------------- 1 | budget = 20000; 2 | -------------------------------------------------------------------------------- /introduction/army/army.mzn: -------------------------------------------------------------------------------- 1 | solve maximize 6*F + 10*L + 8*Z + 40*J; 2 | 3 | int: budget = 10000; 4 | constraint 13*F + 21*L + 17*Z + 100*J <= budget; 5 | 6 | var 0..1000: F; 7 | var 0..400: L; 8 | var 0..500: Z; 9 | var 0..150: J; 10 | 11 | output ["F = \(F), L = \(L), Z = \(Z), J = \(J)\n"]; -------------------------------------------------------------------------------- /introduction/army/armyd.mzn: -------------------------------------------------------------------------------- 1 | solve maximize 6*F + 10*L + 8*Z + 40*J; 2 | 3 | int: budget; 4 | constraint 13*F + 21*L + 17*Z + 100*J <= budget; 5 | 6 | var 0..1000: F; 7 | var 0..400: L; 8 | var 0..500: Z; 9 | var 0..150: J; 10 | 11 | output ["F = \(F), L = \(L), Z = \(Z), J = \(J)\n"]; -------------------------------------------------------------------------------- /introduction/army/gatheringanarmy-cheap.mzn: -------------------------------------------------------------------------------- 1 | solve maximize strength; 2 | 3 | var int: strength = 6*A + 10*B + 8*C + 40*D; 4 | 5 | int: budget = 10000; 6 | constraint 13*A + 21*B + 17*C + 90*D <= budget; 7 | 8 | var 0..1000: A; 9 | var 0..400: B; 10 | var 0..500: C; 11 | var 0..150: D; 12 | 13 | B = 0; C = 0; D = 0; 14 | 15 | output ["A = \(A), B = \(B), C = \(C), D = \(D)\n" ++ 16 | "strength = \(6*A + 10*B + 8*C + 40*D)\n" ++ 17 | "size = \(A + B + C + D)\n"]; -------------------------------------------------------------------------------- /introduction/army/gatheringanarmy-strong.mzn: -------------------------------------------------------------------------------- 1 | solve maximize 6*A + 10*B + 8*C + 40*D; 2 | 3 | int: budget = 10000; 4 | constraint 13*A + 21*B + 17*C + 90*D <= budget; 5 | 6 | var 0..1000: A; 7 | var 0..400: B; 8 | var 0..500: C; 9 | var 0..150: D; 10 | 11 | B = 0; A = 0; C = 0; 12 | 13 | output ["A = \(A), B = \(B), C = \(C), D = \(D)\n" ++ 14 | "strength = \(6*A + 10*B + 8*C + 40*D)\n" ++ 15 | "size = \(A + B + C + D)\n"]; -------------------------------------------------------------------------------- /introduction/banquet/banquet.mzn: -------------------------------------------------------------------------------- 1 | enum DISH; 2 | int: capacity; 3 | array[DISH] of int: satisf; 4 | array[DISH] of int: size; 5 | 6 | array[DISH] of var int: amt; % how many of each dish 7 | 8 | constraint forall(i in DISH)(amt[i] >= 0); 9 | constraint sum(i in DISH)(size[i] * amt[i]) <= capacity; 10 | solve maximize sum(i in DISH)(satisf[i] * amt[i]); 11 | 12 | output ["Amount = ", show(amt), "\n"]; -------------------------------------------------------------------------------- /introduction/banquet/banquet1.dzn: -------------------------------------------------------------------------------- 1 | DISH = {SNAKESOUP, GONGBAOFROGS, MAPOTOFU}; 2 | capacity = 18; 3 | satisf = [29,19,8]; 4 | size = [8,5,3]; 5 | -------------------------------------------------------------------------------- /introduction/banquet/banquet2.dzn: -------------------------------------------------------------------------------- 1 | DISH = {CHILIFISHHEAD, SAUSAGE, SEACUCUMBER, CHICKEN, FRIEDRICE}; 2 | capacity = 70; 3 | satisf = [18,16,14,13,6]; 4 | size = [12,10,9,8,4]; 5 | -------------------------------------------------------------------------------- /introduction/color/color.mzn: -------------------------------------------------------------------------------- 1 | enum COLOR = {GREEN, BLUE, PINK, YELLOW}; 2 | 3 | var COLOR: Si; 4 | var COLOR: Yan; 5 | var COLOR: Yu; 6 | var COLOR: Xu; 7 | var COLOR: Qing; 8 | var COLOR: Ji; 9 | var COLOR: You; 10 | var COLOR: Bing; 11 | var COLOR: Yong; 12 | var COLOR: Liang; 13 | var COLOR: Yi; 14 | var COLOR: Jing; 15 | var COLOR: Yang; 16 | var COLOR: Jiao; 17 | 18 | constraint Liang != Yong; 19 | constraint Yong != Yi; 20 | constraint Yong != Jing; 21 | constraint Yong != Si; 22 | constraint Yi != Jing; 23 | constraint Yi != Jiao; 24 | constraint Jiao != Jing; 25 | constraint Jiao != Yang; 26 | constraint Jing != Yang; 27 | constraint Jing != Yong; 28 | constraint Jing != Si; 29 | constraint Jing != Yu; 30 | constraint Yang != Yu; 31 | constraint Yang != Xu; 32 | constraint Yu != Si; 33 | constraint Yu != Yan; 34 | constraint Yu != Xu; 35 | constraint Xu != Yan; 36 | constraint Xu != Qing; 37 | constraint Yan != Si; 38 | constraint Yan != Ji; 39 | constraint Yan != Ji; 40 | constraint Yan != Qing; 41 | constraint Qing != Ji; 42 | constraint Ji != You; 43 | constraint Ji != Bing; 44 | constraint Ji != Si; 45 | constraint You != Bing; 46 | constraint Bing != Si; 47 | 48 | solve satisfy; 49 | 50 | 51 | -------------------------------------------------------------------------------- /introduction/count/count.mzn: -------------------------------------------------------------------------------- 1 | var 100..800: army; 2 | 3 | constraint army mod 5 = 2; 4 | constraint army mod 7 = 2; 5 | constraint army mod 12 = 1; 6 | 7 | solve satisfy; 8 | -------------------------------------------------------------------------------- /introduction/loan/loan.mzn: -------------------------------------------------------------------------------- 1 | % variables 2 | var 0..10000.0: R; % quarterly repayment 3 | %var float: R; 4 | var float: P; % principal initially borrowed 5 | var 0.0 .. 2.0: I; % interest rate 6 | 7 | % intermediate variables 8 | var float: B1; % balance after one quarter 9 | var float: B2; % balance after two quarters 10 | var float: B3; % balance after three quarters 11 | var float: B4; % balance owing at end 12 | 13 | constraint B1 = P * (1.0 + I) - R; 14 | constraint B2 = B1 * (1.0 + I) - R; 15 | constraint B3 = B2 * (1.0 + I) - R; 16 | constraint B4 = B3 * (1.0 + I) - R; 17 | 18 | solve satisfy; 19 | 20 | output [ 21 | "Borrowing ", show_float(0, 2, P), " at ", show_float(0,2,I*100.0), 22 | "% interest, and repaying ", show_float(0, 2, R), 23 | "\nper quarter for 1 year leaves ", show_float(0, 2, B4), " owing\n" 24 | ]; 25 | -------------------------------------------------------------------------------- /introduction/loan/loan1.dzn: -------------------------------------------------------------------------------- 1 | I = 0.0625; 2 | P = 10000.0; 3 | R = 2600.0; 4 | -------------------------------------------------------------------------------- /introduction/loan/loan2.dzn: -------------------------------------------------------------------------------- 1 | I = 0.04; 2 | P = 10000.0; 3 | B4 = 0.0; 4 | -------------------------------------------------------------------------------- /introduction/loan/loan3.dzn: -------------------------------------------------------------------------------- 1 | R = 3000.0; 2 | P = 10000.0; 3 | B4 = 0.0; 4 | -------------------------------------------------------------------------------- /introduction/production/prod-plan-army.dzn: -------------------------------------------------------------------------------- 1 | PRODUCT = {F, L, Z, J}; 2 | profit = [6.0, 10.0, 8.0, 40.0]; 3 | RESOURCE = {MONEY}; 4 | capacity = [10000.0]; 5 | consumption = [| 13.0 | 21.0 | 17.0 | 100.0 |]; -------------------------------------------------------------------------------- /introduction/production/prod-plan-weapon.dzn: -------------------------------------------------------------------------------- 1 | PRODUCT = {AXE, SWORD, PIKE, SPEAR, CLUB}; 2 | profit = [11.0, 18.0, 15.0, 17.0, 11.0]; 3 | RESOURCE = {IRON, WOOD, SMITH, CARPENTER}; 4 | capacity = [5000, 7500, 4000, 3000]; 5 | consumption = [| 1.5, 1.0, 1.0, 1.0 6 | | 2.0, 0.0, 2.0, 0.0 7 | | 1.5, 0.5, 1.0, 1.0 8 | | 0.5, 1.0, 0.9, 1.5 9 | | 0.1, 2.5, 0.1, 2.5 |]; -------------------------------------------------------------------------------- /introduction/production/prod-plan.mzn: -------------------------------------------------------------------------------- 1 | % products 2 | enum PRODUCT; 3 | % Profit per unit for each product 4 | array[PRODUCT] of float: profit; 5 | 6 | % resources 7 | enum RESOURCE; 8 | % Amount of each resource available 9 | array[RESOURCE] of float: capacity; 10 | 11 | % Units of each resource required to produce 12 | % 1 unit of product 13 | array[PRODUCT,RESOURCE] of float: consumption; 14 | 15 | % Variables: how much should we make of each product 16 | array[PRODUCT] of var int: produce; 17 | 18 | % Must produce a non-negative amount 19 | constraint forall(p in PRODUCT) 20 | (produce[p] >= 0); 21 | 22 | % Production can only use the available resources: 23 | constraint forall (r in RESOURCE)( 24 | sum (p in PRODUCT)(consumption[p, r] * produce[p]) <= capacity[r] 25 | ); 26 | 27 | % Maximize profit 28 | solve maximize sum(p in PRODUCT) 29 | (profit[p]*produce[p]); 30 | 31 | output [ "\(p): \(produce[p])\n" | p in PRODUCT ]++["PROFIT: \(sum(p in PRODUCT)(profit[p]*produce[p]))"]; -------------------------------------------------------------------------------- /introduction/rods/rods.mzn: -------------------------------------------------------------------------------- 1 | set of int: DIGIT = 1..9; 2 | array[DIGIT] of int: rods = [1,2,3,4,5,2,3,4,5]; 3 | 4 | var DIGIT: M1; % first messed up digit 5 | var DIGIT: M2; % second messed up digit 6 | var DIGIT: M3; % third messed up digit 7 | var DIGIT: M4; % fourth messed up digit 8 | var DIGIT: M5; % fifth messed up digit 9 | 10 | 11 | constraint rods[M1] + rods[M2] + rods[M3] + 12 | rods[M4] + rods[M5] = 12; 13 | 14 | constraint 2303 + M1 * 10 + 980 + M2 * 1000 + M3 15 | = 301 + M4 * 1000 + M5 * 10; 16 | 17 | % alldifferent messed up digits 18 | include "alldifferent.mzn"; 19 | 20 | constraint alldifferent([M1,M2,M3,M4,M5]); 21 | 22 | solve satisfy; -------------------------------------------------------------------------------- /multiplemodeling/acupuncture/acupuncture.dzn: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | c = 3; % number of jabs in each stage 5 | m = 4; % number of stages -------------------------------------------------------------------------------- /multiplemodeling/acupuncture/acupuncture.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum SPOT = {DAZHUI, TAODAOO, SHENZHU, LINGTAI, ZHIYANG, ZHONGSHU, JIZHONG, XUANSHU, YAOYANGGUAN, YAOYU}; 4 | %大椎 dazhui 5 | %陶道 taodao 6 | %身柱 shenzhu 7 | %灵台 lingtai 8 | %至阳 zhiyang 9 | %中枢 zhongshu 10 | %脊中 jizhong 11 | %悬枢 xuanshu 12 | %腰阳关 yaoyangguan 13 | %腰俞 yaoyu 14 | 15 | int: c; 16 | int: m; 17 | 18 | array[1..m, 1..c] of var SPOT: point; 19 | array[1..m] of var set of SPOT: stage; 20 | 21 | % points to jab in one stage 22 | constraint forall(i in 1..m)(card(stage[i]) = c); 23 | % order within a stage 24 | constraint forall(i in 1..m, j in 1..c-1) 25 | (point[i, j] < point[i, j+1]); 26 | 27 | % no overlapping points among any three stages 28 | constraint forall(i1, i2, i3 in 1..m where i1 < i2 /\ i2 < i3) 29 | ((stage[i1] intersect stage [i2] intersect stage[i3]) = {}); 30 | % order between stages 31 | constraint forall(i in 1..m-1, j in 1..c) 32 | (point[i, j] < point[i+1, j]); 33 | 34 | % ZHIYANG, ZHONGSHU can be jabbed only once 35 | % constraint global_cardinality_low_up([point[i,j]|i in 1..m, j in 1..c], 36 | % [ZHIYANG, ZHONGSHU], [0,0], [1,1]); 37 | constraint sum(i in 1..m)(ZHIYANG in stage[i]) <= 1; 38 | constraint sum(i in 1..m)(ZHONGSHU in stage[i]) <= 1; 39 | 40 | 41 | constraint forall(i in 1..m, s in SPOT) 42 | ((s in stage[i]) -> exists(j in 1..c)(point[i, j] = s)); % channeling 43 | constraint forall(i in 1..m, j in 1..c)(point[i,j] in stage[i]); % channeling 44 | 45 | solve satisfy; 46 | 47 | output[show(array1d(point))]; 48 | % output[show(point)]; -------------------------------------------------------------------------------- /multiplemodeling/belt/belt.dzn: -------------------------------------------------------------------------------- 1 | n = 4; 2 | 3 | m = 2; -------------------------------------------------------------------------------- /multiplemodeling/belt/beltComb.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | int: n; 4 | set of int: DIG = 1..n; 5 | int: m; 6 | set of int: COPY = 1..m; 7 | int: l = m*n; 8 | set of int: POS = 1..l; 9 | array[DIG,COPY] of var POS: p; 10 | set of int: DIGCOP = 1..l; 11 | array[POS] of var DIGCOP: dc; 12 | 13 | constraint forall(d in DIG, c in 1..m-1) 14 | (p[d,c+1] = p[d,c] + d + 1); 15 | constraint inverse(dc, [p[d,c]|d in DIG, c in COPY]); 16 | 17 | solve satisfy; 18 | 19 | output["\((dc[p]-1) div m + 1) " | p in POS]; 20 | -------------------------------------------------------------------------------- /multiplemodeling/belt/beltDig.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | int: n; 4 | set of int: DIG = 1..n; 5 | int: m; 6 | set of int: COPY = 1..m; 7 | int: l = m*n; 8 | set of int: POS = 1..l; 9 | set of int: DIGCOP = 1..l; 10 | array[POS] of var DIGCOP: dc; 11 | 12 | constraint forall(d in DIG, c in 1..m-1, p in POS) 13 | (dc[p] = m*(d-1) + c <-> 14 | dc[p+d+1] = m*(d-1) + c + 1); 15 | constraint alldifferent([ dc[p] | p in POS]); 16 | 17 | solve satisfy; 18 | 19 | output["\((dc[p]-1) div m + 1) " | p in POS]; 20 | 21 | -------------------------------------------------------------------------------- /multiplemodeling/belt/beltPos.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | int: n; 4 | set of int: DIG = 1..n; 5 | int: m; 6 | set of int: COPY = 1..m; 7 | int: l = m*n; 8 | set of int: POS = 1..l; 9 | array[DIG,COPY] of var POS: p; 10 | 11 | constraint forall(d in DIG, c in 1..m-1) 12 | (p[d,c+1] = p[d,c] + d + 1); 13 | constraint alldifferent([ p[d,c] 14 | | d in DIG, c in COPY]); 15 | 16 | solve satisfy; 17 | 18 | output["\(p)"]; 19 | 20 | -------------------------------------------------------------------------------- /multiplemodeling/cookingwine/combined.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum FOOD; 4 | enum WINE; 5 | array[FOOD, WINE] of int: joy; 6 | 7 | array[FOOD] of var WINE: drink; 8 | %constraint alldifferent(drink); 9 | 10 | array[WINE] of var FOOD: eat; 11 | %constraint alldifferent(eat); 12 | 13 | constraint inverse(eat, drink); 14 | 15 | % solve maximize sum (f in FOOD) (joy[f, drink[f]]); 16 | solve maximize sum (w in WINE) (joy[eat[w], w]); 17 | output["Pair Food \(f) with Wine \(drink[f])\n" | f in FOOD] ++ ["\nJoy: \(sum(f in FOOD)(joy[f, drink[f]]))"]; -------------------------------------------------------------------------------- /multiplemodeling/cookingwine/cookWine.dzn: -------------------------------------------------------------------------------- 1 | WINE = {GRAPE, RICE, GAOLIANG, HUADIAO}; 2 | FOOD = {CHILIFISHHEAD, MAPOTOFU, SNAKESOUP, GONGBAOFROG}; 3 | 4 | joy = [|7, 1, 3, 4 | 8, 2, 5, 1 | 4, 3, 7, 2 | 3, 1, 6, 3|]; -------------------------------------------------------------------------------- /multiplemodeling/cookingwine/foodToWine.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum FOOD; 4 | enum WINE; 5 | array[FOOD, WINE] of int: joy; 6 | 7 | array[FOOD] of var WINE: drink; 8 | 9 | constraint alldifferent(drink); 10 | 11 | solve maximize sum(f in FOOD)(joy[f, drink[f]]); 12 | output["Pair Food \(f) with Wine \(drink[f])\n" | f in FOOD] ++ ["\nJoy: \(sum(f in FOOD)(joy[f, drink[f]]))"]; -------------------------------------------------------------------------------- /multiplemodeling/cookingwine/wineToFood.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum FOOD; 4 | enum WINE; 5 | 6 | array[FOOD, WINE] of int: joy; 7 | 8 | array[WINE] of var FOOD: eat; 9 | constraint alldifferent(eat); 10 | 11 | solve maximize sum(w in WINE)(joy[eat[w], w]); 12 | output["Pair Food \(eat[w]) with Wine \(w)\n" | w in WINE] ++ ["\nJoy: \(sum(w in WINE)(joy[eat[w], w]))"]; -------------------------------------------------------------------------------- /multiplemodeling/tunnel/tunnel.dzn: -------------------------------------------------------------------------------- 1 | PIVOT = {P1,P2,P3,P4,P5,P6,P7,P8,P9}; 2 | first = P5; 3 | coord = [0, 3, 7, 10, 16, 18, 21, 25, 28]; % coordinates of cities (to compute distance) 4 | 5 | m = 4; % number of precedence constraints 6 | %prev = [P6, P4, P5, P3]; 7 | %post = [P2, P7, P6, P5]; 8 | prev = [P6, P4, P8, P3]; 9 | post = [P2, P7, P6, P8]; 10 | %prev = [P6, P7, P6, P5]; 11 | %post = [P2, P4, P5, P3]; 12 | % preceduence city pairs -------------------------------------------------------------------------------- /multiplemodeling/tunnel/tunnel.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum PIVOT; 4 | PIVOT: first; 5 | 6 | set of int: POS = 1..card(PIVOT); 7 | array[PIVOT] of int: coord; 8 | 9 | int: m; 10 | set of int: PREC = 1..m; 11 | array[PREC] of PIVOT: prev; 12 | array[PREC] of PIVOT: post; 13 | 14 | array[PIVOT] of var POS: order; % records visiting order of cities 15 | array[POS] of var PIVOT: route; % records the city visited at each step 16 | 17 | constraint route[1] = first; 18 | constraint alldifferent(order); 19 | constraint inverse(order, route); 20 | constraint forall (i in 1..m) (order[prev[i]] < order[post[i]]); 21 | 22 | solve minimize sum(j in 1..card(PIVOT)-1)(abs(coord[route[j+1]] - coord[route[j]])); 23 | 24 | output["Route: \(route), Total Distance: \(sum(j in 1..card(PIVOT)-1)(abs(coord[route[j+1]] - coord[route[j]])))"]; -------------------------------------------------------------------------------- /packing/rectangles/sbpnorotate.dzn: -------------------------------------------------------------------------------- 1 | n = 5; m = 12; 2 | d = [| 1,0,2,5 % (xoffset,yoffset,xsize,ysize) 3 | | 3,4,1,1 4 | | 0,3,1,1 5 | | 1,4,2,2 6 | | 0,1,1,3 % shared by blocks 2 & 3 7 | | 1,0,4,4 8 | | 1,5,1,2 9 | | 1,0,3,5 10 | | 4,1,1,4 11 | | 0,0,1,3 12 | | 1,0,3,4 13 | | 0,0,4,5 |]; 14 | shape = [ {1,2,3}, {4,5,6}, {5,7,8,9}, {12}, {10,11} ]; 15 | h = 9; maxl = 16; -------------------------------------------------------------------------------- /packing/rectangles/sbpnorotate.mzn: -------------------------------------------------------------------------------- 1 | int: n; % number of blocks 2 | set of int: BLOCK = 1..n; 3 | int: m; % number of rectangle/offsets 4 | set of int: ROFF = 1..m; 5 | array[ROFF,1..4] of int: d; % defns 6 | array[BLOCK] of set of ROFF: shape; 7 | int: h; % width of river 8 | int: maxl; % maximum length of river 9 | 10 | array[BLOCK] of var 0..maxl: x; 11 | array[BLOCK] of var 0..h: y; 12 | 13 | var 0..maxl: l; % length of river used 14 | 15 | solve minimize l; 16 | 17 | constraint forall(i in BLOCK)(forall(r in ROFF) 18 | (r in shape[i] -> 19 | (x[i] + d[r,1] + d[r,3] <= l /\ 20 | y[i] + d[r,2] + d[r,4] <= h))); 21 | 22 | constraint forall(i,j in BLOCK where i < j) 23 | (forall(r1,r2 in ROFF) 24 | (r1 in shape[i] /\ 25 | r2 in shape[j] -> 26 | (x[i] + d[r1,1] + d[r1,3] <= x[j] + d[r2,1] 27 | \/ 28 | x[j] + d[r2,1] + d[r2,3] <= x[i] + d[r1,1] 29 | \/ 30 | y[i] + d[r1,2] + d[r1,4] <= y[j] + d[r2,2] 31 | \/ 32 | y[j] + d[r2,2] + d[r2,4] <= y[i] + d[r1,2]) 33 | )); 34 | 35 | output ["l = \(l);\nx = \(x);\ny = \(y)\n"]; -------------------------------------------------------------------------------- /packing/rotation/sbprgeost.dzn: -------------------------------------------------------------------------------- 1 | n = 5; 2 | m = 45; 3 | h = 9; 4 | maxl = 16; 5 | 6 | d = [| 1,0,1,1 7 | | 0,1,5,2 8 | | 0,3,1,1 9 | | 1,0,2,5 10 | | 3,4,1,1 11 | | 3,1,1,1 12 | | 0,0,1,1 13 | | 3,3,1,1 14 | | 4,0,1,1 15 | | 0,0,4,4 16 | | 1,4,3,1 17 | | 4,2,2,2 18 | | 0,2,4,4 19 | | 4,2,1,3 20 | | 2,0,2,2 21 | | 1,0,4,4 22 | | 0,1,1,3 23 | | 1,4,2,2 24 | | 2,1,4,4 25 | | 2,0,3,1 26 | | 0,1,2,2 27 | | 1,5,1,2 28 | | 1,0,3,5 29 | | 4,1,1,4 30 | | 5,3,2,1 31 | | 0,1,5,3 32 | | 1,0,4,1 33 | | 3,0,3,1 34 | | 0,1,2,1 35 | | 2,1,5,3 36 | | 2,4,4,1 37 | | 4,3,1,3 38 | | 3,0,1,2 39 | | 1,2,3,5 40 | | 0,2,1,4 41 | | 0,0,1,3 42 | | 1,0,3,4 43 | | 0,3,3,1 44 | | 0,0,4,3 45 | | 1,0,3,1 46 | | 0,1,4,3 47 | | 3,1,1,3 48 | | 0,0,3,4 49 | | 0,0,5,4 50 | | 0,0,4,5 51 | |]; 52 | 53 | shape = [ {1,2,3}, {3,4,5}, {6,4,7}, {8,2,9}, 54 | {10,11,12}, {13,14,15}, {16,17,18}, {19,20,21}, 55 | {17,22,23,24}, {11,25,26,27}, {28,29,30,31}, {32,33,34,35}, 56 | {44}, {45}, 57 | {36,37}, {38,39}, {40,41}, {42,43} ]; 58 | 59 | shapeind = [ {1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14}, {15,16,17,18} ]; -------------------------------------------------------------------------------- /packing/rotation/sbprgeost.mzn: -------------------------------------------------------------------------------- 1 | int: n; % number of blocks 2 | set of int: BLOCK = 1..n; 3 | int: m; % number of rectangle/offsets 4 | set of int: ROFF = 1..m; 5 | array[ROFF,1..4] of int: d; % defns 6 | array[int] of set of ROFF: shape; 7 | int: h; % width of river 8 | int: maxl; % maximum length of river 9 | 10 | array[BLOCK] of var 0..maxl: x; 11 | array[BLOCK] of var 0..h: y; 12 | 13 | var 0..maxl: l; % length of river used 14 | 15 | solve minimize l; 16 | 17 | % extract the offsets and sizes 18 | array[ROFF,1..2] of int: rsize = 19 | array2d(ROFF, 1..2, 20 | [d[i,j] | i in ROFF, j in 3..4]); 21 | array[ROFF,1..2] of int: roff = 22 | array2d(ROFF, 1..2, 23 | [d[i,j] | i in ROFF, j in 1..2]); 24 | 25 | % pack the x and y coordinates 26 | array[BLOCK,1..2] of var int: coord; 27 | constraint forall(i in BLOCK) 28 | (coord[i,1] = x[i] /\ coord[i,2] = y[i]); 29 | 30 | % set up the "kind" constraints 31 | array[BLOCK] of var int: kind; 32 | array[BLOCK] of set of int: shapeind; 33 | constraint forall(i in BLOCK)(kind[i] in shapeind[i]); 34 | 35 | include "geost.mzn"; 36 | constraint geost_bb(2, 37 | rsize, 38 | roff, 39 | shape, 40 | coord, 41 | kind, 42 | [ 0,0 ], 43 | [ l,h ]); 44 | 45 | 46 | output ["l = \(l);\nx = \(x);\ny = \(y);\nkind = \(kind);\n"]; -------------------------------------------------------------------------------- /packing/rotation/sbprotate.dzn: -------------------------------------------------------------------------------- 1 | n = 5; 2 | m = 45; 3 | h = 9; 4 | maxl = 16; 5 | 6 | d = [| 1,0,1,1 7 | | 0,1,5,2 8 | | 0,3,1,1 9 | | 1,0,2,5 10 | | 3,4,1,1 11 | | 3,1,1,1 12 | | 0,0,1,1 13 | | 3,3,1,1 14 | | 4,0,1,1 15 | | 0,0,4,4 16 | | 1,4,3,1 17 | | 4,2,2,2 18 | | 0,2,4,4 19 | | 4,2,1,3 20 | | 2,0,2,2 21 | | 1,0,4,4 22 | | 0,1,1,3 23 | | 1,4,2,2 24 | | 2,1,4,4 25 | | 2,0,3,1 26 | | 0,1,2,2 27 | | 1,5,1,2 28 | | 1,0,3,5 29 | | 4,1,1,4 30 | | 5,3,2,1 31 | | 0,1,5,3 32 | | 1,0,4,1 33 | | 3,0,3,1 34 | | 0,1,2,1 35 | | 2,1,5,3 36 | | 2,4,4,1 37 | | 4,3,1,3 38 | | 3,0,1,2 39 | | 1,2,3,5 40 | | 0,2,1,4 41 | | 0,0,1,3 42 | | 1,0,3,4 43 | | 0,3,3,1 44 | | 0,0,4,3 45 | | 1,0,3,1 46 | | 0,1,4,3 47 | | 3,1,1,3 48 | | 0,0,3,4 49 | | 0,0,5,4 50 | | 0,0,4,5 51 | |]; 52 | 53 | shape = [| {1,2,3}, {3,4,5}, {6,4,7}, {8,2,9} 54 | | {10,11,12}, {13,14,15}, {16,17,18}, {19,20,21} 55 | | {17,22,23,24}, {11,25,26,27}, {28,29,30,31}, {32,33,34,35} 56 | | {44}, {45}, {}, {} 57 | | {36,37}, {38,39}, {40,41}, {42,43} 58 | 59 | |]; -------------------------------------------------------------------------------- /packing/rotation/sbprotate.mzn: -------------------------------------------------------------------------------- 1 | int: n; % number of blocks 2 | set of int: BLOCK = 1..n; 3 | int: m; % number of rectangle/offsets 4 | set of int: ROFF = 1..m; 5 | array[ROFF,1..4] of int: d; % defns 6 | set of int: ROT = 1..4; 7 | array[BLOCK,ROT] of set of ROFF: shape; 8 | int: h; % width of river 9 | int: maxl; % maximum length of river 10 | 11 | array[BLOCK] of var 0..maxl: x; 12 | array[BLOCK] of var 0..h: y; 13 | array[BLOCK] of var ROT: rot; 14 | 15 | var 0..maxl: l; % length of river used 16 | 17 | solve minimize l; 18 | 19 | constraint forall(i in BLOCK)(shape[i,rot[i]] != {}); 20 | 21 | constraint forall(i in BLOCK)(forall(r in ROFF) 22 | (r in shape[i,rot[i]] -> 23 | (x[i] + d[r,1] + d[r,3] <= l /\ 24 | y[i] + d[r,2] + d[r,4] <= h))); 25 | 26 | constraint forall(i,j in BLOCK where i < j) 27 | (forall(r1,r2 in ROFF) 28 | (r1 in shape[i,rot[i]] /\ 29 | r2 in shape[j,rot[j]] -> 30 | (x[i] + d[r1,1] + d[r1,3] <= x[j] + d[r2,1] 31 | \/ 32 | x[j] + d[r2,1] + d[r2,3] <= x[i] + d[r1,1] 33 | \/ 34 | y[i] + d[r1,2] + d[r1,4] <= y[j] + d[r2,2] 35 | \/ 36 | y[j] + d[r2,2] + d[r2,4] <= y[i] + d[r1,2] 37 | ))); 38 | 39 | output ["l = \(l);\nx = \(x);\ny = \(y);\nrot = \(rot);\n"]; -------------------------------------------------------------------------------- /packing/rotation/sbprotategeost.mzn: -------------------------------------------------------------------------------- 1 | int: n; % number of rooms 2 | set of int: BLOCK = 1..n; 3 | int: m; % number of rectangle/offsets 4 | set of int: ROFF = 1..m; 5 | array[ROFF,1..4] of int: d; % defns 6 | set of int: ROT = 1..4; 7 | array[BLOCK,ROT] of set of ROFF: shape; 8 | int: h; % height of roll 9 | int: maxl; % maximum length of roll 10 | 11 | array[BLOCK] of var 0..maxl: x; 12 | array[BLOCK] of var 0..h: y; 13 | 14 | var 0..maxl: l; % length of carpet used 15 | 16 | solve minimize l; 17 | 18 | % extract the offsets and sizes 19 | array[ROFF,1..2] of int: rsize = 20 | array2d(ROFF, 1..2, 21 | [d[i,j] | i in ROFF, j in 3..4]); 22 | array[ROFF,1..2] of int: roff = 23 | array2d(ROFF, 1..2, 24 | [d[i,j] | i in ROFF, j in 1..2]); 25 | 26 | % pack the x and y coordinates 27 | array[BLOCK,1..2] of var int: coord; 28 | constraint forall(i in BLOCK) 29 | (coord[i,1] = x[i] /\ coord[i,2] = y[i]); 30 | 31 | % extract the shape orientations into 1-d array 32 | array[1..n*4] of set of int: shapeorient = 33 | array1d([shape[i,j]| i in BLOCK, j in 1..4]); 34 | % shape orientations without empty set 35 | array[int] of set of int: neshapeorient = 36 | [shapeorient[i] | i in 1..n*4 where shapeorient[i] != {}]; 37 | 38 | % set up the "kind" constraints 39 | array[BLOCK] of var int: kind; 40 | array[BLOCK] of int: nemptycount = 41 | [ sum(j in 1..4*i)(shapeorient[j] != {}) | i in BLOCK]; 42 | array[BLOCK] of set of int: shapeind = 43 | [ if i = 1 then { j | j in 1..nemptycount[i]} 44 | else {j | j in nemptycount[i-1]+1..nemptycount[i]} 45 | endif | i in BLOCK ]; 46 | constraint forall(i in BLOCK)(kind[i] in shapeind[i]); 47 | 48 | include "geost.mzn"; 49 | constraint geost_bb(2, 50 | rsize, 51 | roff, 52 | neshapeorient, 53 | coord, 54 | kind, 55 | [ 0,0 ], 56 | [ l,h ]); 57 | 58 | 59 | output ["l = \(l);\nx = \(x);\ny = \(y);\nkind = \(kind);\n"]; -------------------------------------------------------------------------------- /packing/squares/large.dzn: -------------------------------------------------------------------------------- 1 | n = 7; 2 | % ncopy = [3,2,0,5,4,3,4]; 3 | ncopy = [4,3,0,5,4,3,4]; -------------------------------------------------------------------------------- /packing/squares/multisqpack.mzn: -------------------------------------------------------------------------------- 1 | int: n; % number of square sizes 2 | set of int: SQUARE = 1..n; 3 | array[SQUARE] of int: ncopy; 4 | int: maxl = sum(i in SQUARE)(i*ncopy[i]); 5 | int: mina = sum(i in SQUARE)(i*i*ncopy[i]); 6 | 7 | var n..maxl: height; 8 | var n..maxl: width; 9 | var mina .. n*maxl: area = height * width; 10 | 11 | int: nsq = sum(i in SQUARE)(ncopy[i]); 12 | set of int: NSQ = 1..nsq; 13 | array[NSQ] of var 0..maxl: x; 14 | array[NSQ] of var 0..maxl: y; 15 | 16 | array[NSQ] of var SQUARE: size; 17 | % calculate size of each square 18 | include "global_cardinality.mzn"; 19 | constraint global_cardinality(size, [i | i in SQUARE], ncopy); 20 | constraint forall(i in 1..nsq-1)(size[i] <= size[i+1]); 21 | 22 | % squares fit in the rectangle 23 | constraint forall(s in NSQ)(x[s] + size[s] <= width); 24 | constraint forall(s in NSQ)(y[s] + size[s] <= height); 25 | 26 | % non overlap 27 | constraint forall(s1, s2 in NSQ where s1 < s2) 28 | (x[s1] + size[s1] <= x[s2] \/ 29 | x[s2] + size[s2] <= x[s1] \/ 30 | y[s1] + size[s1] <= y[s2] \/ 31 | y[s2] + size[s2] <= y[s1]); 32 | 33 | solve minimize area; 34 | 35 | output ["area = ",show(area), "\n"] ++ 36 | ["height = ",show(height), "\n"] ++ 37 | ["width = ",show(width), "\n"] ++ 38 | ["x = ", show(x), "\n"] ++ 39 | ["y = ", show(y), "\n"]; 40 | -------------------------------------------------------------------------------- /packing/squares/multisqpackimp.mzn: -------------------------------------------------------------------------------- 1 | int: n; % number of square sizes 2 | set of int: SQUARE = 1..n; 3 | array[SQUARE] of int: ncopy; 4 | int: maxl = sum(i in SQUARE)(i*ncopy[i]); 5 | int: mina = sum(i in SQUARE)(i*i*ncopy[i]); 6 | 7 | var n..maxl: height; 8 | var n..maxl: width; 9 | var mina .. n*maxl: area = height * width; 10 | 11 | int: nsq = sum(i in SQUARE)(ncopy[i]); 12 | set of int: NSQ = 1..nsq; 13 | array[NSQ] of var 0..maxl: x; 14 | array[NSQ] of var 0..maxl: y; 15 | 16 | array[NSQ] of var SQUARE: size; 17 | include "global_cardinality.mzn"; 18 | constraint global_cardinality(size, [i | i in SQUARE], ncopy); 19 | constraint forall(i in 1..nsq-1)(size[i] <= size[i+1]); 20 | % calculate size of each square 21 | %array[NSQ] of SQUARE: size = [ max(j in SQUARE)(j*(i > base[j])) | i in NSQ]; 22 | 23 | % squares fit in the rectangle 24 | constraint forall(s in NSQ)(x[s] + size[s] <= width); 25 | constraint forall(s in NSQ)(y[s] + size[s] <= height); 26 | 27 | % non overlap with global diffn 28 | include "diffn.mzn"; 29 | constraint diffn(x,y,size,size); 30 | 31 | % redundant cumulative constraints 32 | include "cumulative.mzn"; 33 | constraint cumulative(x, size, size, height); 34 | constraint cumulative(y, size, size, width); 35 | 36 | % symmetry breaking 37 | array[SQUARE] of int: base = 38 | [if i = 1 then 0 else sum(j in 1..i-1)(ncopy[j]) endif | 39 | i in SQUARE]; 40 | include "lex_greater.mzn"; 41 | constraint forall(i in SQUARE) 42 | (forall(j in 1..ncopy[i]-1)( 43 | lex_greater([x[base[i]+j],y[base[i]+j]], 44 | [x[base[i]+j+1],y[base[i]+j+1]]))); 45 | 46 | 47 | solve minimize area; 48 | 49 | output ["area = ",show(area), "\n"] ++ 50 | ["height = ",show(height), "\n"] ++ 51 | ["width = ",show(width), "\n"] ++ 52 | % ["base = ",show(base), "\n"] ++ 53 | % ["size = ",show(size), "\n"] ++ 54 | ["x = ", show(x), "\n"] ++ 55 | ["y = ", show(y), "\n"]; 56 | -------------------------------------------------------------------------------- /packing/squares/multisqpacking copy.dzn: -------------------------------------------------------------------------------- 1 | n = 6; 2 | ncopy = [0,3,2,5,4,3,4]; -------------------------------------------------------------------------------- /packing/squares/multisqpacking copy.mzn: -------------------------------------------------------------------------------- 1 | int: n; % number of squares 2 | set of int: SQUARE = 1..n; 3 | array[1..n+1] of int: ncopy; 4 | int: maxl = sum(i in SQUARE)(i*ncopy[i+1]); 5 | int: mina = sum(i in SQUARE)(i*i*ncopy[i+1]); 6 | 7 | var n..maxl: height; 8 | var n..maxl: width; 9 | var mina .. n*maxl: area = height * width; 10 | 11 | int: nsq = sum(i in SQUARE)(ncopy[i+1]); 12 | set of int: NSQ = 1..nsq; 13 | array[NSQ] of var 0..maxl: x; 14 | array[NSQ] of var 0..maxl: y; 15 | array[NSQ] of var SQUARE: size; 16 | constraint forall(i in NSQ)(exists(j in 0..n-1) 17 | (let {int: sumtoj = sum(k in 1..j)(ncopy[k+1])} 18 | in sumtoj < i /\ i <= sumtoj + ncopy[j+2] 19 | /\ size[i] = j+1)); 20 | 21 | % squares fit in the rectangle 22 | constraint forall(s in NSQ)(x[s] + size[s] <= width); 23 | constraint forall(s in NSQ)(y[s] + size[s] <= height); 24 | 25 | % non overlap 26 | %constraint forall(s1, s2 in NSQ where s1 < s2) 27 | % (x[s1] + size[s1] <= x[s2] \/ 28 | % x[s2] + size[s2] <= x[s1] \/ 29 | % y[s1] + size[s1] <= y[s2] \/ 30 | % y[s2] + size[s2] <= y[s1]); 31 | 32 | % non overlap with global diffn 33 | include "diffn.mzn"; 34 | constraint diffn(x,y,size,size); 35 | 36 | % redundant cumulative constraints 37 | include "cumulative.mzn"; 38 | constraint cumulative(x,size,size,height); 39 | constraint cumulative(y,size,size,width); 40 | 41 | % symmetry breaking 42 | include "lex_greater.mzn"; 43 | constraint forall(i in SQUARE) 44 | (forall(j in 1..ncopy[i+1]-1)( 45 | let {int: base = sum(k in 0..i-1)(ncopy[k+1])} 46 | in lex_greater([x[base+j],y[base+j]],[x[base+j+1],y[base+j+1]]))); 47 | 48 | % variables ordered in reverse size x[n], y[n], x[n-1], y[n-1], ..., x[1], y[1] 49 | %array[1..2*n] of var 0..maxl: vs = [ if i mod 2 = 0 then x[n+1 - i div 2] 50 | % else y[n+1 - i div 2] endif | i in 2..2*n+1 ]; 51 | 52 | %solve :: seq_search([ 53 | % int_search([area,height,width], input_order, indomain_min, complete) 54 | %,int_search(vs, input_order, indomain_min, complete) 55 | % ]) 56 | solve 57 | minimize area; 58 | 59 | output ["area = ",show(area), "\n"] ++ 60 | ["height = ",show(height), "\n"] ++ 61 | ["width = ",show(width), "\n"] ++ 62 | ["x = ", show(x), "\n"] ++ 63 | ["y = ", show(y), "\n"]; 64 | 65 | %area = 340 66 | %height = 17 67 | %width = 20 68 | %x = [13, 12, 9, 14, 9, 17, 17, 17, 14, 6, 16, 16, 10, 6, 6, 5, 0, 11, 10, 0, 0] 69 | %y = [10, 10, 9, 6, 10, 14, 11, 8, 8, 9, 4, 0, 6, 5, 12, 0, 0, 11, 0, 11, 5] -------------------------------------------------------------------------------- /packing/squares/small.dzn: -------------------------------------------------------------------------------- 1 | n = 3; 2 | ncopy = [5,3,2]; -------------------------------------------------------------------------------- /packing/squares/testing.mzn: -------------------------------------------------------------------------------- 1 | int: n = 7; 2 | array[1..n] of int: x = [3,2,0,5,4,3,4]; 3 | 4 | int: len = sum(i in 1..n)(x[i]); 5 | array[1..len] of var int: y; 6 | 7 | constraint y = [ max(j in 1..n)(j*(i > base[j])) | i in 1..len]; 8 | 9 | %include "globals.mzn"; 10 | 11 | %constraint global_cardinality(y, [i|i in 1..n], x); 12 | %constraint forall(i in 1..len-1)(y[i] <= y[i+1]); 13 | 14 | array[1..n] of int: base = 15 | % [sum(j in 1..i)(x[j]) | i in 1..n]; 16 | [if i = 1 then 0 else sum(j in 1..i-1)(x[j]) endif | i in 1..n]; 17 | 18 | solve satisfy; 19 | 20 | output["base = \(base)\ny = \(y)\n"]; -------------------------------------------------------------------------------- /predicates/armyselect/armySelect.dzn: -------------------------------------------------------------------------------- 1 | ELITE = {E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17, E18}; 2 | archer = {E1, E2, E3, E4}; 3 | cavalry = {E5, E6, E7, E8, E9, E10, E11}; 4 | infantry = ELITE diff archer diff cavalry; 5 | 6 | liuValue = [2, 5, 6, 8, 9, 5, 8, 7, 7, 4, 6, 1, 2, 5, 6, 4, 8, 3]; 7 | guanValue = [9, 8, 4, 7, 6, 4, 5, 3, 5, 5, 7, 5, 8, 3, 9, 2, 4, 6]; 8 | zhangValue = [8, 4, 3, 3, 6, 2, 5, 5, 3, 2, 5, 4, 1, 1, 3, 4, 5, 6]; -------------------------------------------------------------------------------- /predicates/armyselect/armySelect.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum ELITE; 4 | set of ELITE: archer; 5 | set of ELITE: cavalry; 6 | set of ELITE: infantry; 7 | array[ELITE] of int: liuValue; 8 | array[ELITE] of int: guanValue; 9 | array[ELITE] of int: zhangValue; 10 | 11 | var set of ELITE: Liu; 12 | var set of ELITE: Guan; 13 | var set of ELITE: Zhang; 14 | 15 | constraint all_disjoint([Liu, Guan, Zhang]); 16 | 17 | constraint card(Liu intersect archer) >= 1; 18 | constraint card(Liu intersect cavalry) >= 2; 19 | constraint card(Liu intersect infantry) >= 2; 20 | constraint card(Liu) = 6; 21 | 22 | constraint card(Guan intersect archer) >= 1; 23 | constraint card(Guan intersect cavalry) >= 2; 24 | constraint card(Guan intersect infantry) >= 2; 25 | constraint card(Guan) = 6; 26 | 27 | constraint card(Zhang intersect archer) >= 1; 28 | constraint card(Zhang intersect cavalry) >= 2; 29 | constraint card(Zhang intersect infantry) >= 2; 30 | constraint card(Zhang) = 6; 31 | 32 | var int: obj = sum(e in Liu)(liuValue[e]) + 33 | sum(e in Guan)(guanValue[e]) + 34 | sum(e in Zhang)(zhangValue[e]); 35 | solve maximize obj; 36 | 37 | output ["Liu: \(Liu)\n"] ++ 38 | ["Guan: \(Guan)\n"] ++ 39 | ["Zhang: \(Zhang)\n"] ++ 40 | ["\nobj = \(obj);\n"]; 41 | -------------------------------------------------------------------------------- /predicates/armyselect/armySelectPred.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum ELITE; 4 | set of ELITE: archer; 5 | set of ELITE: cavalry; 6 | set of ELITE: infantry; 7 | array[ELITE] of int: liuValue; 8 | array[ELITE] of int: guanValue; 9 | array[ELITE] of int: zhangValue; 10 | 11 | var set of ELITE: Liu; 12 | var set of ELITE: Guan; 13 | var set of ELITE: Zhang; 14 | 15 | constraint all_disjoint([Liu, Guan, Zhang]); 16 | 17 | predicate form(var set of ELITE: aTeam) = 18 | card(aTeam intersect archer) >= 1 /\ 19 | card(aTeam intersect cavalry) >= 2 /\ 20 | card(aTeam intersect infantry) >= 2 /\ 21 | card(aTeam) = 6; 22 | 23 | constraint form(Liu); 24 | constraint form(Guan); 25 | constraint form(Zhang); 26 | 27 | var int: obj = sum(e in Liu)(liuValue[e]) + 28 | sum(e in Guan)(guanValue[e]) + 29 | sum(e in Zhang)(zhangValue[e]); 30 | solve maximize obj; 31 | 32 | output ["Liu: \(Liu)\n"] ++ 33 | ["Guan: \(Guan)\n"] ++ 34 | ["Zhang: \(Zhang)\n"] ++ 35 | ["\nobj = \(obj);\n"]; 36 | -------------------------------------------------------------------------------- /predicates/bandits/bandits.dzn: -------------------------------------------------------------------------------- 1 | size = 9; 2 | nPts = 3; 3 | mDist = 3; 4 | 5 | cost = [| 9, 9, 9, 9, 9, 9, 9, 9, 9 | 6 | 8, 0, 8, 0, 8, 0, 8, 0, 9 | 7 | 7, 7, 7, 7, 7, 7, 7, 8, 9 | 8 | 6, 0, 6, 0, 6, 0, 7, 0, 9 | 9 | 5, 5, 5, 5, 5, 6, 7, 8, 9 | 10 | 4, 0, 4, 0, 5, 0, 7, 0, 9 | 11 | 3, 3, 3, 4, 5, 6, 7, 8, 9 | 12 | 2, 0, 3, 0, 5, 0, 7, 0, 9 | 13 | 1, 2, 3, 4, 5, 6, 7, 8, 9 |]; -------------------------------------------------------------------------------- /predicates/bandits/bandits.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | int: size; 4 | int: nPts; 5 | int: mDist; 6 | 7 | array[1..size,1..size] of int: cost; 8 | 9 | array[1..nPts] of var 1..size: ptR; 10 | array[1..nPts] of var 1..size: ptC; 11 | 12 | % all points different 13 | constraint let {array [1..nPts] of var 1..size*size: points = 14 | [(ptR[i]-1)*size + ptC[i] | i in 1..nPts]} in 15 | alldifferent(points); 16 | 17 | % diggable spots 18 | %constraint forall(i in 1..nPts)(not((ptR[i] mod 2) = 0 /\ (ptC[i] mod 2) = 0)); 19 | constraint forall(i in 1..nPts)((ptR[i] mod 2) = 1 \/ (ptC[i] mod 2) = 1); 20 | 21 | % all cells covered 22 | predicate covered(var int: x, var int: y) = 23 | let {var 1..nPts: i, 24 | var int: dist = abs(x-ptR[i]) + abs(y-ptC[i])} in 25 | dist <= mDist; 26 | constraint let {array [1..(size div 2)] of 1..size-1: 27 | huts = [i*2|i in 1..(size div 2)]} in 28 | forall(i,j in huts)(covered(i,j)); 29 | 30 | var int: tCost = sum(i in 1..nPts)(cost[ptR[i],ptC[i]]); 31 | solve minimize tCost; 32 | 33 | output["Row: \(ptR)\nCol: \(ptC)\nCost: \(tCost)"]; 34 | -------------------------------------------------------------------------------- /predicates/brigades/brigades.mzn: -------------------------------------------------------------------------------- 1 | enum BATTALION = {B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17,B18,B19,B20,B21,B22,B23,B24}; 2 | 3 | set of BATTALION: ARCHER = {B1,B2,B3,B4,B15}; 4 | set of BATTALION: SWORD = {B3,B8,B9,B6,B15}; 5 | set of BATTALION: SHIELD = {B1,B3,B15,B16,B18}; 6 | 7 | int: size = 6; 8 | int: nbrigade = card(BATTALION) div size; 9 | set of int: BRIGADE = 1..nbrigade; 10 | 11 | array[BRIGADE] of var set of BATTALION: brigades; 12 | 13 | % size of each brigade 14 | constraint forall(i in 1..nbrigade)(card(brigades[i]) = size); 15 | % all brigades different 16 | include "all_disjoint.mzn"; 17 | constraint all_disjoint(brigades); 18 | 19 | predicate alldifferent(array[int] of var BATTALION:b) = 20 | forall(i,j in index_set(b) where i < j)(b[i] != b[j]); 21 | 22 | predicate pattern(var set of BATTALION: brigade, 23 | array[int] of set of BATTALION: t) = 24 | let { set of int: IND = 1..length(t); 25 | array[IND] of var BATTALION: b; } in 26 | forall(i in IND)(b[i] in t[i] /\ b[i] in brigade) 27 | /\ alldifferent(b); 28 | 29 | 30 | % 2A1B1C, 1A2B1C, 1A1B2C 31 | predicate elite(var set of BATTALION: brigade) = 32 | pattern(brigade, [ARCHER, ARCHER, SHIELD, SHIELD]) 33 | \/ pattern(brigade, [SWORD, SWORD, SWORD]) 34 | \/ pattern(brigade, [ARCHER, SWORD, SWORD, SHIELD]); 35 | 36 | 37 | constraint elite(brigades[1]); 38 | constraint elite(brigades[2]); 39 | %constraint elite(brigades[3]); 40 | 41 | solve satisfy; 42 | %var int: nsuper = sum(i in 1..nbrigade)(elite(brigades[i])); 43 | %solve maximize nsuper; 44 | 45 | output["Brigade \(i): \(brigades[i])\n" | i in 1..nbrigade];%++["nSuper: \(nSuper)"]; 46 | 47 | 48 | -------------------------------------------------------------------------------- /predicates/brigades/even.mzn: -------------------------------------------------------------------------------- 1 | predicate even( var int:x ) = 2 | let { var int: y } in x = 2*y; 3 | var -1..7: u; 4 | constraint not even(u); 5 | 6 | solve satisfy; -------------------------------------------------------------------------------- /predicates/tableseating/table_seating.dzn: -------------------------------------------------------------------------------- 1 | SCHOLAR = {S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, S20}; 2 | reputation = [10, 7, 5, 6, 2, 10, 10, 10, 4, 3, 7, 8, 3, 9, 8, 6, 3, 5, 1, 7]; 3 | 4 | T = 5; 5 | S = 5; 6 | enemies = [| S1, S2 | S4, S5 | S6, S7 | S8, S10 7 | | S11, S12 | S13, S14 | S17, S18 |]; 8 | friends = [| S1, S5 | S2, S6 |]; 9 | 10 | 11 | -------------------------------------------------------------------------------- /predicates/tableseating/table_seating.mzn: -------------------------------------------------------------------------------- 1 | enum SCHOLAR; 2 | array[SCHOLAR] of int: reputation; 3 | int: maxreputation = max(reputation); 4 | 5 | int: T; 6 | set of int: TABLE = 1..T; 7 | int: S; % tables size 8 | array[int,1..2] of SCHOLAR: enemies; 9 | array[int,1..2] of SCHOLAR: friends; 10 | 11 | array[TABLE] of var set of SCHOLAR: table; 12 | 13 | constraint forall(t in TABLE)(card(table[t]) != 1); 14 | 15 | predicate not_same_table(SCHOLAR: p1, SCHOLAR: p2) = 16 | forall(t in TABLE)(not ({p1,p2} subset table[t])); 17 | 18 | constraint forall(t in TABLE)(card(table[t]) <= S); 19 | 20 | constraint forall(p in SCHOLAR)(exists(t in TABLE)(p in table[t])); 21 | constraint forall(t1, t2 in TABLE where t1 < t2) 22 | (table[t1] intersect table[t2] = {}); 23 | 24 | % enemies not on same table 25 | constraint forall(c in index_set_1of2(enemies)) 26 | (not_same_table(enemies[c,1],enemies[c,2])); 27 | 28 | % friends on same table 29 | constraint forall(c in index_set_1of2(friends)) 30 | (not(not_same_table(friends[c,1],friends[c,2]))); 31 | 32 | % important persons (reputation 10) not on same table 33 | constraint forall(p1,p2 in SCHOLAR where p1 < p2 /\ reputation[p1] = 10 /\ reputation[p2] = 10) 34 | (not_same_table(p1,p2)); 35 | 36 | % Use as few tables as possible 37 | var int: obj1; 38 | constraint obj1 = sum(t in TABLE)(card(table[t]) != 0); 39 | 40 | var int: obj2; 41 | constraint obj2 = sum(t in TABLE) 42 | (let {var int: minRep = min([reputation[p]*(p in table[t]) + maxreputation*(1-(p in table[t])) | p in SCHOLAR]); 43 | var int: maxRep = max([reputation[p]*(p in table[t]) | p in SCHOLAR]); } in 44 | if minRep = maxreputation then 0 else maxRep - minRep endif); 45 | 46 | solve minimize (obj1*100 + obj2); 47 | 48 | output ["Table \(t): \(table[t])\n" | t in TABLE] ++ ["Obj1: \(obj1) and Obj2: \(obj2)\n"]; 49 | -------------------------------------------------------------------------------- /predicates/tableseating/table_seating_imp.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum SCHOLAR; 4 | array[SCHOLAR] of int: reputation; 5 | int: maxreputation = max(reputation); 6 | 7 | int: T; % number of tables 8 | set of int: TABLE = 1..T; 9 | int: S; % tables size 10 | array[int,1..2] of SCHOLAR: enemies; 11 | array[int,1..2] of SCHOLAR: friends; 12 | 13 | array[TABLE] of var set of SCHOLAR: table; 14 | array[SCHOLAR] of var TABLE: seat; 15 | 16 | % No for lonely table 17 | constraint forall(t in TABLE)(card(table[t]) != 1); 18 | 19 | % value symmetry breaking 20 | constraint value_precede_chain([t | t in 1..T], seat); 21 | 22 | predicate not_same_table(SCHOLAR: p1, SCHOLAR: p2) = 23 | seat[p1] != seat[p2]; 24 | 25 | constraint global_cardinality_low_up(seat, [t|t in TABLE], [0|t in TABLE], [S|t in TABLE]); 26 | 27 | % enemies not on same table 28 | constraint forall(c in index_set_1of2(enemies)) 29 | (not_same_table(enemies[c,1],enemies[c,2])); 30 | 31 | % friends on same table 32 | constraint forall(c in index_set_1of2(friends)) 33 | (not(not_same_table(friends[c,1],friends[c,2]))); 34 | 35 | % important persons (reputation 10) not on same table 36 | constraint forall(p1,p2 in SCHOLAR where p1 < p2 /\ reputation[p1] = 10 /\ reputation[p2] = 10) 37 | (not_same_table(p1,p2)); 38 | 39 | % Use as few tables as possible 40 | var int: obj1; 41 | constraint obj1 = sum(t in TABLE)(card(table[t]) != 0); 42 | 43 | % minimize the difference in reputation in each table 44 | var int: obj2; 45 | constraint obj2 = sum(t in TABLE) 46 | (let {var int: minRep = min([reputation[p]*(seat[p] = t) + maxreputation*(seat[p] != t) | p in SCHOLAR]); 47 | var int: maxRep = max([reputation[p]*(seat[p] = t) | p in SCHOLAR]); } in 48 | if minRep = maxreputation then 0 else maxRep - minRep endif); 49 | 50 | constraint forall(t in TABLE, p in SCHOLAR)(p in table[t] <-> seat[p] = t); 51 | 52 | solve minimize (obj1*100 + obj2); 53 | 54 | output ["Table \(t): \(table[t])\n" | t in TABLE] ++ ["Obj1: \(obj1) and Obj2: \(obj2)\n"]; 55 | -------------------------------------------------------------------------------- /scheduling/basic/basic_sched.dzn: -------------------------------------------------------------------------------- 1 | TASK = {FUNDS, SOLDIERS, DEFENSE, WEAPONRY_ART, ELITEARMY, 2 | RAW_MATERIALS, CRAFTSMEN, CASTING, BRICKS, WALL}; 3 | 4 | duration = [10,10,25,25,10,20,15,20,10,20]; 5 | p = 14; % number of precedences 6 | pre = 7 | [| FUNDS, SOLDIERS 8 | | FUNDS, RAW_MATERIALS 9 | | FUNDS, CRAFTSMEN 10 | | FUNDS, BRICKS 11 | | SOLDIERS, WEAPONRY_ART 12 | | SOLDIERS, DEFENSE 13 | | WEAPONRY_ART, ELITEARMY 14 | | DEFENSE, ELITEARMY 15 | | RAW_MATERIALS, CASTING 16 | | CRAFTSMEN, CASTING 17 | | CRAFTSMEN, WALL 18 | | BRICKS, WALL 19 | | CASTING, WEAPONRY_ART 20 | | WALL, DEFENSE |]; -------------------------------------------------------------------------------- /scheduling/basic/basic_sched.mzn: -------------------------------------------------------------------------------- 1 | enum TASK; 2 | 3 | array[TASK] of int: duration; 4 | int: p; % number of precedences 5 | set of int: PREC = 1..p; 6 | array[PREC,1..2] of TASK: pre; 7 | 8 | int: t = sum(duration); 9 | array[TASK] of var 0..t: start; 10 | 11 | constraint forall(i in PREC) 12 | ( 13 | %trace("start[\(pre[i,1])] + \(duration[pre[i,1]]) <= start[\(pre[i,2])]\n", 14 | start[pre[i,1]] + duration[pre[i,1]] <= start[pre[i,2]]) 15 | %) 16 | ; 17 | 18 | var 0..t: makespan = max(task in TASK)(start[task] + duration[task]); 19 | solve minimize makespan; 20 | 21 | output [show(makespan)," = ", show(start)]; 22 | -------------------------------------------------------------------------------- /scheduling/cumulative/cumul_sched.dzn: -------------------------------------------------------------------------------- 1 | TASK = {FUNDS, SOLDIERS, DEFENSE, WEAPONRY_ART, ELITEARMY, 2 | RAW_MATERIALS, CRAFTSMEN, CASTING, BRICKS, WALL}; 3 | 4 | duration = [10,10,25,25,10,20,15,20,10,20]; 5 | p = 14; % number of precedences 6 | pre = 7 | [| FUNDS, SOLDIERS 8 | | FUNDS, RAW_MATERIALS 9 | | FUNDS, CRAFTSMEN 10 | | FUNDS, BRICKS 11 | | SOLDIERS, WEAPONRY_ART 12 | | SOLDIERS, DEFENSE 13 | | WEAPONRY_ART, ELITEARMY 14 | | DEFENSE, ELITEARMY 15 | | RAW_MATERIALS, CASTING 16 | | CRAFTSMEN, CASTING 17 | | CRAFTSMEN, WALL 18 | | BRICKS, WALL 19 | | CASTING, WEAPONRY_ART 20 | | WALL, DEFENSE |]; 21 | 22 | RESOURCE = {QUALITY, MILITARY, COMBAT}; 23 | L = [4, 4, 4]; 24 | res = [| 0, 0, 0, 0, 0, 3, 0, 2, 1, 2 25 | | 0, 3, 0, 0, 0, 2, 2, 0, 1, 0 26 | | 0, 0, 2, 2, 1, 0, 0, 0, 0, 2 |]; -------------------------------------------------------------------------------- /scheduling/cumulative/cumul_sched.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum TASK; 4 | 5 | array[TASK] of int: duration; 6 | int: p; % number of precedences 7 | set of int: PREC = 1..p; 8 | array[PREC,1..2] of TASK: pre; 9 | 10 | int: t = sum(duration); 11 | array[TASK] of var 0..t: start; 12 | 13 | enum RESOURCE; 14 | array[RESOURCE] of int: L; % resource limit 15 | array[RESOURCE,TASK] of int: res; 16 | 17 | constraint forall(i in PREC) 18 | (start[pre[i,1]] + duration[pre[i,1]] <= start[pre[i,2]]); 19 | 20 | constraint forall(r in RESOURCE) 21 | (cumulative(start, duration, [res[r,t] | t in TASK], L[r])); 22 | 23 | var int: makespan = max(t in TASK)(start[t] + duration[t]); 24 | 25 | solve minimize makespan; 26 | 27 | output [show(makespan)," = ", show(start)]; 28 | -------------------------------------------------------------------------------- /scheduling/disjunctive/disj_sched_1.dzn: -------------------------------------------------------------------------------- 1 | TASK = {FUNDS, SOLDIERS, DEFENSE, WEAPONRY_ART, ELITEARMY, 2 | RAW_MATERIALS, CRAFTSMEN, CASTING, BRICKS, WALL}; 3 | 4 | duration = [10,10,25,25,10,20,15,20,10,20]; 5 | p = 14; % number of precedences 6 | pre = 7 | [| FUNDS, SOLDIERS 8 | | FUNDS, RAW_MATERIALS 9 | | FUNDS, CRAFTSMEN 10 | | FUNDS, BRICKS 11 | | SOLDIERS, WEAPONRY_ART 12 | | SOLDIERS, DEFENSE 13 | | WEAPONRY_ART, ELITEARMY 14 | | DEFENSE, ELITEARMY 15 | | RAW_MATERIALS, CASTING 16 | | CRAFTSMEN, CASTING 17 | | CRAFTSMEN, WALL 18 | | BRICKS, WALL 19 | | CASTING, WEAPONRY_ART 20 | | WALL, DEFENSE |]; 21 | 22 | LIU = {CASTING, RAW_MATERIALS, BRICKS, WALL}; -------------------------------------------------------------------------------- /scheduling/disjunctive/disj_sched_1.mzn: -------------------------------------------------------------------------------- 1 | enum TASK; 2 | 3 | array[TASK] of int: duration; 4 | int: p; % number of precedences 5 | set of int: PREC = 1..p; 6 | array[PREC,1..2] of TASK: pre; 7 | 8 | 9 | int: t = sum(duration); 10 | array[TASK] of var 0..t: start; 11 | 12 | constraint forall(i in PREC) 13 | (start[pre[i,1]] + duration[pre[i,1]] <= start[pre[i,2]]); 14 | 15 | predicate nonoverlap(var int:s1, var int:d1, 16 | var int:s2, var int:d2)= 17 | s1 + d1 <= s2 \/ s2 + d2 <= s1; 18 | 19 | set of TASK: LIU; 20 | constraint forall(t1, t2 in LIU where t1 < t2) 21 | (nonoverlap(start[t1],duration[t1], 22 | start[t2],duration[t2])); 23 | 24 | var 0..t: makespan = max(t in TASK)(start[t] + duration[t]); 25 | solve minimize makespan; 26 | 27 | output [show(makespan)," = ", show(start)]; 28 | -------------------------------------------------------------------------------- /scheduling/disjunctive/disj_sched_2.dzn: -------------------------------------------------------------------------------- 1 | TASK = {FUNDS, SOLDIERS, DEFENSE, WEAPONRY_ART, ELITEARMY, 2 | RAW_MATERIALS, CRAFTSMEN, CASTING, BRICKS, WALL}; 3 | 4 | duration = [10,10,25,25,10,20,15,20,10,20]; 5 | p = 14; % number of precedences 6 | pre = 7 | [| FUNDS, SOLDIERS 8 | | FUNDS, RAW_MATERIALS 9 | | FUNDS, CRAFTSMEN 10 | | FUNDS, BRICKS 11 | | SOLDIERS, WEAPONRY_ART 12 | | SOLDIERS, DEFENSE 13 | | WEAPONRY_ART, ELITEARMY 14 | | DEFENSE, ELITEARMY 15 | | RAW_MATERIALS, CASTING 16 | | CRAFTSMEN, CASTING 17 | | CRAFTSMEN, WALL 18 | | BRICKS, WALL 19 | | CASTING, WEAPONRY_ART 20 | | WALL, DEFENSE |]; 21 | 22 | LIU = {CASTING, RAW_MATERIALS, BRICKS, WALL}; 23 | ZHANG = {SOLDIERS, RAW_MATERIALS, BRICKS, CRAFTSMEN}; 24 | GUAN = {WEAPONRY_ART, DEFENSE, ELITEARMY, WALL}; -------------------------------------------------------------------------------- /scheduling/disjunctive/disj_sched_2.mzn: -------------------------------------------------------------------------------- 1 | enum TASK; 2 | 3 | array[TASK] of int: duration; 4 | int: p; % number of precedences 5 | set of int: PREC = 1..p; 6 | array[PREC,1..2] of TASK: pre; 7 | 8 | 9 | int: t = sum(duration); 10 | array[TASK] of var 0..t: start; 11 | 12 | constraint forall(i in PREC) 13 | (start[pre[i,1]] + duration[pre[i,1]] <= start[pre[i,2]]); 14 | 15 | predicate nonoverlap(var int:s1, var int:d1, 16 | var int:s2, var int:d2)= 17 | s1 + d1 <= s2 \/ s2 + d2 <= s1; 18 | 19 | predicate exclusive(set of TASK: tasks) = 20 | forall(t1, t2 in tasks where t1 < t2) 21 | (nonoverlap(start[t1],duration[t1], 22 | start[t2],duration[t2])); 23 | 24 | % Liu is in charge of quality assurance 25 | set of TASK: LIU; 26 | constraint exclusive(LIU); 27 | 28 | % Zhang is in charge of military strategies 29 | set of TASK: ZHANG; 30 | constraint exclusive(ZHANG); 31 | 32 | % Quan is in charge of combat training 33 | set of TASK: GUAN; 34 | constraint exclusive(GUAN); 35 | 36 | var 0..t: makespan = max(t in TASK)(start[t] + duration[t]); 37 | solve minimize makespan; 38 | 39 | output [show(makespan)," = ", show(start)]; 40 | -------------------------------------------------------------------------------- /scheduling/disjunctive/disj_sched_glo.mzn: -------------------------------------------------------------------------------- 1 | include "globals.mzn"; 2 | 3 | enum TASK; 4 | 5 | array[TASK] of int: duration; 6 | int: p; % number of precedences 7 | set of int: PREC = 1..p; 8 | array[PREC,1..2] of TASK: pre; 9 | 10 | 11 | int: t = sum(duration); 12 | array[TASK] of var 0..t: start; 13 | 14 | constraint forall(i in PREC) 15 | (start[pre[i,1]] + duration[pre[i,1]] <= start[pre[i,2]]); 16 | 17 | predicate exclusive(set of TASK: tasks) = 18 | let {array[int] of var int: ss = [start[t] | t in tasks]; 19 | array[int] of int: dd = [duration[t] | t in tasks];} 20 | in disjunctive(ss,dd); 21 | 22 | % Liu is in charge of quality assurance 23 | set of TASK: LIU; 24 | constraint exclusive(LIU); 25 | 26 | % Zhang is in charge of military strategies 27 | set of TASK: ZHANG; 28 | constraint exclusive(ZHANG); 29 | 30 | % Quan is in charge of combat training 31 | set of TASK: GUAN; 32 | constraint exclusive(GUAN); 33 | 34 | var 0..t: makespan = max(t in TASK)(start[t] + duration[t]); 35 | solve minimize makespan; 36 | 37 | output [show(makespan)," = ", show(start)]; 38 | -------------------------------------------------------------------------------- /scheduling/seqdependent/doubleChannel.dzn: -------------------------------------------------------------------------------- 1 | nC = 2; 2 | len = [24,32]; 3 | 4 | nS = 7; 5 | speed = [5,6,4,5,4,7,3]; 6 | % desired = [0,5,9,13,16,20,25]; 7 | desired = [0,0,47,33,100,125,175]; 8 | dirn = [2,1,2,1,1,2,1]; 9 | maxt = 400; 10 | leeway = 2; -------------------------------------------------------------------------------- /scheduling/seqdependent/doubleChannel.mzn: -------------------------------------------------------------------------------- 1 | int: nC; % number of channels 2 | array[1..nC] of int: len; 3 | 4 | int: nS; % number of ships 5 | set of int: SHIP = 1..nS; 6 | array[SHIP] of int: speed; % 100m time 7 | array[SHIP] of int: desired; % desired time 8 | int: enter = 1; int: leave = 2; 9 | array[SHIP] of enter..leave: dirn; 10 | 11 | int: leeway; % leeway between 2 ships 12 | int: maxt; % maximum time 13 | set of int: TIME = 0..maxt; 14 | 15 | set of int: SHIPE = 1..nS+nC; % add dummies 16 | int: dummy = 3; 17 | array[SHIPE] of enter..dummy: kind 18 | = dirn ++ [ dummy | i in 1..nC]; 19 | array[SHIPE] of int: speede = speed++[0|i in 1..nC]; 20 | array[SHIPE] of var TIME: start; 21 | array[SHIPE] of var TIME: end; 22 | array[SHIPE] of var 1..nC: channel; 23 | 24 | array[SHIP] of var SHIPE: next; % next ship 25 | 26 | constraint forall(s in nS + 1 .. nS + nC) 27 | (start[s] = maxt /\ end[s] = maxt); 28 | constraint forall(s in nS + 1 .. nS + nC) 29 | (channel[s] = s - nS); 30 | 31 | constraint forall(s in SHIP)(end[s] = start[s] + 32 | len[channel[s]]*speed[s]); 33 | 34 | include "alldifferent.mzn"; 35 | constraint alldifferent(next); 36 | 37 | constraint forall(s in SHIP) 38 | % ships of opposite dirn 39 | (if kind[s] + kind[next[s]] = 3 then 40 | end[s] <= start[next[s]] 41 | else % same dirn 42 | start[s]+speed[s]*leeway <= start[next[s]] /\ 43 | end[s]+speede[next[s]]*leeway <= end[next[s]] 44 | endif); 45 | 46 | constraint forall(s in SHIP)(start[s] >= desired[s]); 47 | 48 | constraint forall(s in SHIP) 49 | (channel[next[s]] = channel[s]); 50 | 51 | solve minimize max(s in SHIP)(end[s]); 52 | %solve minimize sum(s in SHIP)(start[s] - desired[s]); 53 | %solve minimize sum(s in SHIP)(end[s] - desired[s]); 54 | 55 | output [ "start = ",show(start), 56 | ";\nend = ", show(end), 57 | ";\nchannel = ", show(channel), 58 | ";\nnext = ", show(next), 59 | ";\n" ]; 60 | -------------------------------------------------------------------------------- /scheduling/seqdependent/singleChannel.dzn: -------------------------------------------------------------------------------- 1 | nS = 7; 2 | len = 32; 3 | speed = [5,6,4,5,4,7,3]; 4 | % desired = [0,5,9,13,16,20,25]; 5 | desired = [0,0,47,33,100,125,175]; 6 | dirn = [2,1,2,1,1,2,1]; 7 | maxt = 600; 8 | leeway = 2; -------------------------------------------------------------------------------- /scheduling/seqdependent/singleChannel.mzn: -------------------------------------------------------------------------------- 1 | int: len; 2 | 3 | int: nS; % number of ships 4 | set of int: SHIP = 1..nS; 5 | array[SHIP] of int: speed; % 100m time 6 | array[SHIP] of int: desired; % desired time 7 | int: enter = 1; int: leave = 2; 8 | array[SHIP] of enter..leave: dirn; 9 | 10 | int: leeway; % leeway between 2 ships 11 | int: maxt; % maximum time 12 | set of int: TIME = 0..maxt; 13 | 14 | set of int: SHIPE = 1..nS+1; % add dummies 15 | int: dummy = 3; 16 | array[SHIPE] of enter..dummy: kind 17 | = dirn ++ [ dummy ]; 18 | array[SHIPE] of int: speede = speed++[0]; 19 | array[SHIPE] of var TIME: start; 20 | array[SHIPE] of var TIME: end; 21 | 22 | array[SHIP] of var SHIPE: next; % next ship 23 | 24 | constraint start[nS+1] = maxt; 25 | constraint end[nS+1] = maxt; 26 | 27 | constraint forall(s in SHIP)(end[s] = start[s] + 28 | len*speed[s]); 29 | 30 | include "globals.mzn"; 31 | constraint alldifferent(next); 32 | 33 | constraint forall(s in SHIP) 34 | % ships of opposite dirn 35 | (if kind[s] + kind[next[s]] = 3 then 36 | end[s] <= start[next[s]] 37 | else % same dirn 38 | start[s]+speed[s]*leeway <= start[next[s]] /\ 39 | end[s]+speede[next[s]]*leeway <= end[next[s]] 40 | endif); 41 | 42 | constraint forall(s in SHIP)(start[s] >= desired[s]); 43 | 44 | solve minimize max(s in SHIP)(end[s]); 45 | %solve minimize sum(s in SHIP)(start[s] - desired[s]); 46 | 47 | output [ "start = ",show(start), 48 | ";\nend = ", show(end), 49 | ";\nnext = ", show(next), 50 | ";\n" ]; -------------------------------------------------------------------------------- /sets/bagua/bagua-10-8.dzn: -------------------------------------------------------------------------------- 1 | nSpots = 10; 2 | SYMB = {'天','泽','火','雷','风','水','山','地'}; % name them properly ! 3 | 4 | group = [{1, 4, 6}, {1, 2, 6, 7}, {1, 3, 6, 8}, {1, 2, 3}, {2, 9, 10}, {5, 6, 8, 10}, {7, 8, 10}, {1, 3, 5}]; 5 | % groups of spots grouped by Bagua properties. 6 | 7 | damage = [10, 8, 4, 2, 6, 9, 5, 3, 8, 10]; 8 | 9 | % reward of attacking spots -------------------------------------------------------------------------------- /sets/bagua/bagua.mzn: -------------------------------------------------------------------------------- 1 | % Attack on walls 2 | int: nSpots; 3 | set of int: SPOT = 1..nSpots; 4 | array[SPOT] of int: damage; 5 | 6 | enum SYMB; 7 | array[SYMB] of set of SPOT: group; 8 | 9 | var set of SPOT: attacks; % decision variable (set variable) 10 | 11 | constraint forall(s in SYMB)(card(attacks intersect group[s]) <= 1); 12 | 13 | var int: totalDamages = sum(p in attacks)(damage[p]); 14 | solve maximize (totalDamages); % Goal: maximize attack reward 15 | 16 | output["Attacks: ", show(attacks), " and damages: ", show(totalDamages)] -------------------------------------------------------------------------------- /sets/bagua/baguaBounded-10-8.dzn: -------------------------------------------------------------------------------- 1 | nSpots = 10; 2 | SYMB = {'天','泽','火','雷','风','水','山','地'}; % name them properly ! 3 | size = 3; 4 | 5 | group = [{1, 4, 6}, {1, 2, 6, 7}, {1, 3, 6, 8}, {1, 2, 3}, {2, 9, 10}, {5, 6, 8, 10}, {7, 8, 10}, {1, 3, 5}]; 6 | % groups of spots grouped by Bagua properties. 7 | 8 | damage = [10, 8, 4, 2, 6, 9, 5, 3, 8, 10]; 9 | 10 | % reward of attacking spots -------------------------------------------------------------------------------- /sets/bagua/baguaBoundedInt.mzn: -------------------------------------------------------------------------------- 1 | % Attack on walls 2 | 3 | int: nSpots; 4 | set of int: SPOT = 1..nSpots; % spot set 5 | array[SPOT] of int: damage; 6 | 7 | enum SYMB; % property set 8 | array[SYMB] of set of int: group; 9 | 10 | int: size; 11 | set of int: SPOTx = {0} union SPOT; 12 | array[1..size] of var 0..nSpots: attacks; % decision variable (set variable) 13 | 14 | constraint forall(s in SYMB)(sum(i in 1..size)(attacks[i] in group[s]) <= 1); 15 | constraint forall(i in 1..size-1)(attacks[i] >= (attacks[i] != 0) + attacks[i+1]); 16 | 17 | var int: totalDamages = sum(p in attacks where p > 0)(damage[p]); 18 | solve maximize (totalDamages); % Goal: maximize attack reward 19 | 20 | output["Attacks: ", show(attacks), " and damages: ", show(totalDamages)] -------------------------------------------------------------------------------- /sets/bagua/baguaBoundedIntW.mzn: -------------------------------------------------------------------------------- 1 | % Attack on walls 2 | 3 | int: nSpots; 4 | set of int: SPOT = 1..nSpots; % spot set 5 | array[SPOT] of int: damage; 6 | 7 | enum SYMB; % property set 8 | array[SYMB] of set of int: group; 9 | 10 | int: size; 11 | set of int: SPOTx = {0} union SPOT; 12 | array[1..size] of var 0..nSpots: attacks; % decision variable (set variable) 13 | 14 | constraint forall(s in SYMB)(sum(i in 1..size)(attacks[i] in group[s]) <= 1); 15 | constraint forall(i in 1..size-1)(attacks[i] >= (attacks[i] != 0) + attacks[i+1]); 16 | 17 | var int: totalDamages = sum(p in attacks)(damage[p]); 18 | solve maximize (totalDamages); % Goal: maximize attack reward 19 | 20 | output["Attacks: ", show(attacks), " and damages: ", show(totalDamages)] -------------------------------------------------------------------------------- /sets/bagua/baguaBoundedSet.mzn: -------------------------------------------------------------------------------- 1 | % Attack on walls 2 | 3 | int: nSpots; 4 | set of int: SPOT = 1..nSpots; % spot set 5 | array[SPOT] of int: damage; 6 | 7 | enum SYMB; % property set 8 | array[SYMB] of set of int: group; 9 | 10 | int: size; 11 | var set of SPOT: attacks; % decision variable (set variable) 12 | 13 | constraint forall(s in SYMB)(card(attacks intersect group[s]) <= 1); 14 | constraint card(attacks) <= size; 15 | 16 | var int: totalDamages = sum(p in attacks)(damage[p]); 17 | solve maximize (totalDamages); % Goal: maximize attack reward 18 | 19 | output["Attacks: ", show(attacks), " and damages: ", show(totalDamages)] -------------------------------------------------------------------------------- /sets/bagua/baguaCard-10-8.dzn: -------------------------------------------------------------------------------- 1 | nSpots = 10; 2 | SYMB = {'天','泽','火','雷','风','水','山','地'}; % name them properly ! 3 | size = 3; 4 | 5 | group = [{1, 4, 6}, {1, 2, 6, 7}, {1, 3, 6, 8}, {1, 2, 3}, {2, 9, 10}, {5, 6, 8, 10}, {7, 8, 10}, {1, 3, 5}]; 6 | % groups of spots grouped by Bagua properties. 7 | 8 | damage = [10, 8, 4, 2, 6, 9, 5, 3, 8, 10]; 9 | 10 | % reward of attacking spots -------------------------------------------------------------------------------- /sets/bagua/baguaCardInt.mzn: -------------------------------------------------------------------------------- 1 | % Attack on walls 2 | 3 | int: nSpots; 4 | set of int: SPOT = 1..nSpots; % spot set 5 | array[SPOT] of int: damage; 6 | 7 | enum SYMB; % property set 8 | array[SYMB] of set of SPOT: group; 9 | 10 | int: size; 11 | array[1..size] of var SPOT: attacks; % decision variable (set variable) 12 | 13 | constraint forall(s in SYMB)(sum(i in 1..size)(attacks[i] in group[s]) <= 1); 14 | constraint forall(i in 1..size-1)(attacks[i] < attacks[i+1]); 15 | 16 | var int: totalDamages = sum(p in attacks)(damage[p]); 17 | solve maximize (totalDamages); % Goal: maximize attack reward 18 | 19 | output["Attacks: ", show(attacks), " and damages: ", show(totalDamages)] -------------------------------------------------------------------------------- /sets/bagua/baguaCardSet.mzn: -------------------------------------------------------------------------------- 1 | % Attack on walls 2 | 3 | int: nSpots; 4 | set of int: SPOT = 1..nSpots; % spot set 5 | array[SPOT] of int: damage; 6 | 7 | enum SYMB; % property set 8 | array[SYMB] of set of SPOT: group; 9 | 10 | int: size; 11 | var set of SPOT: attacks; % decision variable (set variable) 12 | 13 | constraint forall(s in SYMB)(card(attacks intersect group[s]) <= 1); 14 | constraint card(attacks) = size; 15 | 16 | var int: totalDamages = sum(p in attacks)(damage[p]); 17 | solve maximize (totalDamages); % Goal: maximize attack reward 18 | 19 | output["Attacks: ", show(attacks), " and damages: ", show(totalDamages)] -------------------------------------------------------------------------------- /sets/yellowturban/yellow-data.dzn: -------------------------------------------------------------------------------- 1 | nMoves = 5; 2 | timeBound = 10; 3 | power = [6, 8, 5, 3, 4]; 4 | duration = [4, 5, 3, 2, 3]; -------------------------------------------------------------------------------- /sets/yellowturban/yellow.mzp: -------------------------------------------------------------------------------- 1 | { 2 | "openFiles": [ 3 | "yellow01SetConcise.mzn", 4 | "yellow-data.dzn", 5 | "yellow01.mzn", 6 | "yellow01Basic.mzn", 7 | "yellow01Bool.mzn", 8 | "yellow01Set.mzn" 9 | ], 10 | "openTab": 2, 11 | "projectFiles": [ 12 | "yellow-data.dzn", 13 | "yellow01.mzn", 14 | "yellow01Basic.mzn", 15 | "yellow01Bool.mzn", 16 | "yellow01Set.mzn", 17 | "yellow01SetConcise.mzn" 18 | ], 19 | "selectedBuiltinConfigId": "org.gecode.gecode", 20 | "selectedBuiltinConfigVersion": "6.3.0", 21 | "version": 106 22 | } 23 | -------------------------------------------------------------------------------- /sets/yellowturban/yellow01.mzn: -------------------------------------------------------------------------------- 1 | % Oath at the Peach Garden as a knapsack problem. 2 | 3 | int: nMoves; 4 | set of int: MOVES = 1..nMoves; 5 | int: timeBound; 6 | array[MOVES] of 1..20: power; 7 | array[MOVES] of 1..10: duration; 8 | array[MOVES] of var 0..1: occur; 9 | 10 | constraint (sum(i in MOVES)(duration[i] * occur[i])) <= timeBound; 11 | 12 | solve maximize sum(i in MOVES)(power[i] * occur[i]); 13 | 14 | output [show(occur)]; -------------------------------------------------------------------------------- /sets/yellowturban/yellow01Basic.mzn: -------------------------------------------------------------------------------- 1 | % Oath at the Peach Garden as a knapsack problem. 2 | 3 | int: nMoves; 4 | set of int: MOVES = 1..nMoves; 5 | int: timeBound; 6 | array[MOVES] of 1..20: power; 7 | array[MOVES] of 1..10: duration; 8 | array[MOVES] of var int: occur; 9 | 10 | constraint forall(i in MOVES)(occur[i] >= 0); 11 | constraint forall(i in MOVES)(occur[i] <= 1); 12 | 13 | constraint (sum(i in MOVES)(duration[i] * occur[i])) <= timeBound; 14 | 15 | solve maximize sum(i in MOVES)(power[i] * occur[i]); 16 | 17 | output [show(occur)]; -------------------------------------------------------------------------------- /sets/yellowturban/yellow01Bool.mzn: -------------------------------------------------------------------------------- 1 | % Oath at the Peach Garden as a knapsack problem. 2 | 3 | int: nMoves; 4 | set of int: MOVES = 1..nMoves; 5 | int: timeBound; 6 | array[MOVES] of 1..20: power; 7 | array[MOVES] of 1..10: duration; 8 | array[MOVES] of var bool: occur; 9 | 10 | constraint (sum(i in MOVES)(duration[i] * bool2int(occur[i]))) <= timeBound; 11 | 12 | solve maximize sum(i in MOVES)(power[i] * bool2int(occur[i])); 13 | 14 | output [show(occur)]; -------------------------------------------------------------------------------- /sets/yellowturban/yellow01Set.mzn: -------------------------------------------------------------------------------- 1 | % Oath at the Peach Garden as a knapsack problem. 2 | 3 | int: nMoves; 4 | set of int: MOVES = 1..nMoves; 5 | int: timeBound; 6 | array[MOVES] of 1..20: power; 7 | array[MOVES] of 1..10: duration; 8 | var set of MOVES: occur; 9 | 10 | constraint (sum(i in MOVES)(duration[i] * bool2int(i in occur))) <= timeBound; 11 | 12 | solve maximize sum(i in MOVES)(power[i] * bool2int(i in occur)); 13 | 14 | output [show(occur)]; -------------------------------------------------------------------------------- /sets/yellowturban/yellow01SetConcise.mzn: -------------------------------------------------------------------------------- 1 | % Oath at the Peach Garden as a knapsack problem. 2 | 3 | int: nMoves; 4 | set of int: MOVES = 1..nMoves; 5 | int: timeBound; 6 | array[MOVES] of 1..20: power; 7 | array[MOVES] of 1..10: duration; 8 | var set of MOVES: occur; 9 | 10 | constraint (sum(i in occur)(duration[i])) <= timeBound; 11 | 12 | solve maximize sum(i in occur)(power[i]); 13 | 14 | output [show(occur)]; -------------------------------------------------------------------------------- /symmetry/crossbow/crossbow-lex.mzn: -------------------------------------------------------------------------------- 1 | int: n; 2 | set of int: N = 1..n; 3 | array[N,N] of var bool: t; 4 | constraint sum(i,j in N)(t[i,j]) = n; 5 | solve satisfy; 6 | 7 | % no two traps on the same row 8 | constraint forall(i in N)(sum(j in N)(t[i,j]) <= 1); 9 | % no two traps on the same column 10 | constraint forall(j in N)(sum(i in N)(t[i,j]) <= 1); 11 | % no two traps on same diagonal 12 | constraint forall(k in 1-n..n-1) 13 | (sum(i,j in N where i-j=k)(t[i,j])<= 1); 14 | constraint forall(k in 2..2*n) 15 | (sum(i,j in N where i+j=k)(t[i,j])<= 1); 16 | 17 | include "lex_lesseq.mzn"; 18 | 19 | % solution lex less than r90 version 20 | constraint let { array[N,N] of var bool: s; } in 21 | forall(i,j in N)(s[i,j] = t[j,n+1-i]) /\ 22 | lex_lesseq(array1d(t), array1d(s)); 23 | 24 | % solution lex less than r180 version 25 | constraint let { array[N,N] of var bool: s; } in 26 | forall(i,j in N)(s[i,j] = t[n+1-i,n+1-j]) /\ 27 | lex_lesseq(array1d(t), array1d(s)); 28 | 29 | % solution lex less than 270 version 30 | constraint let { array[N,N] of var bool: s; } in 31 | forall(i,j in N)(s[i,j] = t[n+1-j,i]) /\ 32 | lex_lesseq(array1d(t), array1d(s)); 33 | 34 | % solution lex less than x flip version 35 | constraint let { array[N,N] of var bool: s; } in 36 | forall(i,j in N)(s[i,j] = t[n+1-i,j]) /\ 37 | lex_lesseq(array1d(t), array1d(s)); 38 | 39 | % solution lex less than y flip version 40 | constraint let { array[N,N] of var bool: s; } in 41 | forall(i,j in N)(s[i,j] = t[i,n+1-j]) /\ 42 | lex_lesseq(array1d(t), array1d(s)); 43 | 44 | % solution lex less than d2 flip version 45 | constraint let { array[N,N] of var bool: s; } in 46 | forall(i,j in N)(s[i,j] = t[n+1-j,n+1-i]) /\ 47 | lex_lesseq(array1d(t), array1d(s)); 48 | 49 | % solution lex less than d1 flip version 50 | constraint let { array[N,N] of var bool: s; } in 51 | forall(i,j in N)(s[i,j] = t[j,i]) /\ 52 | lex_lesseq(array1d(t), array1d(s)); 53 | 54 | 55 | 56 | output [ if fix(t[i,j]) then "T" else "." endif ++ 57 | if j = n then "\n" else "" endif 58 | | i,j in N]; -------------------------------------------------------------------------------- /symmetry/crossbow/crossbow-lib.mzn: -------------------------------------------------------------------------------- 1 | int: n; 2 | set of int: N = 1..n; 3 | array[N,N] of var bool: t; 4 | constraint sum(i,j in N)(t[i,j]) = n; 5 | solve satisfy; 6 | 7 | % no two traps on the same row 8 | constraint forall(i in N)(sum(j in N)(t[i,j]) <= 1); 9 | % no two traps on the same column 10 | constraint forall(j in N)(sum(i in N)(t[i,j]) <= 1); 11 | % no two traps on same diagonal 12 | constraint forall(k in 1-n..n-1) 13 | (sum(i,j in N where i-j=k)(t[i,j])<= 1); 14 | constraint forall(k in 2..2*n) 15 | (sum(i,j in N where i+j=k)(t[i,j])<= 1); 16 | 17 | %include "rot_flip_sqr_sym.mzn"; 18 | include "symmetry.mzn"; 19 | include "lex_lesseq.mzn"; 20 | 21 | constraint rot_flip_sqr_sym(t); 22 | 23 | output [ if fix(t[i,j]) then "T" else "." endif ++ 24 | if j = n then "\n" else "" endif 25 | | i,j in N]; -------------------------------------------------------------------------------- /symmetry/crossbow/crossbow.mzn: -------------------------------------------------------------------------------- 1 | int: n; 2 | set of int: N = 1..n; 3 | array[N,N] of var bool: t; 4 | constraint sum(i,j in N)(t[i,j]) = n; 5 | solve satisfy; 6 | 7 | % no two traps on the same row 8 | constraint forall(i in N)(sum(j in N)(t[i,j]) <= 1); 9 | % no two traps on the same column 10 | constraint forall(j in N)(sum(i in N)(t[i,j]) <= 1); 11 | % no two traps on same diagonal 12 | constraint forall(k in 1-n..n-1) 13 | (sum(i,j in N where i-j=k)(t[i,j])<= 1); 14 | constraint forall(k in 2..2*n) 15 | (sum(i,j in N where i+j=k)(t[i,j])<= 1); 16 | 17 | 18 | output [ if fix(t[i,j]) then "T" else "." endif ++ 19 | if j = n then "\n" else "" endif 20 | | i,j in N]; -------------------------------------------------------------------------------- /symmetry/lamp/double_lex.mzn: -------------------------------------------------------------------------------- 1 | include "lex_lesseq.mzn"; 2 | 3 | predicate double_lex(array[int,int] of var int: x) = 4 | forall(i in index_set_1of2(x) where i != max(index_set_1of2(x))) 5 | (lex_lesseq([ x[i,j] | j in index_set_2of2(x) ], 6 | [ x[i+1,j] | j in index_set_2of2(x) ])) 7 | /\ 8 | forall(j in index_set_2of2(x) where j != max(index_set_2of2(x))) 9 | (lex_lesseq([ x[i,j] | i in index_set_1of2(x) ], 10 | [ x[i,j+1] | i in index_set_1of2(x) ])); 11 | -------------------------------------------------------------------------------- /symmetry/lamp/lamp-dl.mzn: -------------------------------------------------------------------------------- 1 | int: v; 2 | set of int: ROW = 1..v; 3 | int: b; 4 | set of int: COL = 1..b; 5 | int: r; 6 | int: k; 7 | int: lambda; 8 | 9 | array[ROW,COL] of var bool: m; 10 | solve satisfy; 11 | 12 | constraint forall(i in ROW)(sum(j in COL)(m[i,j]) = r); 13 | constraint forall(j in COL)(sum(i in ROW)(m[i,j]) = k); 14 | constraint forall(i1, i2 in ROW where i1 < i2) 15 | (sum(j in COL) 16 | (m[i1,j] /\ m[i2,j]) = lambda); 17 | 18 | include "double_lex.mzn"; 19 | constraint double_lex(m); 20 | 21 | output [ if fix(m[i,j]) then "1" else "0" endif ++ 22 | if j = b then "\n" else "" endif 23 | | i in ROW, j in COL ]; -------------------------------------------------------------------------------- /symmetry/lamp/lamp-sym.mzn: -------------------------------------------------------------------------------- 1 | int: v; 2 | set of int: ROW = 1..v; 3 | int: b; 4 | set of int: COL = 1..b; 5 | int: r; 6 | int: k; 7 | int: lambda; 8 | 9 | array[ROW,COL] of var bool: m; 10 | %solve :: int_search([m[r,c] | r in ROW, c in COL], input_order, indomain_min, complete) satisfy; 11 | solve satisfy; 12 | 13 | constraint forall(i in ROW)(sum(j in COL)(m[i,j]) = r); 14 | constraint forall(j in COL)(sum(i in ROW)(m[i,j]) = k); 15 | constraint forall(i1, i2 in ROW where i1 < i2) 16 | (sum(j in COL) 17 | (m[i1,j] /\ m[i2,j]) = lambda); 18 | 19 | include "lex_lesseq.mzn"; 20 | constraint forall(i in 1..v-1) 21 | (lex_lesseq(row(m,i),row(m,i+1))); 22 | % (lex_lesseq([ m[i,j] | j in COL], 23 | % [ m[i+1,j] | j in COL])); 24 | constraint forall(j in 1..b-1) 25 | (lex_lesseq(col(m,j),col(m,j+1))); 26 | % (lex_lesseq([ m[i,j] | i in ROW], 27 | % [ m[i,j+1] | i in ROW])); 28 | 29 | output [ if fix(m[i,j]) then "1" else "0" endif ++ 30 | if j = b then "\n" else "" endif 31 | | i in ROW, j in COL ]; -------------------------------------------------------------------------------- /symmetry/lamp/lamp.dzn: -------------------------------------------------------------------------------- 1 | v = 7; 2 | b = 56; 3 | r = 24; 4 | k = 3; 5 | lambda = 8; -------------------------------------------------------------------------------- /symmetry/lamp/lamp.mzn: -------------------------------------------------------------------------------- 1 | int: v; 2 | set of int: ROW = 1..v; 3 | int: b; 4 | set of int: COL = 1..b; 5 | int: r; 6 | int: k; 7 | int: lambda; 8 | 9 | array[ROW,COL] of var bool: m; 10 | %solve :: int_search([m[r,c] | r in ROW, c in COL], input_order, indomain_min, complete) satisfy; 11 | solve satisfy; 12 | 13 | constraint forall(i in ROW)(sum(j in COL)(m[i,j]) = r); 14 | constraint forall(j in COL)(sum(i in ROW)(m[i,j]) = k); 15 | constraint forall(i1, i2 in ROW where i1 < i2) 16 | (sum(j in COL) 17 | (m[i1,j] /\ m[i2,j]) = lambda); 18 | 19 | 20 | output [ if fix(m[i,j]) then "1" else "0" endif ++ 21 | if j = b then "\n" else "" endif 22 | | i in ROW, j in COL ]; 23 | 24 | 25 | %110111 <= 011111 -------------------------------------------------------------------------------- /symmetry/road/road.dzn: -------------------------------------------------------------------------------- 1 | n = 14; 2 | coop=array2d(1..n, 1..n, 3 | [0, 15, 3, 13, 4, 1, 5, 4, 4, 1, 1, 11, 10, 1, 4 | 15, 0, 3, 13, 4, 11, 10, 9, 11, 7, 1, 5, 4, 1, 5 | 3, 3, 0, 13, 4, 11, 10, 9, 10, 7, 1, 5, 4, 1, 6 | 13, 13, 13, 0, 4, 11, 10, 9, 9, 7, 1, 5, 4, 1, 7 | 4, 4, 4, 4, 0, 1, 5, 4, 8, 1, 1, 11, 10, 1, 8 | 1, 11, 11, 11, 1, 0, 10, 9, 7, 7, 1, 5, 4, 1, 9 | 5, 10, 10, 10, 5, 10, 0, 9, 8, 7, 1, 5, 4, 1, 10 | 4, 9, 9, 9, 4, 9, 9, 0, 8, 7, 1, 5, 4, 1, 11 | 4, 11, 10, 9, 10, 7, 8, 8, 0, 7, 1, 5, 4, 1, 12 | 1, 7, 7, 7, 1, 7, 7, 7, 7, 0, 1, 5, 4, 1, 13 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 5, 4, 1, 14 | 11, 5, 5, 5, 11, 5, 5, 5, 5, 5, 5, 0, 4, 4, 15 | 10, 4, 4, 4, 10, 4, 4, 4, 4, 4, 4, 4, 0, 3, 16 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 3, 0]); -------------------------------------------------------------------------------- /symmetry/road/road.mzn: -------------------------------------------------------------------------------- 1 | int: n; 2 | set of int: GEN = 1..n; 3 | set of int: ROAD = 1..n; 4 | array[GEN,GEN] of int: coop; 5 | array[ROAD] of var GEN: road; 6 | 7 | include "alldifferent.mzn"; 8 | constraint alldifferent(road); 9 | 10 | constraint road[1] < road[n]; 11 | 12 | var int: scoop = sum(i in 1..n-1) 13 | (coop[road[i], road[i+1]]); 14 | solve maximize scoop; 15 | 16 | output["road = \(road)\nscoop = \(scoop)"]; -------------------------------------------------------------------------------- /symmetry/road/roaddom.mzn: -------------------------------------------------------------------------------- 1 | int: n; 2 | set of int: GEN = 1..n; 3 | set of int: ROAD = 1..n; 4 | array[GEN,GEN] of int: coop; 5 | array[ROAD] of var GEN: road; 6 | 7 | include "alldifferent.mzn"; 8 | constraint alldifferent(road); 9 | 10 | constraint road[1] < road[n]; 11 | 12 | var int: scoop = sum(i in 1..n-1) 13 | (coop[road[i], road[i+1]]); 14 | solve maximize scoop; 15 | 16 | output["road = \(road)\nscoop = \(scoop)"]; 17 | 18 | constraint forall(i in 2..n-2) 19 | (forall(j in i+1..n-1) 20 | (coop[road[i-1], road[i]] + 21 | coop[road[j], road[j+1]] 22 | >= 23 | coop[road[i-1], road[j]] + 24 | coop[road[i], road[j+1]] 25 | ) 26 | ); -------------------------------------------------------------------------------- /symmetry/square/var_perm_sym.mzn: -------------------------------------------------------------------------------- 1 | predicate var_perm_sym(array[int] of var int: x, 2 | array[int,int] of int: p) = 3 | let { int: l = min(index_set_1of2(p)), 4 | int: u = max(index_set_1of2(p)), 5 | array[1..length(x)] of var int: 6 | y = [ x[i] | i in index_set(x) ] } 7 | in 8 | forall (i, j in l..u where i != j) ( 9 | var_perm_sym_pairwise(y, 10 | [ p[i,k] | k in index_set_2of2(p) ], 11 | [ p[j,k] | k in index_set_2of2(p) ]) 12 | ); 13 | 14 | predicate var_perm_sym_pairwise( 15 | array[int] of var int: x, 16 | array[int] of int: p1, 17 | array[int] of int: p2) = 18 | let { int: n = length(x), 19 | array[1..n] of 1..n: 20 | invp1 = [ j | i, j in 1..n 21 | where p1[j] = i ] } 22 | in 23 | lex_lesseq(x, [ x[p2[invp1[i]]] | i in 1..n ]); 24 | -------------------------------------------------------------------------------- /symmetry/square/var_sqr_sym.mzn: -------------------------------------------------------------------------------- 1 | include "var_perm_sym.mzn"; 2 | 3 | predicate 4 | var_sqr_sym(array[int,int] of var int: x) = 5 | let { int: n = card(index_set_1of2(x)); 6 | int: n2 = card(index_set_2of2(x)); 7 | constraint assert(n = n2,"square symmetry applied to non-square array"); 8 | int: l = n * n; 9 | array[1..l] of var int: 10 | y = [ x[i,j] | i in index_set_1of2(x), 11 | j in index_set_2of2(x) ]; 12 | array[1..8,1..l] of 1..l: 13 | p = array2d(1..8,1..l, 14 | [ if k == 1 then i*n + j - n 15 | elseif k == 2 then (n - j)*n + i % r270 16 | elseif k == 3 then (n - i)*n + (n - j)+1 % r180 17 | elseif k == 4 then (j*n - n) + (n - i + 1) % r90 18 | elseif k == 5 then (n - i)*n + j % x flip 19 | elseif k == 6 then (i*n - n) + (n - j + 1) % y flip 20 | elseif k == 7 then (n - j)*n + (n - i + 1) % d2 flip 21 | else (j*n - n) + i % d1 flip 22 | endif 23 | | k in 1..8, i,j in 1..n]) } 24 | in 25 | var_perm_sym(y,p); -------------------------------------------------------------------------------- /symmetry/wind/wind.dzn: -------------------------------------------------------------------------------- 1 | n = 6; 2 | m = 3; 3 | 4 | TRIBUTE = {LETTUCE, TURNIP, CARROT, % rank 1 5 | BANANA, PEACH, GRAPE, % rank 2 6 | SNAKE, CHICKEN, FISHHEAD, % rank 3 7 | RICEWINE, GAOLIANG, GRAPEWINE, % rank 4 8 | GOLD, SILVER, BRONZE, % rank 5 9 | GREEN, RED, BLUE % rank 6 10 | }; -------------------------------------------------------------------------------- /symmetry/wind/wind.mzn: -------------------------------------------------------------------------------- 1 | % matching problem 2 | 3 | include "globals.mzn"; 4 | 5 | int: n; 6 | set of int: VERTEX = 1..n; 7 | set of int: RANK = 1..n; 8 | int: m; 9 | set of int: POLYGON = 1..m; 10 | 11 | enum TRIBUTE; 12 | array[TRIBUTE] of RANK: rank = [(i-1) div m + 1 | i in 1..n*m]; 13 | 14 | array[POLYGON, VERTEX] of var TRIBUTE: tribute; 15 | array[1..m-1, VERTEX] of var 0..n-1: ncoins; 16 | 17 | 18 | constraint all_different (array1d(tribute)); 19 | 20 | constraint forall (i in 1..m-1)( 21 | forall (j in VERTEX)( 22 | ncoins[i,j] = 23 | abs(rank[tribute[i,j]] - 24 | rank[tribute[i+1,j]]) 25 | ) 26 | ); 27 | 28 | var int: tcoins = sum(i in 1..m-1, j in VERTEX) 29 | (ncoins[i,j]); 30 | solve maximize tcoins; 31 | 32 | output [ "tributes: \n"] ++ [( if j > n then "\n" else show(tribute[i, j]) ++ "\t" endif ) 33 | | i in 1..m, j in 1..(n + 1) 34 | ] ++ 35 | [ "coins: \n"] ++ [( if j > n then "\n" else show(ncoins[i, j]) ++ "\t" endif ) 36 | | i in 1..m-1, j in 1..(n + 1) 37 | ] ++ 38 | ["matching: (m = ", show(m), ", n = ", show(n), ", tcoins = ", show(tcoins), ")\n"]; 39 | 40 | % variable symmetry breaking 41 | %constraint forall(j in 1..n-1)( 42 | % lex_lesseq([tribute[i,j] | i in POLYGON], 43 | % [tribute[i,j+1] | i in POLYGON]) 44 | % ); 45 | 46 | %constraint lex_lesseq([tribute[i,j] | i in 1..round(m div 2), j in VERTEX], [tribute[m+1-i,j] | i in 1..round(m div 2), j in VERTEX]); 47 | constraint forall(j in 1..n-1) 48 | (tribute[1,j] < tribute[1,j+1]); 49 | constraint tribute[1,1] < tribute[m,1]; -------------------------------------------------------------------------------- /symmetry/wind/windchanvar.mzn: -------------------------------------------------------------------------------- 1 | % matching problem 2 | 3 | include "globals.mzn"; 4 | 5 | int: n; 6 | set of int: VERTEX = 1..n; 7 | set of int: RANK = 1..n; 8 | int: m; 9 | set of int: POLYGON = 1..m; 10 | 11 | enum TRIBUTE; 12 | array[TRIBUTE] of RANK: rank = [(i-1) div m + 1 | i in 1..n*m]; 13 | 14 | array[POLYGON, VERTEX] of var TRIBUTE: tribute; 15 | array[1..m-1, VERTEX] of var 0..n-1: ncoins; 16 | 17 | 18 | constraint all_different (array1d(tribute)); 19 | 20 | constraint forall (i in 1..m-1)( 21 | forall (j in VERTEX)( 22 | ncoins[i,j] = 23 | abs(rank[tribute[i,j]] - 24 | rank[tribute[i+1,j]]) 25 | ) 26 | ); 27 | 28 | var int: tcoins = sum(i in 1..m-1, j in VERTEX) 29 | (ncoins[i,j]); 30 | solve maximize tcoins; 31 | 32 | output [ "tributes: \n"] ++ [( if j > n then "\n" else show(tribute[i, j]) ++ "\t" endif ) 33 | | i in 1..m, j in 1..(n + 1) 34 | ] ++ 35 | [ "coins: \n"] ++ [( if j > n then "\n" else show(ncoins[i, j]) ++ "\t" endif ) 36 | | i in 1..m-1, j in 1..(n + 1) 37 | ] ++ 38 | ["matching: (m = ", show(m), ", n = ", show(n), ", tcoins = ", show(tcoins), ")\n"]; 39 | 40 | % variable symmetry breaking 41 | %constraint forall(j in 1..n-1)( 42 | % lex_lesseq([tribute[i,j] | i in POLYGON], 43 | % [tribute[i,j+1] | i in POLYGON]) 44 | % ); 45 | 46 | %constraint lex_lesseq([tribute[i,j] | i in 1..round(m div 2), j in VERTEX], [tribute[m+1-i,j] | i in 1..round(m div 2), j in VERTEX]); 47 | constraint forall(j in 1..n-1) 48 | (tribute[1,j] < tribute[1,j+1]); 49 | constraint tribute[1,1] < tribute[m,1]; 50 | 51 | % value symmetry breaking by breaking variable 52 | % variable symmetry using channeling 53 | set of int: PVERTEX = 1..n*m; 54 | 55 | array[1..length(TRIBUTE)] of var PVERTEX: position; 56 | 57 | 58 | constraint inverse(array1d(tribute), position); 59 | 60 | constraint forall (i in RANK) ( 61 | forall (j in m*(i-1)+1..m*i-1) ( 62 | position[j] < position[j+1] 63 | ) 64 | ); -------------------------------------------------------------------------------- /symmetry/wind/windprec.mzn: -------------------------------------------------------------------------------- 1 | % matching problem 2 | 3 | include "globals.mzn"; 4 | 5 | int: n; 6 | set of int: VERTEX = 1..n; 7 | set of int: RANK = 1..n; 8 | int: m; 9 | set of int: POLYGON = 1..m; 10 | 11 | enum TRIBUTE; 12 | array[TRIBUTE] of RANK: rank = [(i-1) div m + 1 | i in 1..n*m]; 13 | 14 | array[POLYGON, VERTEX] of var TRIBUTE: tribute; 15 | array[1..m-1, VERTEX] of var 0..n-1: ncoins; 16 | 17 | 18 | constraint all_different(array1d(tribute)); 19 | 20 | constraint forall (i in 1..m-1)( 21 | forall (j in VERTEX)( 22 | ncoins[i,j] = 23 | abs(rank[tribute[i,j]] - 24 | rank[tribute[i+1,j]]) 25 | ) 26 | ); 27 | 28 | var int: tcoins = sum(i in 1..m-1, j in VERTEX) 29 | (ncoins[i,j]); 30 | solve maximize tcoins; 31 | 32 | output [ "tributes: \n"] ++ [( if j > n then "\n" else show(tribute[i, j]) ++ "\t" endif ) 33 | | i in 1..m, j in 1..(n + 1) 34 | ] ++ 35 | [ "coins: \n"] ++ [( if j > n then "\n" else show(ncoins[i, j]) ++ "\t" endif ) 36 | | i in 1..m-1, j in 1..(n + 1) 37 | ] ++ 38 | ["matching: (m = ", show(m), ", n = ", show(n), ", tcoins = ", show(tcoins), ")\n"]; 39 | 40 | 41 | 42 | % variable symmetry breaking 43 | %constraint forall(j in 1..n-1)( 44 | % lex_lesseq([tribute[i,j] | i in POLYGON], 45 | % [tribute[i,j+1] | i in POLYGON]) 46 | % ); 47 | 48 | %constraint lex_lesseq([tribute[i,j] | i in 1..round(m div 2), j in VERTEX], [tribute[m+1-i,j] | i in 1..round(m div 2), j in VERTEX]); 49 | constraint forall(j in 1..n-1) 50 | (tribute[1,j] < tribute[1,j+1]); 51 | constraint tribute[1,1] < tribute[m,1]; 52 | 53 | % value symmetry breaking 54 | constraint forall(r in RANK) 55 | (value_precede_chain([i | i in (r-1)*m+1..r*m], array1d(tribute))); -------------------------------------------------------------------------------- /workshops/composition_solution.mzn: -------------------------------------------------------------------------------- 1 | % composition problem 2 | int: n; 3 | set of int: NOTE = 1..n; 4 | set of int: POSN = 1..n; 5 | set of int: DIFF = 1..n-1; 6 | set of int: PDIFF = 1..n-1; 7 | 8 | array[POSN] of var NOTE: order; 9 | array[PDIFF] of var DIFF: diffs; 10 | 11 | include "alldifferent.mzn"; 12 | constraint alldifferent(diffs); 13 | constraint alldifferent(order); 14 | 15 | constraint forall(i in PDIFF)(diffs[i] = abs(order[i] - order[i+1])); 16 | 17 | solve satisfy; 18 | 19 | output ["order = ",show(order),";\n"]; 20 | -------------------------------------------------------------------------------- /workshops/compositiondual_solution.mzn: -------------------------------------------------------------------------------- 1 | % composition problem 2 | int: n; 3 | set of int: NOTE = 1..n; 4 | set of int: POSN = 1..n; 5 | set of int: DIFF = 1..n-1; 6 | set of int: PDIFF = 1..n-1; 7 | 8 | array[NOTE] of var POSN: posn; 9 | array[POSN] of var NOTE: order; 10 | array[PDIFF] of var DIFF: diffs; 11 | array[DIFF] of var PDIFF: dposn; 12 | 13 | include "inverse.mzn"; 14 | constraint inverse(posn,order); 15 | 16 | constraint forall(i in DIFF)(diffs[i] = abs(order[i] - order[i+1])); 17 | 18 | constraint inverse(diffs,dposn); 19 | 20 | constraint abs(posn[1] - posn[n]) = 1; 21 | constraint dposn[n-1] = min(posn[1],posn[n]); 22 | 23 | solve satisfy; 24 | 25 | output ["order = ",show(order),";\n"] 26 | ++ ["diffs = ",show(diffs),";\n"] 27 | ++ ["posn = ",show(posn),";\n"] 28 | ++ ["dposn = ",show(dposn),";\n"]; 29 | 30 | -------------------------------------------------------------------------------- /workshops/feasttrap_solution.mzn: -------------------------------------------------------------------------------- 1 | % Beauty Trap 2 | % Create the most magnificient feast 3 | enum DISH; 4 | enum TASTE = {spicy, sour, salty, sweet, umame, bland}; 5 | enum TEMP = {hot, cold, warm}; 6 | %int: ndish; 7 | %set of int: DISH = 1..ndish; 8 | %set of int: TASTE = 1..6; 9 | %int: spicy = 1; int: sour = 2; int: salty = 3; int: sweet = 4; int: umame = 5; int: bland = 6; 10 | %set of int: TEMP = 1..3; 11 | %int: hot = 1; int: cold = 2; int: warm = 3; 12 | 13 | 14 | array[DISH] of TASTE: taste; 15 | array[DISH] of TEMP: temp; 16 | array[DISH] of bool: heavy; 17 | array[DISH] of int: value; 18 | 19 | int: len; % length of banquet 20 | set of int: COURSE = 1..len; 21 | 22 | array[COURSE] of var DISH: dish; 23 | 24 | include "alldifferent.mzn"; 25 | constraint alldifferent(dish); 26 | 27 | %constraint taste[dish[1]] = salty; 28 | %constraint taste[dish[len]] = sweet; 29 | %constraint forall(c in 1..len-1) 30 | % ((taste[dish[c]] = spicy -> (taste[dish[c+1]] in {bland, sweet})) /\ 31 | % (taste[dish[c]] = sour -> (taste[dish[c+1]] in {bland, umame})) /\ 32 | % (taste[dish[c]] = sweet -> (taste[dish[c+1]] in {spicy, sour, bland}))); 33 | %constraint forall(c in 1..len-1) 34 | % (taste[dish[c]] != taste[dish[c+1]]); 35 | 36 | include "regular.mzn"; 37 | constraint regular([taste[dish[c]] | c in COURSE], 7, card(TASTE), d, 1, {5}); 38 | array[1..7,TASTE] of 0..7: d = 39 | [| 0,0,4,0,0,0 40 | | 0,0,0,5,0,7 41 | | 0,0,0,0,6,7 42 | | 2,3,0,5,6,7 43 | | 0,3,4,0,0,7 44 | | 2,3,4,5,0,7 45 | | 2,3,4,5,6,0 |]; 46 | 47 | 48 | 49 | % a warm dish between any hot dish and later cold dish 50 | 51 | % -- Inititial formulation: 52 | %constraint forall(c in 1..len-1) 53 | % (temp[dish[c]] = hot -> 54 | % forall(c1 in c+1..len) 55 | % (temp[dish[c1]] = cold -> 56 | % exists(c2 in c+1..c1-1)(temp[dish[c2]] = warm))); 57 | 58 | % -- Formulation using regular: 59 | % constraint regular([temp[dish[c]] | c in COURSE], 3, card(TEMP), e, 2, 1..3); 60 | % array[1..3,TEMP] of 0..3: e = 61 | % [| 1,0,3 62 | % | 1,2,3 63 | % | 1,2,3 |]; 64 | 65 | % -- The best formulation: 66 | constraint forall(c in 1..len-1)(temp[dish[i]] = hot -> temp[dish[i+1]] != cold); 67 | % Note that this formulation is not mentioned in the video, but directly 68 | % follows from the automaton. This formulation is just as powerful as the 69 | % regular constraint, but is a lot simpler for the solver. 70 | 71 | 72 | % no more than two heavy dishes in a rows 73 | constraint forall(c in 1..len-2) 74 | (heavy[dish[c]] /\ heavy[dish[c+1]] -> not heavy[dish[c+2]]); 75 | % include "sliding_sum.mzn"; 76 | % constraint sliding_sum([ heavy[dish[c]] | c in COURSE], 0, 2, 3); 77 | 78 | 79 | var int: obj = sum(c in COURSE)(value[dish[c]]) + 80 | (len - 1) + 81 | sum(c in 1..len-1)(temp[dish[c]] != temp[dish[c+1]]) + 82 | sum(c in 1..len-1)(heavy[dish[c]] != heavy[dish[c+1]]); 83 | 84 | solve maximize obj; 85 | 86 | output ["dish = \(dish);\nobj = \(obj);\n"]; 87 | 88 | -------------------------------------------------------------------------------- /workshops/plasters_solution_dominance.mzn: -------------------------------------------------------------------------------- 1 | 2 | int: length; % length of Huang Gai's back 3 | set of int: LENGTH = 1..length; 4 | int: width; % width of Huang Gai's back 5 | set of int: WIDTH = 1..width; 6 | 7 | array[LENGTH,WIDTH] of bool: wound; % wound positions 8 | int: total_wounds = sum(array1d(wound)); 9 | 10 | int: ntypes; % number of types of plaster 11 | set of int: TYPE = 1..ntypes; 12 | array[TYPE] of int: number; % number of plaster available 13 | array[TYPE,1..2] of int: dim; % dimensions of plaster 14 | int: maxdim = max(array1d(dim)); 15 | array[TYPE] of int: price; 16 | 17 | int: total = sum(number); 18 | set of int: PLASTER = 1..total; 19 | array[TYPE] of int: psum = [ sum(i in 1..t-1)(number[i]) | t in TYPE ]; 20 | array[PLASTER] of TYPE: t = [max(t in TYPE)(t*(p > psum[t])) | p in PLASTER]; 21 | array[PLASTER] of var LENGTH: x; 22 | array[PLASTER] of var WIDTH: y; 23 | enum USAGE = { Long, Wide, Not }; 24 | array[PLASTER] of var USAGE: u; 25 | array[TYPE] of var 0..max(number): used; 26 | 27 | var TYPE: dominated; 28 | 29 | include "lex_lesseq.mzn"; 30 | % symmetry 31 | constraint forall(p in 1..total-1 where t[p] = t[p+1]) 32 | (lex_lesseq([ u[p], x[p], y[p] ], [u[p+1], x[p+1], y[p+1] ])); 33 | % unused symmetry 34 | constraint forall(p in PLASTER)(u[p] = Not -> x[p] = 1 /\ y[p] = 1); 35 | 36 | % used variables 37 | constraint forall(ty in TYPE) 38 | (used[ty] = sum(p in PLASTER where t[p] = ty)(u[p] != Not)); 39 | 40 | constraint sum(ty in TYPE)(used[ty]*dim[ty,1]*dim[ty,2]) = dim[dominated,1] * dim[dominated,2]; 41 | 42 | % dont rotate square plasters 43 | constraint forall(p in PLASTER)(if dim[t[p],1] = dim[t[p],2] then u[p] != Wide else true endif); 44 | 45 | include "diffn.mzn"; 46 | 47 | array[PLASTER] of var 0..maxdim: len = [ [dim[t[p],1], dim[t[p],2], 0][u[p]] | p in PLASTER ]; 48 | array[PLASTER] of var 0..maxdim: wid = [ [dim[t[p],2], dim[t[p],1], 0][u[p]] | p in PLASTER ]; 49 | 50 | constraint diffn(x,y,len,wid); 51 | 52 | constraint forall(p in PLASTER)(x[p] + len[p] -1 <= dim[dominated,1] /\ y[p] + wid[p] -1 <= dim[dominated,2]); 53 | 54 | var int: cost = sum(t in TYPE)(used[t] * price[t]); 55 | 56 | constraint cost < price[dominated]; 57 | 58 | solve satisfy; 59 | 60 | output %["x = \(x);\ny = \(y);\nu = \(u);\ncost = \(cost);\nused = \(used);\ndominated = \(dominated);\n"] 61 | %++ 62 | ["constraint used[\(dominated)] >= 1 -> " ++ 63 | "exists(t in TYPE where \(used)[t] >= 1)(number[t] - used[t] < \(used)[t]);"] 64 | ; 65 | -------------------------------------------------------------------------------- /workshops/poetry_solution.mzn: -------------------------------------------------------------------------------- 1 | % poetry 2 | % place k stanzas of E type and l stanzas of S type and m stanzas of O type 3 | % in order such that 4 | % no two stanzas of E or S are adjacent 5 | % maximize the sum of differences in effectivenesss of 6 | % adjacent stanzas of types E and S 7 | int: k; 8 | int: l; 9 | int: m; 10 | set of int: ESSTANZA = 1..k+l; 11 | int: other = 0; 12 | set of int: STANZA = 0..k+l; % other stanzas are not important 13 | 14 | enum KIND = { E, S, O }; 15 | array[ESSTANZA] of KIND: kind = [ E | i in 1..k ] ++ [ S | i in 1..l ]; 16 | 17 | array[ESSTANZA] of int: effect; 18 | 19 | int: n = k+l+m; 20 | set of int: POSN = 1..n; 21 | 22 | array[ESSTANZA] of var POSN: place; % place of each E and S stanza 23 | array[POSN] of var STANZA: what; % what is in each posn, 0 = other stanza 24 | 25 | % symmetry breaking: This constraint is guaranteed to be correct 26 | % Make sure and E or S stanza is in the first position, 27 | % If there are two other stanzas in a row this has to happen at the end. 28 | constraint what[1] != other /\ 29 | forall(i in 1..n-1) 30 | (what[i] = other /\ what[i+1] = other 31 | -> forall(j in i..n)(what[j] = other)); 32 | 33 | output ["obj = \(obj);\nwhat = \(what);\nplace = \(place);\n"]; 34 | 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ALL MODELLING ERRORS ARE BELOW THIS LINE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 36 | 37 | constraint forall(i in ESSTANZA, j in POSN)(place[i] = j <-> what[j] = i); 38 | 39 | include "alldifferent.mzn"; 40 | constraint alldifferent(place); 41 | 42 | constraint forall(p1, p2 in ESSTANZA where p1 < p2) 43 | (kind[p1] = kind[p2] -> abs(place[p1] - place[p2]) > 1); 44 | 45 | var int: obj = sum(p in 1..n-1) 46 | (if what[p] != other /\ what[p+1] != other 47 | then abs(effect[what[p]] - effect[what[p+1]]) 48 | else 0 endif); 49 | 50 | solve maximize obj; 51 | -------------------------------------------------------------------------------- /workshops/surrender_solution.mzn: -------------------------------------------------------------------------------- 1 | % workshop 2 2 | % select a set of trade negotiation party 3 | enum NEGOTIATOR; 4 | NEGOTIATOR: dummy; 5 | 6 | int: l; % minimum party size 7 | int: u; % maximum party size 8 | int: m; % minimum joint ability 9 | 10 | array[NEGOTIATOR] of int: honor; 11 | array[NEGOTIATOR,NEGOTIATOR] of int: joint; 12 | 13 | array[1..u] of var NEGOTIATOR: party; 14 | 15 | 16 | constraint forall(i in 1..l)(party[i] > dummy); 17 | 18 | constraint forall(i in 1..u-1)(party[i] >= party[i+1] + (party[i+1] != dummy)); 19 | 20 | constraint sum(i,j in 1..u where i < j)(joint[party[i],party[j]]) >= m; 21 | 22 | solve maximize obj; 23 | 24 | var int: obj; 25 | constraint obj = (min(j in 1..u)((party[j] = dummy)*max(honor) + honor[party[j]])); 26 | 27 | output ["party = "] ++ 28 | ["{"] ++ [ if fix(party[j]) != dummy then 29 | show(party[j]) ++ if j == u \/ fix(party[j+1]) = dummy then "" else ", " endif 30 | else "" endif | j in 1..u ] ++ ["};\n"] ++ 31 | ["obj = \(obj);\n"]; -------------------------------------------------------------------------------- /workshops/surrender_solution_set.mzn: -------------------------------------------------------------------------------- 1 | % workshop 2 2 | % select a set of trade negotiation party 3 | enum NEGOTIATOR; 4 | NEGOTIATOR: dummy; 5 | 6 | int: l; % minimum party size 7 | int: u; % maximum party size 8 | int: m; % minimum joint ability 9 | 10 | array[NEGOTIATOR] of int: honor; 11 | array[NEGOTIATOR,NEGOTIATOR] of int: joint; 12 | 13 | var set of NEGOTIATOR: party; 14 | 15 | constraint card(party) >= l /\ card(party) <= u; 16 | 17 | constraint not (dummy in party); 18 | 19 | constraint sum(i,j in party where i < j)(joint[i,j]) >= m; 20 | 21 | solve maximize obj; 22 | 23 | var int: obj; 24 | constraint obj = (min(j in party)(honor[j])); 25 | 26 | output ["party = \(party);\n"] ++ 27 | ["obj = \(obj);\n"]; 28 | -------------------------------------------------------------------------------- /workshops/temperature_solution.mzn: -------------------------------------------------------------------------------- 1 | int: start; 2 | array[int] of int: readings; 3 | int: n = length(readings); 4 | set of int: HOUR = 1..n; 5 | set of int: HOUR0 = 0..n; 6 | 7 | enum CHOICE = {heat, strongly_heat, cool, strongly_cool, do_nothing}; 8 | array[CHOICE] of int: cost = [1,5,3,9,0]; 9 | array[CHOICE] of int: effect = [1,4,-2,-5,0]; 10 | 11 | array[HOUR0] of var 25..30: temp; 12 | array[HOUR] of var CHOICE: choice; 13 | 14 | constraint temp[0] = start; 15 | 16 | constraint forall(h in HOUR) 17 | (temp[h] = (temp[h-1] + readings[h]) div 2 + effect[choice[h]]); 18 | 19 | solve minimize obj; 20 | 21 | var int: obj; 22 | constraint obj = sum(h in HOUR)(cost[choice[h]]); 23 | 24 | output ["temp = \(temp);\nchoice = \(choice);\ncost = \(obj);\n"]; 25 | 26 | 27 | -------------------------------------------------------------------------------- /workshops/visit_zhuge_solution.mzn: -------------------------------------------------------------------------------- 1 | enum PERSON; % set of people to be visited 2 | 3 | array[PERSON] of int: duration; % duration of visit 4 | array[PERSON] of bool: on_weekend; % can the person be visited over weekends 5 | array[PERSON] of int: rank; % rank of person 6 | 7 | array[int,1..2] of PERSON: prec; % precedences between visits 8 | set of int: PREC = index_set_1of2(prec); 9 | 10 | 0..6: starting_day; % which day of the week is day 0 in the schedule 11 | % 0 Monday, 1 Tuesday, ..., 5 Saturday, 6 Sunday 12 | 13 | % upper bound on the amount of time needed: total duration plus 1 week 14 | % per person who cant be visited on the weekend 15 | int: total = sum(duration) + 7*sum(p in PERSON)(on_weekend[p] = false); 16 | set of int: TIME = 0..total; 17 | 18 | array[PERSON] of var TIME: start; 19 | var TIME: end; 20 | 21 | constraint forall(p in PREC) 22 | (start[prec[p,1]] + duration[prec[p,1]] <= start[prec[p,2]]); 23 | 24 | include "disjunctive.mzn"; 25 | constraint disjunctive(start, duration); 26 | 27 | array[int] of var TIME: weekday = [ start[t] | t in PERSON where on_weekend[t] = false ]; 28 | array[int] of int: weekdur = [ duration[t] | t in PERSON where on_weekend[t] = false ]; 29 | 30 | array[int] of TIME: weekends = 31 | if starting_day = 6 then [ 1 ] else [] endif ++ 32 | [ t | t in TIME where (t + starting_day) mod 7 = 5 ]; 33 | array[int] of int: weekend_dur = 34 | if starting_day = 6 then [ 1 ] else [] endif ++ 35 | [ 2 | t in TIME where (t + starting_day) mod 7 = 5 ]; 36 | 37 | constraint disjunctive(weekday ++ weekends, weekdur ++ weekend_dur ); 38 | 39 | constraint forall(p in PERSON)(start[p] + duration[p] <= end); 40 | 41 | var int: rank_violation; 42 | constraint rank_violation = sum(p1,p2 in PERSON where rank[p1] < rank[p2])(start[p1] > start[p2]); 43 | 44 | solve minimize card(PERSON)*card(PERSON)*end + rank_violation; 45 | 46 | 47 | 48 | %output ["weekends = \(weekends);\n"]; 49 | 50 | %output [ show(p1) ++ " > " ++ show(p2) ++ "\n" 51 | % | p1, p2 in PERSON where rank[p1] > rank[p2] /\ fix(start[p1]) < fix(start[p2]) ]; 52 | --------------------------------------------------------------------------------