| 1 |
/*** |
| 2 |
!Test |
| 3 |
expected: |
| 4 |
- !Result |
| 5 |
solution: !Solution |
| 6 |
obj: 224 |
| 7 |
objective: 224 |
| 8 |
x: |
| 9 |
- [0, 0, 0, 1, 0, 0] |
| 10 |
- [1, 0, 1, 0, 1, 1] |
| 11 |
- [0, 1, 0, 0, 1, 0] |
| 12 |
- [1, 0, 0, 0, 0, 1] |
| 13 |
- !Result |
| 14 |
solution: !Solution |
| 15 |
obj: 224 |
| 16 |
objective: 224 |
| 17 |
x: |
| 18 |
- [0, 0, 0, 1, 0, 0] |
| 19 |
- [0, 1, 1, 0, 1, 1] |
| 20 |
- [1, 0, 0, 0, 1, 0] |
| 21 |
- [1, 0, 0, 0, 0, 1] |
| 22 |
- !Result |
| 23 |
solution: !Solution |
| 24 |
obj: 224 |
| 25 |
objective: 224 |
| 26 |
x: |
| 27 |
- [0, 0, 0, 1, 0, 0] |
| 28 |
- [1, 1, 0, 0, 1, 1] |
| 29 |
- [0, 0, 1, 0, 0, 1] |
| 30 |
- [1, 0, 0, 0, 1, 0] |
| 31 |
- !Result |
| 32 |
solution: !Solution |
| 33 |
obj: 224 |
| 34 |
objective: 224 |
| 35 |
x: |
| 36 |
- [0, 0, 0, 1, 0, 0] |
| 37 |
- [1, 0, 1, 0, 1, 1] |
| 38 |
- [1, 0, 0, 0, 1, 0] |
| 39 |
- [0, 1, 0, 0, 0, 1] |
| 40 |
***/ |
| 41 |
|
| 42 |
%------------------------------------------------------------------------------% |
| 43 |
% trucking.mzn |
| 44 |
% Jakob Puchinger |
| 45 |
% December 2007 |
| 46 |
% vim: ft=zinc ts=4 sw=4 et tw=0 |
| 47 |
% Original model comes from Peters Student Tim |
| 48 |
% There are N Trucks which have to can be used in every time period, |
| 49 |
% Each truck can transport a given Load of material. |
| 50 |
% Each truck has an associated cost. |
| 51 |
% In each time period a demand has to be fulfilled. |
| 52 |
% Truck1 and Truck2 have some further constraints, disallowing |
| 53 |
% them to be used more than once in consecutive or two consecutive time periods. |
| 54 |
% The goal is to minimise the cost |
| 55 |
%------------------------------------------------------------------------------% |
| 56 |
|
| 57 |
% Time Periods |
| 58 |
int: T; |
| 59 |
% Trucks |
| 60 |
int: N; |
| 61 |
|
| 62 |
1..N: Truck1; |
| 63 |
1..N: Truck2; |
| 64 |
|
| 65 |
array[1..T] of int: Demand; |
| 66 |
array[1..N] of int: Cost; |
| 67 |
array[1..N] of int: Loads; |
| 68 |
|
| 69 |
array[1..N, 1..T] of var 0..1: x; |
| 70 |
|
| 71 |
constraint |
| 72 |
forall(t in 1..T)( |
| 73 |
sum(i in 1..N)( Loads[i] * x[i,t]) >= Demand[t] |
| 74 |
); |
| 75 |
|
| 76 |
constraint |
| 77 |
forall(tau in 1..T-2)( |
| 78 |
sum(t in tau..tau+2)( x[Truck1, t] ) <= 1 |
| 79 |
); |
| 80 |
|
| 81 |
constraint |
| 82 |
forall(tau in 1..T-1)( |
| 83 |
sum(t in tau..tau+1)( x[Truck2, t] ) <= 1 |
| 84 |
); |
| 85 |
|
| 86 |
solve minimize |
| 87 |
sum(i in 1..N)(sum(t in 1..T )( Cost[i] * x[i,t] )); |
| 88 |
|
| 89 |
% required for showing the objective function |
| 90 |
var int: obj; |
| 91 |
constraint |
| 92 |
obj = sum(i in 1..N)(sum(t in 1..T )( Cost[i] * x[i,t] )); |
| 93 |
|
| 94 |
output |
| 95 |
[ "Cost = ", show( obj ), "\n" ] ++ |
| 96 |
[ "X = \n\t" ] ++ |
| 97 |
[ show(x[i, t]) ++ if t = T then "\n\t" else " " endif | |
| 98 |
i in 1..N, t in 1..T ] ++ |
| 99 |
[ "\n" ]; |
| 100 |
|
| 101 |
%------------------------------------------------------------------------------% |
| 102 |
% Data |
| 103 |
|
| 104 |
T = 6; |
| 105 |
N = 4; |
| 106 |
Cost = [30, 27, 23, 20]; |
| 107 |
Loads = [20, 18, 15, 13]; |
| 108 |
Demand = [27, 11, 14, 19, 25, 22]; |
| 109 |
Truck1 = 3; |
| 110 |
Truck2 = 4; |