COIN-OR::LEMON - Graph Library

source: lemon-project-template-glpk/deps/glpk/doc/cnfsat.tex

subpack-glpk
Last change on this file was 9:33de93886c88, checked in by Alpar Juttner <alpar@…>, 13 years ago

Import GLPK 4.47

File size: 13.1 KB
RevLine 
[9]1%* cnfsat.tex *%
2
3\documentclass[11pt,draft]{article}
4
5\begin{document}
6
7\title{CNF Satisfiability Problem}
8
9\author{Andrew Makhorin {\tt<mao@gnu.org>}}
10
11\date{August 2011}
12
13\maketitle
14
15\section{Introduction}
16
17The {\it Satisfiability Problem (SAT)} is a classic combinatorial
18problem. Given a Boolean formula of $n$ variables
19$$f(x_1,x_2,\dots,x_n),\eqno(1.1)$$
20this problem is to find such values of the variables, on which the
21formula takes on the value {\it true}.
22
23The {\it CNF Satisfiability Problem (CNF-SAT)} is a version of the
24Satisfiability Problem, where the Boolean formula (1.1) is specified
25in the {\it Conjunctive Normal Form (CNF)}, that means that it is a
26conjunction of {\it clauses}, where a clause is a disjunction of
27{\it literals}, and a literal is a variable or its negation.
28For example:
29$$(x_1\vee x_2)\;\&\;(\neg x_2\vee x_3\vee\neg x_4)\;\&\;(\neg
30x_1\vee x_4).\eqno(1.2)$$
31Here $x_1$, $x_2$, $x_3$, $x_4$ are Boolean variables to be assigned,
32$\neg$ means
33negation (logical {\it not}), $\vee$ means disjunction (logical
34{\it or}), and $\&$ means conjunction (logical {\it and}). One may
35note that the formula (1.2) is {\it satisfiable}, because on
36$x_1$ = {\it true}, $x_2$ = {\it false}, $x_3$ = {\it false}, and
37$x_4$ = {\it true} it takes on the value {\it true}. If a formula
38is not satisfiable, it is called {\it unsatisfiable}, that means that
39it takes on the value {\it false} on any values of its variables.
40
41Any CNF-SAT problem can be easily translated to a 0-1 programming
42problem as follows. A Boolean variable $x$ can be modeled by a binary
43variable in a natural way: $x=1$ means that $x$ takes on the value
44{\it true}, and $x=0$ means that $x$ takes on the value {\it false}.
45Then, if a literal is a negated variable, i.e. $t=\neg x$, it can
46be expressed as $t=1-x$. Since a formula in CNF is a conjunction of
47clauses, to provide its satisfiability we should require all its
48clauses to  take on the value {\it true}. A particular clause is
49a disjunction of literals:
50$$t\vee t'\vee t''\dots ,\eqno(1.3)$$
51so it takes on the value {\it true} iff at least one of its literals
52takes on the value {\it true}, that can be expressed as the following
53inequality constraint:
54$$t+t'+t''+\dots\geq 1.\eqno(1.4)$$
55Note that no objective function is used in this case, because only
56a feasible solution needs to be found.
57
58For example, the formula (1.2) can be translated to the following
59constraints:
60$$\begin{array}{c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c}
61x_1&+&x_2&&&&&\geq&1\\
62&&(1-x_2)&+&x_3&+&(1-x_4)&\geq&1\\
63(1-x_1)&&&&&+&x_4&\geq&1\\
64\end{array}$$
65$$x_1, x_2, x_3, x_4\in\{0,1\}$$
66Carrying out all constant terms to the right-hand side gives
67corresponding 0-1 programming problem in the standard format:
68$$\begin{array}{r@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }c@{\ }r}
69x_1&+&x_2&&&&&\geq&1\\
70&-&x_2&+&x_3&-&x_4&\geq&-1\\
71-x_1&&&&&+&x_4&\geq&0\\
72\end{array}$$
73$$x_1, x_2, x_3, x_4\in\{0,1\}$$
74
75In general case translation of a CNF-SAT problem results in the
76following 0-1 programming problem:
77$$\sum_{j\in J^+_i}x_j-\sum_{j\in J^-_i}x_j\geq 1-|J^-_i|,
78\ \ \ i=1,\dots,m\eqno(1.5)$$
79$$x_j\in\{0,1\},\ \ \ j=1,\dots,n\eqno(1.6)$$
80where $n$ is the number of variables, $m$ is the number of clauses
81(inequality constraints), $J^+_i\subseteq\{1,\dots,n\}$ is a subset
82of variables, whose literals in $i$-th clause do not have negation,
83and $J^-_i\subseteq\{1,\dots,n\}$ is a subset of variables, whose
84literals in $i$-th clause are negations of that variables. It is
85assumed that $J^+_i\cap J^-_i=\emptyset$ for all $i$.
86
87\newpage
88
89\section{GLPK API Routines}
90
91\subsection{glp\_read\_cnfsat---read CNF-SAT problem data in\\DIMACS
92format}
93
94\subsubsection*{Synopsis}
95
96\begin{verbatim}
97int glp_read_cnfsat(glp_prob *P, const char *fname);
98\end{verbatim}
99
100\subsubsection*{Description}
101
102The routine \verb|glp_read_cnfsat| reads the CNF-SAT problem data from
103a text file in DIMACS format and automatically translates the data to
104corresponding 0-1 programming problem instance (1.5)--(1.6).
105
106The parameter \verb|P| specifies the problem object, to which the
1070-1 programming problem instance should be stored. Note that before
108reading data the current content of the problem object is completely
109erased with the routine \verb|glp_erase_prob|.
110
111The character string \verb|fname| specifies the name of a text file
112to be read in. (If the file name ends with the suffix `\verb|.gz|',
113the file is assumed to be compressed, in which case the routine
114decompresses it ``on the fly''.)
115
116\subsubsection*{Returns}
117
118If the operation was successful, the routine returns zero. Otherwise,
119it prints an error message and returns non-zero.
120
121\subsubsection*{DIMACS CNF-SAT problem format\footnote{This material
122is based on the paper ``Satisfiability Suggested Format'', which is
123publicly available at {\tt http://dimacs.rutgers.edu/}.}}
124
125The DIMACS input file is a plain ASCII text file. It contains lines of
126several types described below. A line is terminated with an end-of-line
127character. Fields in each line are separated by at least one blank
128space.
129
130\paragraph{Comment lines.} Comment lines give human-readable
131information about the file and are ignored by programs. Comment lines
132can appear anywhere in the file. Each comment line begins with a
133lower-case character \verb|c|.
134
135\begin{verbatim}
136   c This is a comment line
137\end{verbatim}
138
139\newpage
140
141\paragraph{Problem line.} There is one problem line per data file. The
142problem line must appear before any clause lines. It has the following
143format:
144
145\begin{verbatim}
146   p cnf VARIABLES CLAUSES
147\end{verbatim}
148
149\noindent
150The lower-case character \verb|p| signifies that this is a problem
151line. The three character problem designator \verb|cnf| identifies the
152file as containing specification information for the CNF-SAT problem.
153The \verb|VARIABLES| field contains an integer value specifying $n$,
154the number of variables in the instance. The \verb|CLAUSES| field
155contains an integer value specifying $m$, the number of clauses in the
156instance.
157
158\paragraph{Clauses.} The clauses appear immediately after the problem
159line. The variables are assumed to be numbered from 1 up to $n$. It is
160not necessary that every variable appears in the instance. Each clause
161is represented by a sequence of numbers separated by either a space,
162tab, or new-line character. The non-negated version of a variable $j$
163is represented by $j$; the negated version is represented by $-j$. Each
164clause is terminated by the value 0. Unlike many formats that represent
165the end of a clause by a new-line character, this format allows clauses
166to be on multiple lines.
167
168\paragraph{Example.} Below here is an example of the data file in
169DIMACS format corresponding to the CNF-SAT problem (1.2).
170
171\begin{footnotesize}
172\begin{verbatim}
173c sample.cnf
174c
175c This is an example of the CNF-SAT problem data
176c in DIMACS format.
177c
178p cnf 4 3
1791 2 0
180-4 3
181-2 0
182-1 4 0
183c
184c eof
185\end{verbatim}
186\end{footnotesize}
187
188\newpage
189
190\subsection{glp\_check\_cnfsat---check for CNF-SAT problem instance}
191
192\subsubsection*{Synopsis}
193
194\begin{verbatim}
195int glp_check_cnfsat(glp_prob *P);
196\end{verbatim}
197
198\subsubsection*{Description}
199
200The routine \verb|glp_check_cnfsat| checks if the specified problem
201object \verb|P| contains a 0-1 programming problem instance in the
202format (1.5)--(1.6) and therefore encodes a CNF-SAT problem instance.
203
204\subsubsection*{Returns}
205
206If the specified problem object has the format (1.5)--(1.6), the
207routine returns zero, otherwise non-zero.
208
209\subsection{glp\_write\_cnfsat---write CNF-SAT problem data in\\DIMACS
210format}
211
212\subsubsection*{Synopsis}
213
214\begin{verbatim}
215int glp_write_cnfsat(glp_prob *P, const char *fname);
216\end{verbatim}
217
218\subsubsection*{Description}
219
220The routine \verb|glp_write_cnfsat| automatically translates the
221specified 0-1 programming problem instance (1.5)--(1.6) to a CNF-SAT
222problem instance and writes the problem data to a text file in DIMACS
223format.
224
225The parameter \verb|P| is the problem object, which should specify
226a 0-1 programming problem instance in the format (1.5)--(1.6).
227
228The character string \verb|fname| specifies a name of the output text
229file to be written. (If the file name ends with suffix `\verb|.gz|',
230the file is assumed to be compressed, in which case the routine
231performs automatic compression on writing that file.)
232
233\subsubsection*{Returns}
234
235If the operation was successful, the routine returns zero. Otherwise,
236it prints an error message and returns non-zero.
237
238\newpage
239
240\subsection{glp\_minisat1---solve CNF-SAT problem instance with\\
241MiniSat solver}
242
243\subsubsection*{Synopsis}
244
245\begin{verbatim}
246int glp_minisat1(glp_prob *P);
247\end{verbatim}
248
249\subsubsection*{Description}
250
251The routine \verb|glp_minisat1| is a driver to MiniSat, a CNF-SAT
252solver developed by Niklas E\'en and Niklas S\"orensson, Chalmers
253University of Technology, Sweden.\footnote{The MiniSat software module
254is {\it not} part of GLPK, but is used with GLPK and included in the
255distribution.}
256
257It is assumed that the specified problem object \verb|P| contains
258a 0-1 programming problem instance in the format (1.5)--(1.6) and
259therefore encodes a CNF-SAT problem instance.
260
261If the problem instance has been successfully solved to the end, the
262routine \verb|glp_minisat1| returns 0. In this case the routine
263\verb|glp_mip_status| can be used to determine the solution status:
264
265\verb|GLP_OPT| means that the solver found an integer feasible
266solution and therefore the corresponding CNF-SAT instance is
267satisfiable;
268
269\verb|GLP_NOFEAS| means that no integer feasible solution exists and
270therefore the corresponding CNF-SAT instance is unsatisfiable.
271
272If an integer feasible solution was found, corresponding values of
273binary variables can be retrieved with the routine
274\verb|glp_mip_col_val|.
275
276\subsubsection*{Returns}
277
278\begin{tabular}{@{}p{25mm}p{97.3mm}@{}}
2790 & The MIP problem instance has been successfully solved. (This code
280does {\it not} necessarily mean that the solver has found feasible
281solution. It only means that the solution process was successful.)\\
282\verb|GLP_EDATA| & The specified problem object contains a MIP instance
283which does {\it not} have the format (1.5)--(1.6).\\
284\verb|GLP_EFAIL| & The solution process was unsuccessful because of the
285solver failure.\\
286\end{tabular}
287
288\newpage
289
290\subsection{glp\_intfeas1---solve integer feasibility problem}
291
292\subsubsection*{Synopsis}
293
294\begin{verbatim}
295int glp_intfeas1(glp_prob *P, int use_bound, int obj_bound);
296\end{verbatim}
297
298\subsubsection*{Description}
299
300The routine \verb|glp_intfeas1| is a tentative implementation of
301an integer feasibility solver based on a CNF-SAT solver (currently
302it is MiniSat; see Subsection 2.4).
303
304If the parameter \verb|use_bound| is zero, the routine searches for
305{\it any} integer feasibile solution to the specified integer
306programming problem. Note that in this case the objective function is
307ignored.
308
309If the parameter \verb|use_bound| is non-zero, the routine searches for
310an integer feasible solution, which provides a value of the objective
311function not worse than \verb|obj_bound|. In other word, the parameter
312\verb|obj_bound| specifies an upper (in case of minimization) or lower
313(in case of maximization) bound to the objective function.
314
315If the specified problem has been successfully solved to the end, the
316routine \verb|glp_intfeas1| returns 0. In this case the routine
317\verb|glp_mip_status| can be used to determine the solution status:
318
319\begin{itemize}
320\item {\tt GLP\_FEAS} means that the solver found an integer feasible
321solution;
322
323\item {\tt GLP\_NOFEAS} means that the problem has no integer feasible
324solution (if {\tt use\_bound} is zero) or it has no integer feasible
325solution, which is not worse than {\tt obj\_bound} (if {\tt use\_bound}
326is non-zero).
327\end{itemize}
328
329If an integer feasible solution was found, corresponding values of
330variables (columns) can be retrieved with the routine
331\verb|glp_mip_col_val|.
332
333\subsubsection*{Usage Notes}
334
335The integer programming problem specified by the parameter \verb|P|
336should satisfy to the following requirements:
337
338\begin{enumerate}
339\item All variables (columns) should be either binary ({\tt GLP\_BV})
340or fixed at integer values ({\tt GLP\_FX}).
341
342\item All constraint and objective coefficients should be integer
343numbers in the range $[-2^{31},\ +2^{31}-1]$.
344\end{enumerate}
345
346Though there are no special requirements to the constraints,
347currently the routine \verb|glp_intfeas1| is efficient mainly for
348problems, where most constraints (rows) fall into the following three
349classes:
350
351\begin{enumerate}
352\item Covering inequalities
353$$\sum_{j}t_j\geq 1,$$
354where $t_j=x_j$ or $t_j=1-x_j$, $x_j$ is a binary variable.
355
356\item Packing inequalities
357$$\sum_{j}t_j\leq 1.$$
358
359\item Partitioning equalities (SOS1 constraints)
360$$\sum_{j}t_j=1.$$
361\end{enumerate}
362
363\subsubsection*{Returns}
364
365\begin{tabular}{@{}p{25mm}p{97.3mm}@{}}
3660 & The problem has been successfully solved. (This code does {\it not}
367necessarily mean that the solver has found an integer feasible solution.
368It only means that the solution process was successful.)\\
369
370\verb|GLP_EDATA| & The specified problem object does not satisfy to the
371requirements listed in Paragraph `Usage Notes'.\\
372
373\verb|GLP_ERANGE| & An integer overflow occured on translating the
374specified problem to a CNF-SAT problem.\\
375
376\verb|GLP_EFAIL| & The solution process was unsuccessful because of the
377solver failure.\\
378\end{tabular}
379
380\end{document}
Note: See TracBrowser for help on using the repository browser.