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
102
103
104
105
106
107
/*
 
  Car sequencing in Comet.
 
  This is based on the OPL3 model car.mod.
 
  This Comet model was created by Hakan Kjellerstrand (hakank@bonetmail.com)
  Also, see my Comet page: http://www.hakank.org/comet
 
 */
 
// Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/
 
import cotfd;
 
int t0 = System.getCPUTime();
 
int nbCars = 6;
int nbOptions = 5;
int nbSlots = 10;
range Cars = 1..nbCars;
range Options = 1..nbOptions;
range Slots = 1..nbSlots;
 
int demand[Cars] = [1, 1, 2, 2, 2, 2];
 
 
int option[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]
 ];
 
 
tuple Tcapacity {
   int l;
   int u;
}
 
Tcapacity capacity[Options] =
[
 Tcapacity(1,2),
 Tcapacity(2,3),
 Tcapacity(1,3),
 Tcapacity(2,5),
 Tcapacity(1,5)
];
 
int optionDemand[i in Options] = sum(j in Cars) demand[j] * option[i,j];
 
cout << "optionDemand: " << optionDemand<< endl;
 
Solver<CP> m();
 
var<CP>{int} slot[Slots](m,Cars);
var<CP>{int} setup[Options,Slots](m,0..1);
 
Integer num_solutions(0);
 
// exploreall<m> {
minimize<m> sum(s in Cars) s*slot[s] subject to {
 
  forall(c in Cars )
    m.post(sum(s in Slots ) (slot[s] == c) == demand[c]);
 
  forall(o in Options, s in 1..nbSlots - capacity[o].u + 1)
    m.post(sum(j in s..s + capacity[o].u - 1) setup[o,j] <= capacity[o].l);
 
  forall(o in Options, s in Slots )
    m.post(setup[o,s] == option[o,slot[s]]);
 
  forall(o in Options, i in 1..optionDemand[o])
    m.post(sum(s in 1..(nbSlots - i * capacity[o].u)) setup[o,s] >=
           (optionDemand[o] - i * capacity[o].l));
 
 
} using {
       
  label(m);
 
  num_solutions := num_solutions + 1;
 
  cout << slot << endl;
  forall(o in Options) {
    cout << capacity[o].l << "/" << capacity[o].u << ": " ;
    forall(s in Slots) {
      cout << setup[o,s] << " ";
    }
  cout << endl;
  }
  cout << endl;
     
 
 
}
 
 
cout << "\nnum_solutions: " << num_solutions << endl;
     
int t1 = System.getCPUTime();
cout << "time:      " << (t1-t0) << endl;
cout << "#choices = " << m.getNChoice() << endl;
cout << "#fail    = " << m.getNFail() << endl;
cout << "#propag  = " << m.getNPropag() << endl;