alpar@1
|
1 |
/* min01ks.mod - finding minimal equivalent 0-1 knapsack inequality */
|
alpar@1
|
2 |
|
alpar@1
|
3 |
/* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
|
alpar@1
|
4 |
|
alpar@1
|
5 |
/* It is obvious that for a given 0-1 knapsack inequality
|
alpar@1
|
6 |
|
alpar@1
|
7 |
a[1] x[1] + ... + a[n] x[n] <= b, x[j] in {0, 1} (1)
|
alpar@1
|
8 |
|
alpar@1
|
9 |
there exist infinitely many equivalent inequalities with exactly the
|
alpar@1
|
10 |
same feasible solutions.
|
alpar@1
|
11 |
|
alpar@1
|
12 |
Given a[j]'s and b this model allows to find an inequality
|
alpar@1
|
13 |
|
alpar@1
|
14 |
alfa[1] x[1] + ... + alfa[n] x[n] <= beta, x[j] in {0, 1}, (2)
|
alpar@1
|
15 |
|
alpar@1
|
16 |
which is equivalent to (1) and where alfa[j]'s and beta are smallest
|
alpar@1
|
17 |
non-negative integers.
|
alpar@1
|
18 |
|
alpar@1
|
19 |
This model has the following formulation:
|
alpar@1
|
20 |
|
alpar@1
|
21 |
minimize
|
alpar@1
|
22 |
|
alpar@1
|
23 |
z = |alfa[1]| + ... + |alfa[n]| + |beta| = (3)
|
alpar@1
|
24 |
|
alpar@1
|
25 |
= alfa[1] + ... + alfa[n] + beta
|
alpar@1
|
26 |
|
alpar@1
|
27 |
subject to
|
alpar@1
|
28 |
|
alpar@1
|
29 |
alfa[1] x[1] + ... + alfa[n] x[n] <= beta (4)
|
alpar@1
|
30 |
|
alpar@1
|
31 |
for all x satisfying to (1)
|
alpar@1
|
32 |
|
alpar@1
|
33 |
alfa[1] x[1] + ... + alfa[n] x[n] >= beta + 1 (5)
|
alpar@1
|
34 |
|
alpar@1
|
35 |
for all x not satisfying to (1)
|
alpar@1
|
36 |
|
alpar@1
|
37 |
alfa[1], ..., alfa[n], beta are non-negative integers.
|
alpar@1
|
38 |
|
alpar@1
|
39 |
Note that this model has n+1 variables and 2^n constraints.
|
alpar@1
|
40 |
|
alpar@1
|
41 |
It is interesting, as noticed in [1] and explained in [2], that
|
alpar@1
|
42 |
in most cases LP relaxation of the MIP formulation above has integer
|
alpar@1
|
43 |
optimal solution.
|
alpar@1
|
44 |
|
alpar@1
|
45 |
References
|
alpar@1
|
46 |
|
alpar@1
|
47 |
1. G.H.Bradley, P.L.Hammer, L.Wolsey, "Coefficient Reduction for
|
alpar@1
|
48 |
Inequalities in 0-1 Variables", Math.Prog.7 (1974), 263-282.
|
alpar@1
|
49 |
|
alpar@1
|
50 |
2. G.J.Koehler, "A Study on Coefficient Reduction of Binary Knapsack
|
alpar@1
|
51 |
Inequalities", University of Florida, 2001. */
|
alpar@1
|
52 |
|
alpar@1
|
53 |
param n, integer, > 0;
|
alpar@1
|
54 |
/* number of variables in the knapsack inequality */
|
alpar@1
|
55 |
|
alpar@1
|
56 |
set N := 1..n;
|
alpar@1
|
57 |
/* set of knapsack items */
|
alpar@1
|
58 |
|
alpar@1
|
59 |
/* all binary n-vectors are numbered by 0, 1, ..., 2^n-1, where vector
|
alpar@1
|
60 |
0 is 00...00, vector 1 is 00...01, etc. */
|
alpar@1
|
61 |
|
alpar@1
|
62 |
set U := 0..2^n-1;
|
alpar@1
|
63 |
/* set of numbers of all binary n-vectors */
|
alpar@1
|
64 |
|
alpar@1
|
65 |
param x{i in U, j in N}, binary, := (i div 2^(j-1)) mod 2;
|
alpar@1
|
66 |
/* x[i,j] is j-th component of i-th binary n-vector */
|
alpar@1
|
67 |
|
alpar@1
|
68 |
param a{j in N}, >= 0;
|
alpar@1
|
69 |
/* original coefficients */
|
alpar@1
|
70 |
|
alpar@1
|
71 |
param b, >= 0;
|
alpar@1
|
72 |
/* original right-hand side */
|
alpar@1
|
73 |
|
alpar@1
|
74 |
set D := setof{i in U: sum{j in N} a[j] * x[i,j] <= b} i;
|
alpar@1
|
75 |
/* set of numbers of binary n-vectors, which (vectors) are feasible,
|
alpar@1
|
76 |
i.e. satisfy to the original knapsack inequality (1) */
|
alpar@1
|
77 |
|
alpar@1
|
78 |
var alfa{j in N}, integer, >= 0;
|
alpar@1
|
79 |
/* coefficients to be found */
|
alpar@1
|
80 |
|
alpar@1
|
81 |
var beta, integer, >= 0;
|
alpar@1
|
82 |
/* right-hand side to be found */
|
alpar@1
|
83 |
|
alpar@1
|
84 |
minimize z: sum{j in N} alfa[j] + beta; /* (3) */
|
alpar@1
|
85 |
|
alpar@1
|
86 |
phi{i in D}: sum{j in N} alfa[j] * x[i,j] <= beta; /* (4) */
|
alpar@1
|
87 |
|
alpar@1
|
88 |
psi{i in U diff D}: sum{j in N} alfa[j] * x[i,j] >= beta + 1; /* (5) */
|
alpar@1
|
89 |
|
alpar@1
|
90 |
solve;
|
alpar@1
|
91 |
|
alpar@1
|
92 |
printf "\nOriginal 0-1 knapsack inequality:\n";
|
alpar@1
|
93 |
for {j in 1..n} printf (if j = 1 then "" else " + ") & "%g x%d",
|
alpar@1
|
94 |
a[j], j;
|
alpar@1
|
95 |
printf " <= %g\n", b;
|
alpar@1
|
96 |
printf "\nMinimized equivalent inequality:\n";
|
alpar@1
|
97 |
for {j in 1..n} printf (if j = 1 then "" else " + ") & "%g x%d",
|
alpar@1
|
98 |
alfa[j], j;
|
alpar@1
|
99 |
printf " <= %g\n\n", beta;
|
alpar@1
|
100 |
|
alpar@1
|
101 |
data;
|
alpar@1
|
102 |
|
alpar@1
|
103 |
/* These data correspond to the very first example from [1]. */
|
alpar@1
|
104 |
|
alpar@1
|
105 |
param n := 8;
|
alpar@1
|
106 |
|
alpar@1
|
107 |
param a := [1]65, [2]64, [3]41, [4]22, [5]13, [6]12, [7]8, [8]2;
|
alpar@1
|
108 |
|
alpar@1
|
109 |
param b := 80;
|
alpar@1
|
110 |
|
alpar@1
|
111 |
end;
|