Download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
%
% 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
%
% Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/
%
% include "globals.mzn";
int: nbCars;
int: nbOptions;
int: nbSlots;
set of int: Cars = 1..nbCars;
set of int: Options = 1..nbOptions;
set of int: Slots = 1..nbSlots;
 
array[Cars] of int: demand;
 
array[Options,Cars] of int: option;
array[Options, 1..2] of int: capacity;
 
array[Options] of int: optionDemand = [sum(j in Cars) (demand[j] * option[i,j]) | i in Options];
 
% decision variables
 
array[Slots] of var Cars: slot;
array[Options, Slots] of var 0..1: setup;
 
 
var int: z = sum(s in Cars) (s*slot[s]);
 
solve minimize z;
% solve satisfy;
 
constraint
  forall(c in Cars ) (
    sum(s in Slots ) (bool2int(slot[s] = c)) = demand[c]
  )
  /\
  forall(o in Options, s in 1..nbSlots - capacity[o,2] + 1) (
    sum(j in s..s + capacity[o,2]- 1) (setup[o,j]) <= capacity[o,1]
  )
  /\
  forall(o in Options, s in Slots ) (
    setup[o,s] = option[o,slot[s]]
  )
  /\
  forall(o in Options, i in 1..optionDemand[o]) (
    sum(s in 1..(nbSlots - i * capacity[o,2])) (setup[o,s]) >=
           (optionDemand[o] - i * capacity[o,1])
  )
;
 
% 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
];
 
 
%
% data
%
 
% From OPL, car dat (smallest instance)
nbCars = 6;
nbOptions = 5;
nbSlots = 10;
demand = [1, 1, 2, 2, 2, 2];
option =
  array2d(Options,Cars,
    [
        1, 0, 0, 0, 1, 1,
        0, 0, 1, 1, 0, 1,
        1, 0, 0, 0, 1, 0,
        1, 1, 0, 1, 0, 0,
        0, 0, 1, 0, 0, 0
    ]);
capacity =
  array2d(Options, 1..2,
   [
        1,2,
        2,3,
        1,3,
        2,5,
        1,5
    ]);