| 1 |
/*** |
| 2 |
!Test |
| 3 |
expected: |
| 4 |
- !Result |
| 5 |
solution: !Solution |
| 6 |
items: |
| 7 |
- [0, 0, 0] |
| 8 |
- [0, 0, 0] |
| 9 |
- [0, 0, 0] |
| 10 |
- [0, 0, 0] |
| 11 |
- [0, 0, 2] |
| 12 |
- [0, 2, 0] |
| 13 |
- [1, 0, 1] |
| 14 |
- [1, 0, 1] |
| 15 |
obj: 4 |
| 16 |
objective: 4 |
| 17 |
pieces: [0, 0, 0, 0, 1, 1, 1, 1] |
| 18 |
- !Result |
| 19 |
solution: !Solution |
| 20 |
items: |
| 21 |
- [0, 0, 3] |
| 22 |
- [0, 2, 0] |
| 23 |
- [1, 0, 1] |
| 24 |
- [1, 0, 1] |
| 25 |
- [0, 0, 0] |
| 26 |
- [0, 0, 0] |
| 27 |
- [0, 0, 0] |
| 28 |
- [0, 0, 0] |
| 29 |
obj: 4 |
| 30 |
objective: 4 |
| 31 |
pieces: [1, 1, 1, 1, 0, 0, 0, 0] |
| 32 |
***/ |
| 33 |
|
| 34 |
%------------------------------------------------------------------------------% |
| 35 |
% cutstock.mzn |
| 36 |
% Jakob Puchinger <[email protected]> |
| 37 |
% December 2007 |
| 38 |
% vim: ft=zinc ts=4 sw=4 et tw=0 |
| 39 |
% |
| 40 |
% The cutting stock problem: Kantorovitch formulation for colgen. |
| 41 |
% |
| 42 |
%------------------------------------------------------------------------------% |
| 43 |
|
| 44 |
int: L; % stock length |
| 45 |
int: K; % upper bound on number of stock pieces |
| 46 |
int: N; % number of stock pieces |
| 47 |
|
| 48 |
array[1..N] of int: i_length; |
| 49 |
array[1..N] of int: i_demand; |
| 50 |
|
| 51 |
array[1..K] of var 0..1: pieces; |
| 52 |
array[1..K, 1..N] of var int: items; |
| 53 |
|
| 54 |
constraint |
| 55 |
forall(k in 1..K, i in 1..N)( items[k,i] >=0 ); |
| 56 |
|
| 57 |
solve ::int_search(array1d(1..K*N,items)++pieces,input_order,indomain_min,complete) minimize |
| 58 |
sum([ pieces[k] | k in 1..K]); |
| 59 |
|
| 60 |
constraint |
| 61 |
forall(i in 1..N) |
| 62 |
( |
| 63 |
sum( [ items[k, i] | k in 1..K] ) >= i_demand[i] |
| 64 |
); |
| 65 |
|
| 66 |
constraint |
| 67 |
forall( k in 1..K ) ( |
| 68 |
sum(i in 1..N)( items[k,i] * i_length[i] ) <= pieces[k] * L |
| 69 |
); |
| 70 |
|
| 71 |
% required for showing the objective function |
| 72 |
var int: obj; |
| 73 |
constraint |
| 74 |
obj = sum([ pieces[k] | k in 1..K]); |
| 75 |
|
| 76 |
output |
| 77 |
[ "Cost = ", show( obj ), "\n" ] ++ |
| 78 |
[ "Pieces = \n\t" ] ++ [show(pieces)] ++ [ "\n" ] ++ |
| 79 |
[ "Items = \n\t" ] ++ |
| 80 |
[ show(items[k, i]) ++ if k = K then "\n\t" else " " endif | |
| 81 |
i in 1..N, k in 1..K ] ++ |
| 82 |
[ "\n" ]; |
| 83 |
|
| 84 |
|
| 85 |
% data: |
| 86 |
N = 3; |
| 87 |
K = sum(i_demand); |
| 88 |
L = 10; |
| 89 |
i_length = [7, 5, 3]; |
| 90 |
i_demand = [2, 2, 4]; |
| 91 |
|