| 1 |
/*** |
| 2 |
!Test |
| 3 |
expected: |
| 4 |
- !Result |
| 5 |
solution: !Solution |
| 6 |
Entry: |
| 7 |
- 62 |
| 8 |
- 4 |
| 9 |
- 18 |
| 10 |
- 47 |
| 11 |
Period: 25 |
| 12 |
Removal: |
| 13 |
- 0 |
| 14 |
- 14 |
| 15 |
- 43 |
| 16 |
- 57 |
| 17 |
objective: 25 |
| 18 |
***/ |
| 19 |
|
| 20 |
%------------------------------------------------------------------------------% |
| 21 |
% singHoist2.mzn |
| 22 |
% Peter Stuckey |
| 23 |
% September 30 2006 |
| 24 |
%------------------------------------------------------------------------------% |
| 25 |
%------------------------------------------------------------------------------% |
| 26 |
% singHoist2.zinc |
| 27 |
% Jakob Puchinger <[email protected]> |
| 28 |
% Wed Jun 21 |
| 29 |
%------------------------------------------------------------------------------% |
| 30 |
|
| 31 |
%------------------------------------------------------------------------------% |
| 32 |
% Minizinc model of one-hoist scheduling |
| 33 |
% |
| 34 |
% Robert Rodosek and Mark Wallace |
| 35 |
% A Generic Model and Hybrid Algorithm for Hoist Scheduling Problems |
| 36 |
% in Michael J. Maher and Jean-Francois Puget eds. |
| 37 |
% Principles and Practice of Constraint Programming - CP98, |
| 38 |
% Springer, Lecture Notes in Computer Science, volume 1520, 1998. |
| 39 |
|
| 40 |
|
| 41 |
%------------------------------------------------------------------------------% |
| 42 |
% constants |
| 43 |
|
| 44 |
int: NumTanks; |
| 45 |
int: NumJobs; |
| 46 |
array [0..NumTanks, 0..NumTanks] of int: Empty; |
| 47 |
array [0..NumTanks] of int: Full; |
| 48 |
array [1..NumTanks] of int: MinTime; |
| 49 |
array [1..NumTanks] of int: MaxTime; |
| 50 |
|
| 51 |
|
| 52 |
%------------------------------------------------------------------------------% |
| 53 |
% decision variables |
| 54 |
|
| 55 |
int: PerMax = sum([MaxTime[i] | i in 1..NumTanks]); |
| 56 |
|
| 57 |
array [0..NumTanks] of var 0..(NumJobs * PerMax): Entry; |
| 58 |
array [0..NumTanks] of var 0..(NumJobs * PerMax): Removal; |
| 59 |
var 0..PerMax : Period; |
| 60 |
|
| 61 |
%------------------------------------------------------------------------------% |
| 62 |
% model |
| 63 |
|
| 64 |
solve minimize Period; |
| 65 |
|
| 66 |
constraint |
| 67 |
forall (Tank in 0..NumTanks) ( |
| 68 |
Removal[Tank] + Full[Tank] = Entry[(Tank + 1) mod (NumTanks+1)] |
| 69 |
); |
| 70 |
|
| 71 |
constraint |
| 72 |
forall (Tank in 1..NumTanks) ( |
| 73 |
Entry[Tank] + MinTime[Tank] <= Removal[Tank] |
| 74 |
/\ Entry[Tank] + MaxTime[Tank] >= Removal[Tank] |
| 75 |
); |
| 76 |
|
| 77 |
constraint |
| 78 |
Removal[NumTanks] + Full[NumTanks] <= NumJobs * Period; |
| 79 |
|
| 80 |
% disjoint constraint |
| 81 |
constraint |
| 82 |
forall (T1 in 0..NumTanks-1, T2 in T1+1..NumTanks, K in 1..NumJobs-1) ( |
| 83 |
Entry[(T1 + 1) mod (NumTanks+1)] + |
| 84 |
Empty[(T1+1) mod (NumTanks+1), T2] + K * Period |
| 85 |
<= Removal[T2] |
| 86 |
\/ Entry[(T2 + 1) mod (NumTanks+1)] + |
| 87 |
Empty[(T2 + 1) mod (NumTanks+1), T1] |
| 88 |
<= Removal[T1] + K * Period |
| 89 |
); |
| 90 |
|
| 91 |
constraint |
| 92 |
Removal[0] = 0; |
| 93 |
|
| 94 |
%------------------------------------------------------------------------------% |
| 95 |
% Test case. |
| 96 |
|
| 97 |
NumTanks = 3; |
| 98 |
NumJobs = 3; |
| 99 |
Empty = array2d(0..NumTanks, 0..NumTanks, |
| 100 |
[ 0, 2, 3, 3, |
| 101 |
2, 0, 2, 3, |
| 102 |
3, 2, 0, 2, |
| 103 |
3, 3, 2, 0]); |
| 104 |
Full = array1d(0..NumTanks, [4, 4, 4, 5]); |
| 105 |
MinTime = [10, 25, 10]; |
| 106 |
MaxTime = [10, 25, 10]; |
| 107 |
constraint 0 <= Period /\ Period <= sum([MaxTime[i] | i in 1..NumTanks]); |
| 108 |
|
| 109 |
output [ |
| 110 |
"singHoist2:\n", |
| 111 |
"Period = ", show(Period), "\n", |
| 112 |
"Entry[] = [", |
| 113 |
show(Entry[0]), " ", |
| 114 |
show(Entry[1]), " ", |
| 115 |
show(Entry[2]), " ", |
| 116 |
show(Entry[3]), "]\n", |
| 117 |
"Removal[] = [", |
| 118 |
show(Removal[0]), " ", |
| 119 |
show(Removal[1]), " ", |
| 120 |
show(Removal[2]), " ", |
| 121 |
show(Removal[3]), "]\n" |
| 122 |
]; |