1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | % % Car sequencing in MiniZinc. % % This is based on the OPL3 model car.mod. % % Compare with the Comet model % % % This MiniZinc model was created by Hakan Kjellerstrand, hakank@bonetmail.com % See also my MiniZinc page: http://www.hakank.org/minizinc % % Model modified to match CSPLib data format by Chris Mears. % % Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/ % % include "globals.mzn"; int : numclasses; int : numoptions; int : numcars; set of int : Classes = 1..numclasses; set of int : Options = 1..numoptions; set of int : Slots = 1..numcars; array [Classes] of int : numberPerClass; array [Classes,Options] of int : optionsRequired; array [Options] of int : windowSize; array [Options] of int : optMax; array [Options] of int : optionNumberPerClass = [ sum (j in Classes) (numberPerClass[j] * optionsRequired[j,i]) | i in Options]; % decision variables array [Slots] of var Classes: slot; array [Options, Slots] of var 0..1: setup; var int : z = sum (s in Classes) (s*slot[s]); % solve minimize z; solve :: int_search(slot, input_order, indomain_min, complete) satisfy ; constraint forall (c in Classes ) ( sum (s in Slots ) ( bool2int (slot[s] = c)) = numberPerClass[c] ) /\ forall (o in Options, s in 1..numcars - windowSize[o] + 1) ( sum (j in s..s + windowSize[o]- 1) (setup[o,j]) <= optMax[o] ) /\ forall (o in Options, s in Slots ) ( setup[o,s] = optionsRequired[slot[s],o] ) /\ forall (o in Options, i in 1..optionNumberPerClass[o]) ( sum (s in 1..(numcars - i * windowSize[o])) (setup[o,s]) >= (optionNumberPerClass[o] - i * optMax[o]) ) ; % for solve satisfy % constraint z = 82; output [ "z: " ++ show (z) ++ "\n" ++ "slot: " ++ show (slot) ++ "\n" ] ++ [ if j = 1 then "\n" else " " endif ++ show (setup[i,j]) | i in Options, j in Slots ]; |