# source:glpk-cmake/examples/sat.mod@1:c445c931472f

Last change on this file since 1:c445c931472f was 1:c445c931472f, checked in by Alpar Juttner <alpar@…>, 10 years ago

Import glpk-4.45

• Generated files and doc/notes are removed
File size: 5.1 KB
Line
1/* SAT, Satisfiability Problem */
2
3/* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
4
5param m, integer, > 0;
6/* number of clauses */
7
8param n, integer, > 0;
9/* number of variables */
10
11set C{1..m};
12/* clauses; each clause C[i], i = 1, ..., m, is disjunction of some
13   variables or their negations; in the data section each clause is
14   coded as a set of indices of corresponding variables, where negative
15   indices mean negation; for example, the clause (x3 or not x7 or x11)
16   is coded as the set { 3, -7, 11 } */
17
18var x{1..n}, binary;
19/* main variables */
20
21/* To solve the satisfiability problem means to determine all variables
22   x[j] such that conjunction of all clauses C[1] and ... and C[m] takes
23   on the value true, i.e. all clauses are satisfied.
24
25   Let the clause C[i] be (t or t' or ... or t''), where t, t', ..., t''
26   are either variables or their negations. The condition of satisfying
27   C[i] can be most naturally written as:
28
29      t + t' + ... + t'' >= 1,                                       (1)
30
31   where t, t', t'' have to be replaced by either x[j] or (1 - x[j]).
32   The formulation (1) leads to the mip problem with no objective, i.e.
33   to a feasibility problem.
34
35   Another, more practical way is to write the condition for C[i] as:
36
37      t + t' + ... + t'' + y[i] >= 1,                                (2)
38
39   where y[i] is an auxiliary binary variable, and minimize the sum of
40   y[i]. If the sum is zero, all y[i] are also zero, and therefore all
41   clauses are satisfied. If the sum is minimal but non-zero, its value
42   shows the number of clauses which cannot be satisfied. */
43
44var y{1..m}, binary, >= 0;
45/* auxiliary variables */
46
47s.t. c{i in 1..m}:
48      sum{j in C[i]} (if j > 0 then x[j] else (1 - x[-j])) + y[i] >= 1;
49/* the condition (2) */
50
51minimize unsat: sum{i in 1..m} y[i];
52/* number of unsatisfied clauses */
53
54data;
55
56/* These data correspond to the instance hole6 (pigeon hole problem for
57   6 holes) from SATLIB, the Satisfiability Library, which is part of
58   the collection at the Forschungsinstitut fuer anwendungsorientierte
59   Wissensverarbeitung in Ulm Germany */
60
61/* The optimal solution is 1 (one clause cannot be satisfied) */
62
63param m := 133;
64
65param n := 42;
66
67set C[1] := -1 -7;
68set C[2] := -1 -13;
69set C[3] := -1 -19;
70set C[4] := -1 -25;
71set C[5] := -1 -31;
72set C[6] := -1 -37;
73set C[7] := -7 -13;
74set C[8] := -7 -19;
75set C[9] := -7 -25;
76set C[10] := -7 -31;
77set C[11] := -7 -37;
78set C[12] := -13 -19;
79set C[13] := -13 -25;
80set C[14] := -13 -31;
81set C[15] := -13 -37;
82set C[16] := -19 -25;
83set C[17] := -19 -31;
84set C[18] := -19 -37;
85set C[19] := -25 -31;
86set C[20] := -25 -37;
87set C[21] := -31 -37;
88set C[22] := -2 -8;
89set C[23] := -2 -14;
90set C[24] := -2 -20;
91set C[25] := -2 -26;
92set C[26] := -2 -32;
93set C[27] := -2 -38;
94set C[28] := -8 -14;
95set C[29] := -8 -20;
96set C[30] := -8 -26;
97set C[31] := -8 -32;
98set C[32] := -8 -38;
99set C[33] := -14 -20;
100set C[34] := -14 -26;
101set C[35] := -14 -32;
102set C[36] := -14 -38;
103set C[37] := -20 -26;
104set C[38] := -20 -32;
105set C[39] := -20 -38;
106set C[40] := -26 -32;
107set C[41] := -26 -38;
108set C[42] := -32 -38;
109set C[43] := -3 -9;
110set C[44] := -3 -15;
111set C[45] := -3 -21;
112set C[46] := -3 -27;
113set C[47] := -3 -33;
114set C[48] := -3 -39;
115set C[49] := -9 -15;
116set C[50] := -9 -21;
117set C[51] := -9 -27;
118set C[52] := -9 -33;
119set C[53] := -9 -39;
120set C[54] := -15 -21;
121set C[55] := -15 -27;
122set C[56] := -15 -33;
123set C[57] := -15 -39;
124set C[58] := -21 -27;
125set C[59] := -21 -33;
126set C[60] := -21 -39;
127set C[61] := -27 -33;
128set C[62] := -27 -39;
129set C[63] := -33 -39;
130set C[64] := -4 -10;
131set C[65] := -4 -16;
132set C[66] := -4 -22;
133set C[67] := -4 -28;
134set C[68] := -4 -34;
135set C[69] := -4 -40;
136set C[70] := -10 -16;
137set C[71] := -10 -22;
138set C[72] := -10 -28;
139set C[73] := -10 -34;
140set C[74] := -10 -40;
141set C[75] := -16 -22;
142set C[76] := -16 -28;
143set C[77] := -16 -34;
144set C[78] := -16 -40;
145set C[79] := -22 -28;
146set C[80] := -22 -34;
147set C[81] := -22 -40;
148set C[82] := -28 -34;
149set C[83] := -28 -40;
150set C[84] := -34 -40;
151set C[85] := -5 -11;
152set C[86] := -5 -17;
153set C[87] := -5 -23;
154set C[88] := -5 -29;
155set C[89] := -5 -35;
156set C[90] := -5 -41;
157set C[91] := -11 -17;
158set C[92] := -11 -23;
159set C[93] := -11 -29;
160set C[94] := -11 -35;
161set C[95] := -11 -41;
162set C[96] := -17 -23;
163set C[97] := -17 -29;
164set C[98] := -17 -35;
165set C[99] := -17 -41;
166set C[100] := -23 -29;
167set C[101] := -23 -35;
168set C[102] := -23 -41;
169set C[103] := -29 -35;
170set C[104] := -29 -41;
171set C[105] := -35 -41;
172set C[106] := -6 -12;
173set C[107] := -6 -18;
174set C[108] := -6 -24;
175set C[109] := -6 -30;
176set C[110] := -6 -36;
177set C[111] := -6 -42;
178set C[112] := -12 -18;
179set C[113] := -12 -24;
180set C[114] := -12 -30;
181set C[115] := -12 -36;
182set C[116] := -12 -42;
183set C[117] := -18 -24;
184set C[118] := -18 -30;
185set C[119] := -18 -36;
186set C[120] := -18 -42;
187set C[121] := -24 -30;
188set C[122] := -24 -36;
189set C[123] := -24 -42;
190set C[124] := -30 -36;
191set C[125] := -30 -42;
192set C[126] := -36 -42;
193set C[127] := 6 5 4 3 2 1;
194set C[128] := 12 11 10 9 8 7;
195set C[129] := 18 17 16 15 14 13;
196set C[130] := 24 23 22 21 20 19;
197set C[131] := 30 29 28 27 26 25;
198set C[132] := 36 35 34 33 32 31;
199set C[133] := 42 41 40 39 38 37;
200
201end;
Note: See TracBrowser for help on using the repository browser.