1 \documentclass[12pt,
a4paper,
dvips]{article
}
4 \usepackage{graphicx,html
}
6 \htmladdtonavigation{\htmladdnormallink
7 {\htmladdimg{../images/home.png
}}{../piplib.html
}}
9 % NdCed: ca c'est pour retrouver le format original (le document de 96
10 % etait prevu pour LaTeX 2.09, et est a present au standard LaTeX2e).
11 \setlength{\textwidth}{145mm
}
12 \setlength{\textheight}{219mm
}
14 \newcommand{\pair}[2]{\,<\!
#1,
#2\!>\,
}
15 \newcommand{\bq}{\begin{equation
}}
16 \newcommand{\eq}{\end{equation
}}
17 \newenvironment{exemple
}{\begin{quote
} \small}{\end{quote
}}
18 \newtheorem{grammar
}{Grammar
}
19 \def\|
#1|
{\mathrel{\hbox{\tt #1}}}
21 \date{Additions by Jean-Fran
\c{c
}ois Collard and C\'edric Bastoul\\
22 Fourth Version, rev
1.5, November
8,
2005}
24 \title{Solving Systems of Affine (In)Equalities: PIP's User's Guide
}
26 \author{Paul Feautrier
}
33 \bibliographystyle{plain
}
36 This
document is the User's Manual of PIP, a software which solves
37 Parametric Integer Programming problems. That is, PIP finds the
38 lexicographic minimum of the set of integer points which lie inside a
39 convex polyhedron, when that polyhedron depends linearly on one or
40 more integral parameters.
43 \section{Introduction
}
44 The semantic analysis of programs accessing arrays often boils down
45 to finding integer solutions to parametric linear programming problems. This is
46 due to two main phenomena:
48 \item Array subscripts are very often linear functions of surrounding loop counters~;
49 \item The program's execution order enforces an order on possible solutions.
52 Let us consider the following example:
55 for j :=
0 to n do
{I
}
59 After completion of execution, for which values of $k$ is
{\tt A
[}$k$
{\tt ]}
60 defined, and which instances of the assignment wrote into
61 this array element? We can easily check that answering this question
62 is equivalent to finding the solutions of the following system, where $i,
63 j$ and $k$ are the unknowns:
65 0 \leq & i &
\leq m ,\\
66 0 \leq & j &
\leq n ,\\
70 Moreover, if we want to know which instance gave its
{\em final
} value
71 to
{\tt A
[}$k$
{\tt ]}, that is if we are looking for the
{\em last
} instance
72 writing into
{\tt A
[}$k$
{\tt ]}, then we have to look for the maximal value
73 of vector $(i,j)$ according to lexicographic order. We
74 thus consider the following
{\em polyhedron
} $
{\cal F
}(k, m, n) $:
76 {\cal F
}(k, m, n) = \
{<i, j>|
0 \leq i
\leq m,
0 \leq j
\leq n,
2i+j = k\
} .
79 What is the lexicographical maximum of the
80 integer-valued vectors included in $
{\cal F
}(k, m, n)$?
81 The aim of PIP is to solve such problems. The reader is referred to
82 \cite{Feau:
88b
} for a mathematical description of the method.
84 % Ajouter qq explications
88 \subsection{General formulation
}
89 Let $
{\cal F
}$ be a polyhedron:
93 = \
{ \vec{x
} |
\vec{x
} \geq 0,
94 {\bf A
} \vec{x
} +
{\bf B
} \vec{z
} +
\vec{c
} \geq 0\
} .
96 In this formula, $
\vec{x
}$ is a vector with $n$ entries: the vector of
97 all unknowns. $
\vec{z
}$, $
\vec{z
}\geq 0$, is the vector built from
98 parameters and has $p$ entries. Polyhedron $
{\cal F
}(
\vec{z
})$ is a
99 subset of $
{\bf R
}^
{n
}$ and is defined by $n + l$ inequalities: $n$
100 inequalities expressing
102 and the $l$ inequalities corresponding to rows of matrix
103 $
{\bf A
}$ of size $l
\times n$, matrix $
{\bf B
}$ of size $l
\times p$,
104 and constant vector $
\vec{c
}$ of size $l$.
106 Size parameters can themselves be constrained by a set of affine inequalities
107 \
[ {\bf M
} \vec{z
} +
\vec{h
} \geq 0 ,\
]
108 which is called the
{\em context
} of the problem. $
{\bf M
}$ is an $m
109 \times p$ matrix and $
\vec{h
}$ a vector of dimension $m$.
110 All data of a PIP problem: ($
{\bf A
},
{\bf B
},
{\bf M
},
\vec{c
},
\vec{h
}$)
111 are assumed to be integer-valued.
114 \section{Using the PIP Software
}
117 \subsection{Writing the Input File
}
118 \label{specif:donnees
}
120 The input text file follows the following context-free grammar:
126 Problem ::= ( Comments Nn Np Nl Nm Bg Nq Tableau Context )
128 List ::= Atom | ( List ... )
129 Tableau ::= ( Vector ... )
130 Context ::= ( Vector ... )
131 Vector ::= #
[ Integer ...
]
140 This syntax was chosen so as to ease the generation of problems
141 by a Lisp program. In
142 particular, each
{\tt Problem
} is a balanced list, as far as both
143 parentheses and brackets are concerned.
147 {\tt Comments
} are arbitrary lists. These comments are
148 written verbatim to the output file, and are useful to keep track of
149 problems and solutions.
151 Note that several
{\tt Problem
}s can be given to PIP in the same
152 file. The problems may be separated by any text that does not
153 contain a parenthesis. By using Unix FIFOs as input and output files,
154 it is easy to convert the present implementation of PIP into a
155 linear programming server.
158 {\tt Nn
} is the number of unknowns in the program (which was denoted
159 by $n$ in the first section).
161 \item {\tt Np
} is the number of (symbolic) parameters ($p$)
163 \item {\tt Nl
} is the number of inequalities defining the domain of the unknowns ($l$).
165 \item {\tt Nm
} is the number of inequalities satisfied by the parameters ($m$).
167 \item {\tt Bg
} is the index of a ``Big'' parameter whose value is assumed
168 to be infinitely large. That is, if the big parameter appears with a
169 positive coefficient in a form $
\phi$, then we can immediately deduce
170 that $
\phi >
0$. If
{\tt Bg
} is set to a nonpositive
171 value, then there is no big parameter in the problem to be solved.
173 Be aware that
{\tt Bg
} is the column rank of the corresponding
174 parameter in the
{\tt Tableau
}, and that the first valid value for it
177 \item {\tt Nq
} is an integer but should be interpreted
178 as a boolean value
{\sl \`a la
}
179 C, that is, it denotes ``true'' if its value is nonzero. If
{\tt Nq
}
180 is true, then an integer-valued solution is looked for. Otherwise, PIP
181 finds the lexicographic minimum rational solution to the problem.
183 \item {\tt Tableau
} stores the set of inequalities defining the domain
184 of unknowns. Each
{\tt Vector
} represents one inequality. The entries
185 in
{\tt Vector
} are, in this order:
187 \item the coefficients of the unknowns (I.e., a row of matrix $
{\bf A
}$),
188 \item the (additive) constant, (I.e., an entry of vector $
\vec{c
}$),
189 \item the coefficients of the parameters (I.e., a row of matrix $
{\bf B
}$)
191 This notation heavily depends on the positions given
192 to unknowns and parameters: it is the responsibility of the user to
193 enforce a coherent ordering of coefficients and to set a coefficient
194 to zero when the corresponding unknown/parameter does not appear.
196 There are $l$ such
{\tt Vector
}s in
{\tt Tableau
}, and each
{\tt
197 vector
} exactly has $n+
1+p$ entries.
200 \item In a similar way,
{\tt Context
} is a list of
{\tt Vector
}s. Each
{\tt Vector
} represents a row of Matrix $
{\bf M
}$ followed by the
201 corresponding entry in vector $
\vec{h
}$.
{\tt Context
} thus includes
202 $m$
{\tt Vector
}s of $p +
1$ entries.
208 \subsubsection{Example
} \label{exp2
}
209 This example is taken from
\cite{Feau:
88c
}. We consider the loop nest below:
212 for j :=
0 to n do
{II
}
213 for k :=
0 to i+j do ...
215 and we wish to rewrite this nest in the order
{\tt k, j, i
}. The
216 bounds on
{\tt k
} can easily be guessed ($
0\leq k
\leq m+n$), so let's
217 look for the lower bound on
{\tt j
} in the rewritten nest. This lower bound on
218 {\tt j
} can be found by solving the following problem:
219 \
[ {\cal D
}_
{2}(k) = \
{\pair{j
}{i
} | i
\leq m, j
\leq n, k
\leq i + j\
} .\
]
221 This problem is to be solved in the context $k
\leq m+n$. The input file
222 may thus look like this:
224 ( (Lower bound on j after loop inversion
235 The first sequence of integers should be read as: This problem has
2
236 unknowns ($i$ and $j$) and
3 parameters ($k$, $m$ and $n$). The domain is
237 defined by
3 inequalities, the context by
1 inequality. There is no
238 (-
1) big parameter and it is true (
1) that we are looking for an
241 \subsection{Calling PIP
}
242 PIP is called by the following command:
244 pip
[-s|-v...
] [-d
] [-z
] [input
[output
]]
246 PIP prints some information on the screen after having solved a
247 problem. The
{\tt -s
} (silent mode) switches this feature off. On the
248 contrary, the verbose
{\tt -v
} option tells PIP to copy, in a file,
249 all the input data and all the intermediary results. The name of this
250 file is given either by the variable
{\tt DEBUG
} in the environment or
251 is built by
{\tt mkstemp
}. The number of consecutive v's controls the
252 degree of verbosity of Pip. A word of caution: debug files may become
253 very large very fast.
255 When Pip is asked for an integral solution, it constructs new constraints
256 (the so-called
{\em cuts
}) which eliminate fractional solutions and keep
257 all integer solutions. The selection of cuts is somewhat arbitrary. When
258 the
{\tt -d
} option is given, Pip uses this degree of freedom to select
259 the ``deepest cut'' according to an algorithm by Gondran. Intractable
260 problems may become tractable when using this option, and conversely.
263 If the
{\tt -z
} option is given, then the solution is somewhat simplified
266 {\tt input
} and
{\tt output
} are the names of the input (data) and
267 output (results) files, respectively. If no
{\tt output
} (
{\tt
268 input
}) file is given, then the results are printed to the standard
272 \subsubsection{Messages
}
275 \item {\tt Version X.x
}. Currently,
{\tt D
.1}.
277 \item {\tt cross : <n>, alloc : <m>
} This message is output after solving
278 each problem. The value of
{\tt <n>
} gives an idea of the complexity of
282 \paragraph{Errors related to the input
}
284 \item {\tt Syntax error
}: unbalanced parentheses in the input.
286 \item {\tt Your computer doesn't have enough memory
}: self explanatory.
288 \paragraph{Errors related to the solution
}
290 \item {\tt Integer Overflow
}: A number has been generated that is too large
291 to be accommodated in a
32 bit integer. Check the input and/or switch
292 to Zbigniew Chamski's infinite precision PIP.
294 \item {\tt The solution is too complex
}: the solution quast has grown beyond
295 the memory allocated to it. Check the input and/or change the value of
296 constant
{\tt SOL
\_SIZE} in file
{\tt type.h
}, then rebuild PIP.
298 \item {\tt Memory overflow
}: self explanatory.
300 \item {\tt <file> unaccessible
}: one of the input, output or debug file
303 \paragraph{Dimension errors
}
305 \item {\tt Too much variables
}
307 \item {\tt Too much parameters
} : Check the input and/or change the value of
308 constants
{\tt MAXCOL
} and
{\tt MAXPARM
} in file
{\tt type.h
}, then
311 \paragraph{Implementation errors
}
313 All such error messages begin by the word
{\tt Syserr
}. These messages
314 indicate a bug in the implementation. You should
report such events
315 by sending a copy of the input file by e-mail to the author,
\linebreak
316 {\tt Paul.Feautrier@prism.uvsq.fr
} who will endeavor to solve the problem
319 \subsection{Output Data
}\label{OutputData
}
320 The output file can be described by the following grammar:
321 \begin{grammar
}\label{GrammarOutputData
}
326 Result :: ( Comments Solution )
327 Solution ::= Quast_group
329 Quast_group ::= Quast
332 | (if Vector Quast_group Quast_group)
333 Form ::= (list Vector ...)
335 Newparm ::= (newparm Integer (div Vector Integer))
336 Vector ::= #
[ Coefficient ...
]
337 Coefficient ::= Integer | Integer / Integer
340 The
{\tt Comments
} are copied from the input file. The
{\tt Solution
}
341 is said to be
{\tt void
} when the initial context is void. Otherwise,
342 it is given as a quast written
{\sl \`a la
} Lisp. The quast may
343 possibly be preceded by the definition of one or several new
346 The vector coefficients may be either integers or rationals written as
347 {\tt num/denom
}. The latter case occurs if
{\tt Nq
} had been
348 set to
0 in the input file.
350 In the solution, a
{\tt Vector
} represents an affine form; each entry
351 is the coefficient of the corresponding parameter (the parameter of
352 the same rank). The last entry is the additive constant.
354 The definition of a new parameter begins with the key-word
355 {\tt newparm
}, then a rank number, a vector of coefficients, and a
356 denominator. The new parameter is equal to the integer division of the
357 vector by the denominator. The new parameter can only appear in the
358 {\tt Quast
} following its definition. Introducing a new parameter adds
359 one entry in the list of parameters, so the length of vectors in the
360 solution is not constant. However, this length is always equal to
1 plus
361 the number of original parameters plus the number of new parameters
364 The solution is a multi-level conditional expression (a
365 tree of nested conditionals.) A predicate expression $p$ should be
366 understood as the boolean expression $p
\geq 0$. Leaves of the
367 conditional tree are either
{\tt nil
}, meaning that the input problem
368 has no solution, or a
{\tt Form
}. A
{\tt Form
} is a list of vectors,
369 each vector giving the value of the corresponding unknown.
371 \subsubsection{Example
}
372 The output of PIP is not intended for human consumption.
373 No attempt has been made to implement a pretty-printer. In the interest
374 of readability, some of the result files in this paper have been beautified
375 by hand. The reader should not be surprised if he gets results with
376 different layouts when running the examples.
378 Here is the output solution file for the example above (
\ref{exp2
}):
380 ( (Lower bound on j after loop inversion
382 (parameters k m n)
1 )(if #
[ -
1 1 0 0]
392 To express this solution, no new parameter had to be introduced. The
393 form associated to the first conditional is:
394 \
[ -
1 \times k +
1 \times m +
0 \times n +
0 \times 1 = m-k \
]
395 so the test should be read as $m - k
\geq 0$. If this inequality
396 holds, then the solution is $<
0, k>$. Otherwise, the solution is
399 To sum things up, the lexicographical minimum of $
{\cal D
}_2$ is:
401 if m-k >=
0 then <
0, k> else <k-m, m>.
403 Hence the lower bound on the first coordinate:
405 if m-k >=
0 then
0 else k-m
408 \subsubsection{Simplifying the solution
}
410 The solution of a parametric problem may be in the form of a quast all
411 of whose leaves are nil. This means in fact that the original polyhedron
412 is empty whatever the values of the parameters. An example, due to Dirk
413 Fimmel, is the following:
429 Without the
{\tt -z
} option, the solution is:
437 (newparm
2 (div #
[ 0 2 3] 6))
438 (newparm
3 (div #
[ 0 2 10 7] 12))
439 (newparm
4 (div #
[ 0 4 0 2 1] 6))
442 (newparm
2 (div #
[ 0 4 3] 6))
443 (if #
[ 0 -
8 6 11] () ())
448 (if #
[ 10 -
2 -
15] ()())
453 Inspection reveals that all leaves are
{\tt ()
}. With the
{\tt -z
} option,
454 the solution is much simpler:
456 (((i j
1)(m n) -
1 )()
459 \subsection{The Power of PIP
}
460 In the following sections, we explain how PIP can be used to solve
461 extended classes of problems:
463 \item Problems where equalities occur.
464 \item Problems where a lexicographical
{\em maximum
} has to
466 \item Cases when linear cost functions are to be optimized.
467 \item Problems where unknowns and/or parameters may be negative
470 \subsubsection{Handling Equalities
}
471 When the input problem contains $r$ affine equalities $f_i =
0$,$
1\leq i
\leq r$,
472 one may just write $r$ inequalities $f_i
\geq 0$ and $r$ inequalities $f_i
\leq 0$,
473 thus satisfying PIP's input syntax. However, one may notice that only $r+
1$ inequalities
474 are needed: $f_i
\geq 0$, $
1\leq i
\leq r$, and the following inequality:
475 \
[ \sum_{i=
1}^
{r
} f_i
\leq 0.\
]
477 \subsubsection{The bigparm trick
}
479 In some cases, it is useful to suppose that one parameter in a PIP problem
480 grows ``very large''. Some examples will be given in the following sections.
481 Let $B$ be the name of this parameter. Suppose that in the solution, one
482 of the predicates is:
484 where $b$ may depend on all other parameters. For $B$ large enough, if $a >
0$
485 then the predicate is true, and if $a <
0$ then the predicate is false.
486 One can find the limit shape of the solution by removing such tests and
487 replacing them by their true of false branch, as appropriate. This can be done
488 {\sl a posteriori\/
} on the results of PIP, or PIP can do it ``on the fly''
489 while solving the problem. This last method is more efficient, since it
490 tends to simplify the solution.
492 PIP is notified of the presence of a big parameter by setting the
{\tt Bg
}
493 argument to a positive value. This value is the rank of the big parameter
494 in the problem tableau. Hence, the lowest admissible value for
{\tt Bg
}
497 The reader should convince himself that in the presence of two big
498 parameters, no such simplifications are possible unless one has some
499 information on the relative size of the parameters. Such situations
500 should be handled by giving PIP ordinary parameters, and doing the
501 simplification on the solution in the light of extra knowledge.
503 \subsubsection{Computing Lexicographical Maxima
}
505 To get the maximum of an unknown $x$, minimize $B - x$, where
506 B is a new "big" parameter. Adding a parameter just adds one column
507 in the problem tableau. The fact that this column corresponds to a Big
508 parameter is specified by setting the
5-th switch to a positive value,
509 this value being the position of the column of B in the problem
512 These cases can be handled systematically in the following way. Suppose that
513 we are asked for the integer maximum of the polyhedron:
515 x &
\ge &
0,
\nonumber \\
516 y &
\ge &
0,
\label{biggy
}\\
517 3 y &
\le & x +
12,
\nonumber\\
518 y &
\ge &
2 x -
3.
\nonumber
520 Let us introduce the new unknowns:
521 \
[ x'= B - x, \;\; y' = B - y ,\
]
522 where $B$ is the big parameter. System (
\ref{biggy
}) translates to:
526 -x' +
3y' +
12 -
2B &
\ge &
0,\\
527 2x' - y' +
3 - B &
\ge &
0.
529 Finding the maximum of $(x,y)^T$ is equivalent to finding the minimum of
530 $(x', y')^T$, provided $B$ is large enough. The solution of the above
533 ((a maximization problem
1 )
539 (newparm
1 (div #
[ 1 1] 2))
548 Suppose we tell PIP that $B$ is a large parameter. The input file is
551 ((a maximization problem)
561 and the solution is much simpler:
563 ((a maximization problem
1 )
567 The reader may care to check that this result is equivalent to the
568 previous one as soon as $B >
5$. The position of the minimum is:
569 $x' = B -
4, y' = B -
5$, from which we deduce: $x =
4, y =
5$. As
570 expected, $B$ has disappeared from the solution. If this does not happen,
571 we observe first that $B$ must have a positive coefficient in the result
572 (if not, one of the inequalities $x, y
\ge 0$ would be violated for $B$
573 large enough). This means that the original polyhedron is not bounded,
574 since, whatever $B$, it contains a point whose coordinates are $O(B)$,
575 and hence has no maximum.
577 \subsubsection{Optimizing Linear Cost Functions
}
579 The problem here is to compute the minimum of a linear function $cx$
581 where $c$ is a vector with integer coefficients. Let us introduce
582 a new unknown $y$. Solve the linear programming problem obtained by
583 adding the constraint $y
\ge cx$ to the defining constraints of $P$.
584 $y$ should be the first unknown in the lexicographic ordering. Let
585 $y_s, x_s$ be the solution. Suppose that the minimum of $cx$ in $P$
586 is obtained at $x_m$ and set $y_m = c x_m$. Since $x_s$ is in $P$,
587 and $y_s
\ge cx_s$, it is clear that $y_s
\ge y_m$. Conversely,
588 $(y_m, x_m)$ satisfies the constraints of the problem of which $(y_s, x_m)$
589 is the lexicographic minimum. Hence $(y_s, x_s)
\ll (y_m, x_m)$, and,
590 since $y$ is the first unknown, $y_s
\le y_m$. Hence, $y_m = y_s$.
591 There is no guarantee, however, that $x_s = x_m$.
594 % an example needed here
598 \subsubsection{Negative Unknowns and Parameters
}
600 Suppose we want to find the minimum of $f(i,j) = i-
2j$ over the square
604 (i,j)
\mid -
4 n -
20 \le i + j
\le 0 \wedge -
2 n -
10 \le i - j
\le 2 n +
10
607 represented in Figure~
\ref{iter-domain
}.
%
608 \footnote{This example was proposed and solved by Pierre Boulet.
}
612 \begin{minipage
}{0cm
}
616 \POS(-
18,
0)
\ar(
15,
0)
\POS?(
0.95)*++!D
{i
}
617 \POS(
0,-
15)
\ar(
0,
10)
\POS?(
0.95)*++!R
{j
}
618 \POS@i@=
{(-
5,
5),(
5,-
5),(-
5,-
15),(-
15,-
5),(-
5,
5)
},
{0*
\xypolyline{}}
619 \POS(-
5,
0)*
{\bullet},*++!U
{-n-
5}
620 \POS(
5,
0)*
{\bullet},*++!U
{n+
5}
621 \POS(
0,
5)*
{\bullet},*++!L
{n+
5}
622 \POS(
0,-
5)*
{\bullet},*++!L
{-n-
5}
623 \POS(-
8,
8)
\ar@
{--
}(
12,-
12)
\POS?(
0.8)*
[@
]!/_7pt/
{i+j=
0}
624 \POS(-
24,
4)
\ar@
{--
}(-
8,-
12)
\POS?(
0.2)*
[@
]!/^
7pt/
{i+j=-
4n-
20}
625 \POS(-
24,-
14)
\ar@
{--
}(-
3,
7)
\POS?(
0.2)*
[@
]!/^
7pt/
{i-j=-
2n-
10}
626 \POS(-
4,-
14)
\ar@
{--
}(
17,
7)
\POS?(
0.8)*
[@
]!/_7pt/
{i-j=
2n+
10}
631 \caption{\label{iter-domain
} Problem domain
}
635 we introduce a new unknown $f$ and the inequality $f-i+
2j
\geq
636 0$. Since we want to optimize $f$, $f$ will appear
637 as the first unknown.
639 To allow $n$ (or any other parameter) to become negative,
640 we apply the standard trick of
641 replacing $n$ by $$n = n' - n'',$$ where $n'$ and $n''$ are two new
642 parameters, both non-negative.
643 For handling possibly negative unknows, we add a number $G$ to each of the
644 unknowns that ensures that
650 are all non-negative. That is, $G$ should be such that
652 G
\ge \max(
0,-i,-j,-f).
655 is again a big parameter.
656 After replacement of $i,j,n$ and $f$ by the new variables
657 $i',j',n',n''$ and $f'$, we obtain the set
662 & f' -i' +
2j' -
2 G
\ge 0 \wedge {} \\
663 & -
4 (n'-n'') -
20 \le i' + j' -
2 G
\le 0 \wedge {} \\
664 & -
2 (n'-n'') -
10 \le i' - j'
\le 2 (n'-n'') +
10
668 which corresponds to the following input:
671 ( Solving MIN(i-
2.j) under the following constraints:
672 Unknowns may be negative.
674 f' i' j' constant G n'' n'
679 #
[ 0 1 1 20 -
2 -
4 4 ]
681 #
[ 0 1 -
1 10 0 -
2 2 ]
682 #
[ 0 -
1 1 10 0 -
2 2 ]
690 ( Solving MIN(i-
2.j) under the following constraints:
691 Unknowns may be negative.
693 f' i' j' constant G n'' n'
703 which should be read as:
705 (f',i',j') & = &
{\tt if
}\; -n''+n'-
5 \geq 0 \\
706 & &
{\tt then
} \; (G+
3n''-
3n'-
15, G+n''-n'-
5,G-n''+n'+
5) \\
707 & &
{\tt else
} \;
\bot
709 That is, in the original coordinate system:
710 \
[ (f,i,j) =
{\tt if
}\; n
\geq 5 \;
{\tt then
} \; (-
3n-
15, -n-
5, n+
5)
711 \;
{\tt else
} \;
\bot \
]
712 I.e., the minimum value for function $f$ is $-
3n-
15$, and this value
713 is reached at point $(-n-
5, n+
5)$. This minimum exists only if $n
\ge 5$;
714 otherwise, the feasible set is empty.
716 \subsubsection{Mixed Programming
}
718 A mixed program is a program in which some variables are constrained
719 to be integers while others may take rational values. Suppose for
720 instance that we have to solve:
722 S & = &
\min a x + b y,\\
723 & & A x + B y + c
\ge 0,
725 where $y$ is the vector of the integer variables. First, solve
729 & & A x + B y + c
\ge 0,
731 in rational, with $y$ as parameters. The result is a quast.
732 To each leaf $i$ is associated a linear function $f_i(y)$
733 and a set of inequalities $C_i y + d_i
\ge 0$. $T$ is equal to
734 $f_i$ when $y$ is such that the corresponding inequalities
735 are satisfied. For each $i$, solve the problem:
737 S_i & = &
\min f_i(y) + b y,\\
738 & & C_i y + d_i
\ge 0,
740 in integers. The final result is the minimum of all $S_i$.
741 Obviously, the method can accommodate parameters in the
742 constraints. The $S_i$ will be functions of these
743 parameters, and the minimum must be computed symbolically.
746 % an example is needed here
748 \section{Using the PIP Library
}
749 The PIP Library (PipLib for short) was implemented to allow the user to call PIP
750 directly from his programs, without file accesses or system calls. The
751 user only needs to link his programs with C libraries. The
752 PipLib mainly provides one function which takes as input the problem description
753 and some options, and returns a
{\tt Quast
} (see grammar
\ref{GrammarOutputData
}
754 in section
\ref{OutputData
}) corresponding to the solution. Some
755 other functions are provided for convenience reasons ; they
756 are described in section
\ref{PipLibfunc
}. Most of them require
757 some specific structures to represent the problem or
758 the solution ; these structures are described in section
\ref{PipLibdata
}.
760 \subsection{PipLib data structures description
}\label{PipLibdata
}
761 \subsubsection{PipMatrix structure
}
764 { unsigned NbRows, NbColumns ;
769 typedef struct pipmatrix PipMatrix ;
771 The
{\tt PipMatrix
} structure is devoted to represent a constraints matrix in the
772 PolyLib shape
\cite{Wild:
93}. The whole matrix is arranged row after row at the
773 {\tt p
\_Init} address.
{\tt p
} is an array of pointers in which
774 {\tt p
[i
]} points to the beginning of the i$^
{th
}$ row.
775 {\tt NbRows
} and
{\tt NbColumns
} are respectively the number of
776 rows and columns of the matrix. We use this structure to carry polyhedrons.
777 Each row corresponds to a constraint which the polyhedron must satisfy. The
778 constraint is an equality if the first element is $
0$, an inequality
779 $p(x)
\geq 0$ if the first element is $
1$. The next elements are
780 the unknown coefficients, followed by the parameter coefficients.
781 The last element is the constant factor.
782 For instance, in the problem of section
\ref{exp2
} the domain is defined by
3
793 the rows corresponding to these constraints would be:
795 # eq/in i j k m n cst
800 The context is defined by one constraint:
808 the row corresponding to this constraint would be:
813 {\tt p
\_Init\_size} is needed by the PolyLib to free the memory allocated by
814 mpz
\_init in the multiple precision release.
816 \subsubsection{PipVector structure
}
820 Entier * the_vector ;
823 typedef struct pipvector PipVector ;
825 The
{\tt PipVector
} structure represents a
{\tt Vector
}
826 as described in grammar
\ref{GrammarOutputData
} in section
\ref{OutputData
}.
827 {\tt nb
\_elements} is the number of vector elements,
{\tt the
\_vector} is
828 an array which contains the numerators of these elements and
{\tt the
\_deno}
829 is an array which contains their denominators: the i$^
{th
}$ element is
830 {\tt the
\_vector[i
]/the
\_deno[i
]}.
832 \subsubsection{PipNewparm structure
}
838 struct pipnewparm * next ;
840 typedef struct pipnewparm PipNewparm ;
842 The
{\tt PipNewparm
} structure represents a
{\tt NULL
} terminated linked list of
843 {\tt Newparm
} as described in grammar
\ref{GrammarOutputData
}
844 in section
\ref{OutputData
}. For each
{\tt Newparm
}, the rank is
{\tt rank
},
845 the vector of coefficients is pointed by
{\tt vector
}, and the denominator
846 is
{\tt deno
}.
{\tt next
} is a pointer to the next
{\tt PipNewparm
} structure.
848 \subsubsection{PipList structure
}
851 { PipVector * vector ;
852 struct piplist * next ;
854 typedef struct piplist PipList ;
856 The
{\tt PipList
} structure represents a
{\tt NULL
} terminated linked list of
857 {\tt Vector
} as described in grammar
\ref{GrammarOutputData
} in section
858 \ref{OutputData
}.
{\tt vector
} is a pointer to the vector of the current node and
859 {\tt next
} is a pointer to the next
{\tt PipList
} structure.
861 \subsubsection{PipQuast structure
}
864 { PipNewparm * newparm ;
866 PipVector * condition ;
867 struct pipquast * next_then ;
868 struct pipquast * next_else ;
869 struct pipquast * father ;
871 typedef struct pipquast PipQuast ;
873 The
{\tt PipQuast
} represents a
{\tt Quast
} as described in
874 grammar
\ref{GrammarOutputData
} in section
\ref{OutputData
}. Each
{\tt Quast
}
875 has a tree structure and begins with a list of
{\tt Newparm
}
876 (field
{\tt newparm
}). If the pointer
{\tt condition
} is not
{\tt NULL
}, the
877 list of
{\tt Newparm
} is followed by a conditional structure : if the condition
878 pointed by
{\tt condition
} is true, then the solution continues in the
879 {\tt Quast
} pointed by
{\tt next
\_then}, in the
{\tt Quast
} pointed by
880 {\tt next
\_else} otherwise. If the pointer
{\tt condition
} is
{\tt NULL
}, the
881 list of
{\tt Newparm
} is followed by a list of vectors (field
{\tt list
}).
882 For
{\tt Quast
} manipulation convenience, a pointer to the father in the tree
883 is provided (field
{\tt father
}), obviously the father of the root is
{\tt NULL
}.
886 \subsubsection{PipOptions structure
}
897 typedef struct pipoptions PipOptions ;
899 The
{\tt PipOptions
} structure contains all the possible options ruling
900 the PIP behaviour and having to be set by the user:
902 \item {\tt Nq
}: a boolean set to
1 if an integer solution is needed,
0
904 \item {\tt Verbose
}: a graduate value for debug informations:
906 \item -
1: absolute silence,
907 \item 0: relative silence,
908 \item 1: information on cuts when an integer solution is required,
909 \item 2: information on pivots and determinants,
910 \item 3: information on arrays.
912 Each option include the preceding one.
913 If
{\tt Verbose
} is not $-
1$, most of the processing will be printed in
914 a file. The file name is generated at random (by
\textit{mkstemp
}) or
915 set with environment variable DEBUG.
916 \item {\tt Simplify
}: a boolean set to
1 if some trivial quast simplifications
917 are needed (recursive elimination of degenerated patterns like
918 {\tt if \#
[...
] () ()
}),
0 otherwise,
919 \item {\tt Deepest
\_cut}: a boolean set to
1 if PIP has to use the deepest cut
920 algorithm,
0 otherwise,
921 \item {\tt Maximize
}: a boolean set to
0 if the lexicographic
922 minimum is requested, or to
1 for the lexicographic maximum. When trying to
923 find the lexicographic maximum, the method used is the one
924 presented in Section~
\ref{maximum
}: if no bigparm was set, a new (big)
925 parameter is automatically created by adding a new ending column to the
926 constraint system. This optional extra parameter is removed again from the
927 output. Unbounded solutions have their
\verb+the_deno+ set to zero.
928 Note that setting this option allows for negative solutions.
929 This may change in a future release.
930 \item \verb+Urs_parms+: controls signs of parameters:
932 \item -
1: all parameters have unrestricted sign,
933 \item 0: all parameters are non-negative.
935 \item \verb+Urs_unknowns+: controls signs of unknowns:
937 \item -
1: all unknowns have unrestricted sign,
938 \item 0: all unknowns are non-negative.
941 Every
{\tt PipOptions
} structure should be created and filled with the default
942 values by the
{\tt pip
\_options\_init} function (see section
\ref{optinit
}).
944 \subsection{PipLib functions description
}\label{PipLibfunc
}
945 \subsubsection{pip
\_solve function
}
948 ( PipMatrix * domain,
954 The
{\tt pip
\_solve} function solves a linear problem provided as input. The
955 first three parameters describe the problem that the user wants to solve.
956 The last parameter describe the options that the user has to set.
957 These parameters are:
959 \item {\tt domain
}: a pointer to the equations and inequalities system which
960 describes the unknown domain in the PolyLib constraints matrix shape,
961 \item {\tt context
}: a pointer to the equations and inequalities system satisfied
962 by the parameters context in the PolyLib constraints matrix shape
963 (it can be NULL if there is no context),
964 \item {\tt Bg
}: the column rank of the bignum (first column rank is
0), or a
965 negative value if there is no big parameter in the problem to be solved,
966 \item {\tt options
}: a pointer to a data structure containing the options
967 ruling the behaviour of PIP.
969 This function returns a pointer to a
{\tt PipQuast
} structure containing the
970 solution, it will be
{\tt NULL
} if the context is
{\tt void
}.
972 \subsubsection{pip
\_options\_init function
}\label{optinit
}
974 PipOptions * pip_options_init(void) ;
976 The
{\tt pip
\_options\_init} function allocates the memory space for a
977 {\tt PipOptions
} structure and fills it with the default values:
979 \item {\tt Nq
} $=
1$: an integer value is required,
980 \item {\tt Verbose
} $=
0$: no debug informations,
981 \item {\tt Simplify
} $=
0$: do not try to simplify solutions,
982 \item {\tt Deepest
\_cut} $=
0$: do not use deepest cut algorithm,
983 \item {\tt Maximize
} $=
0$: compute the lexicographic minimum,
984 \item \verb+Urs_parms+ $=
0$: all parameters are non-negative,
985 \item \verb+Urs_unknowns+ $=
0$: all unknowns are non-negative.
987 We strongly recommend to use this function to create and initialize any
988 {\tt PipOptions
} structure. In this way, if some new options appear in
989 the future, there will be no compatibility problems.
991 \subsubsection{pip
\_close function
}
993 void pip_close(void) ;
995 The
{\tt pip
\_close} frees the memory space that have been allocated for
996 few global variables PipLib needs. This function has to be called when
997 PipLib is no more useful in order to prevent slight memory leaks.
999 \subsubsection{pip
\_matrix\_alloc function
}
1001 PipMatrix * pip_matrix_alloc
1006 The
{\tt pip
\_matrix\_alloc} function allocates the memory space
1007 for a
{\tt PipMatrix
} structure with
{\tt nb
\_rows} rows and
{\tt nb
\_columns}
1008 columns. It fills the
{\tt Nb
\_Rows},
{\tt Nb
\_Columns} and
{\tt p
} fields
1009 and initializes the matrix entries to
0, then it returns a pointer to this
1012 \subsubsection{pip
\_matrix\_read function
}
1014 PipMatrix * pip_matrix_read(FILE *) ;
1016 The
{\tt pip
\_matrix\_read} function read a matrix from a file. It takes
1017 as input a pointer to the file it has to read (possibly
{\tt stdin
}), and
1018 returns a pointer to a
{\tt PipMatrix
} structure. The input has the following syntax:
1020 \item some optional comment lines which begin with
{\tt \#
},
1021 \item the row numbers and column numbers, possibly followed by comments,
1023 \item the matrix rows, each row must be on a single line and is possibly
1024 followed by comments.
1026 For instance, in the problem of section
\ref{exp2
} the domain is defined as follows
1028 # This is the domain
1029 3 7 #
3 lines and
7 columns
1030 1 0 -
1 0 1 0 0 # -i + m >=
0
1031 1 -
1 0 0 0 1 0 # -j + n >=
0
1032 1 1 1 -
1 0 0 0 # j + i - k >=
0
1035 \subsubsection{Printing Functions
}
1037 void pip_matrix_print(FILE *, PipMatrix *) ;
1038 void pip_vector_print(FILE *, PipVector *) ;
1039 void pip_newparm_print(FILE *, PipNewparm *, int indent) ;
1040 void pip_list_print(FILE *, PipList *, int indent) ;
1041 void pip_quast_print(FILE *, PipQuast *, int indent) ;
1042 void pip_options_print(FILE *, PipOptions *) ;
1044 There is a printing function for each structure of the PipLib. They all take as input
1045 a pointer to a file (possibly
{\tt stdout
}) and a pointer to a structure.
1046 Some of them takes as input an
1047 indent step. They print the structure contents to the file without indent if
1048 {\tt indent
} $<
0$, with an indentation step of
{\tt indent
} otherwise.
1050 \subsubsection{Memory Deallocation Functions
}
1052 void pip_matrix_free(PipMatrix *) ;
1053 void pip_vector_free(PipVector *) ;
1054 void pip_newparm_free(PipNewparm *) ;
1055 void pip_list_free(PipList *) ;
1056 void pip_quast_free(PipQuast *) ;
1057 void pip_options_free(PipOptions *) ;
1059 There is a memory deallocation function for each structure of the PipLib.
1060 They free the allocated memory for the structure.
1062 \subsection{Example
}
1063 Here is a simple example showing how one can use the PipLib, assuming that
1064 a basic installation was done. The following C program reads a domain and its
1065 context on the standard input then prints the solution on the standard output.
1066 Options are preselected : there is no bignum, we are looking for an integral
1067 solution without simplification and we don't want debug informations.
1071 # include <piplib/piplib64.h>
1074 { PipMatrix * domain, * context ;
1075 PipQuast * solution ;
1076 PipOptions * options ;
1078 domain = pip_matrix_read(stdin) ;
1079 context = pip_matrix_read(stdin) ;
1080 options = pip_options_init() ;
1082 solution = pip_solve(domain,context,-
1,options) ;
1084 pip_options_free(options) ;
1085 pip_matrix_free(domain) ;
1086 pip_matrix_free(context) ;
1088 pip_quast_print(stdout,solution,
0) ;
1092 The compilation command could be :
1094 gcc example.c -lpiplib64 -o example
1096 Supposing that the user wants to solve the problem of section
\ref{exp2
}, he
1106 And the program will print :
1120 \section{Installing PIP
}
1122 \subsection{Implementation Notes
}
1124 The main problem with any integer programming software is that, since one
1125 must distinguish between integer and rationals, all computations are
1126 to be done exactly. Rationals must be represented as quotients with
1127 an integer numerator and an integer denominator. In the preceding version,
1128 there was only one denominator for the whole tableau. The consequence
1129 was that simplifications where most unlikely, and that the integers
1130 in the tableau were growing until overflows occurred.
1132 In the present version, there is one denominator per row of the tableau.
1133 Reduction to lower terms occurs frequently, and the growth of numbers in the
1134 problem tableau is limited. As a consequence, much larger problems can be
1135 solved. This has had the unfortunate consequence that several bugs, which
1136 were beyond the domain of the old version, have now surfaced. These bugs
1137 have been corrected. As far as the author
1138 can tell, these bugs mainly gave correct
1139 results which were not in simplest form: the quast had extraneous leaves.
1140 In some cases, the result was wrong but the error was self evident: for
1141 instance, there were denominators in integer results.
1143 \subsection{License
}
1144 This program is free software; you can redistribute it and/or
1145 modify it under the terms of the GNU General Public License version
2
1146 as published by the Free Software Foundation.
1148 This program is distributed in the hope that it will be useful,
1149 but WITHOUT ANY WARRANTY; without even the implied warranty of
1150 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1151 GNU General Public License for more details.
1152 {\tt http://www.gnu.org/copyleft/gpl.html
}
1154 \subsection{Adjusting the Precision
}
1155 Pip is an all integer version of the dual simplex algorithm. As such,
1156 it has to handle integers whose size may grow exponentially as the
1157 computation proceeds. Integer overflow may occur and have to be checked.
1158 Since the hardware integer overflow exception is usually masked by
1159 the operating system or the compiler, overflow is detected by checking
1160 that a division somewhere in the algorithm, which can be proved to be
1161 exact by mathematical arguments, is indeed exact. If not, an error is
1162 reported and the computation stops.
1164 The size of the numbers to be handled depends strongly on the size of the
1165 constraint matrix and on the size of its coefficients.
1167 \subsubsection{Bounded Pip
}
1168 The precision of the integer representation in the Pip code can be
1169 adjusted at compile time by giving options to the
{\tt configure
}
1171 By giving
{\tt configure
} the option
{\tt --enable-llint
} you ask
1172 for long long int version only (
64 bits). It results in a
64 bits Pip
1174 By giving
{\tt configure
} the option
{\tt --enable-int
} you
1175 ask for int version only. It results in a
32 bits called
1176 {\tt pip32
} and a faster running time.
1178 \subsubsection{Multiple Precision Pip
}
1179 Multiple Precision Pip is built on top of the GMP library
1180 (this library is freely available at
{\tt http://www.swox.com/gmp
}).
1181 Each integer in the program is represented as a list of
32 bits numbers.
1182 All computations are done exactly, and the size of the numbers increases
1183 as needed to preserve exactness. It follows that no overflow is possible.
1184 However, when the size of numbers increases, computations get slower and
1185 slower, and memory overflow may occur in extreme cases. In well behaved
1186 problems,
32 bits are enough for the initial data, the size of intermediate
1187 results first increases up to a maximum, then decreases, and
32 bits
1188 are again enough for the results. Hence, it has been possible to keep
1189 the input format and output format of Multiple Precision Pip completely
1190 compatible with the formats of the bounded precision versions.
1192 To install Multiple Precision Pip, first install GMP according to the
1193 directions found at the above URL. Usually, the library is installed
1194 in
{\tt /usr/local/lib
}, and the header files are in
{\tt /usr/local/include
}.
1195 If this is not the case, you must adjust the Pip makefile by giving
1196 to the
{\tt configure
} shell script the option
{\tt --with-gmp=PATH
}, where
1197 {\tt PATH
} is the GMP library installation path.
1199 By giving
{\tt configure
} the option
{\tt --enable-gmp
} you ask
1200 for a GMP version only. It results in a multiple precision Pip
1204 \subsection{Building the Executable and the Library
}
1206 To build PIP, first copy the above tar file to any convenient directory.
1207 Expand the tar file using:
1209 zcat pip.tar.Z | tar xvf -
1211 You should obtain the following files:
1213 \item header files in the
{\tt include
} directory,
1214 \item C code files in the
{\tt source
} directory,
1215 \item a lot of data files
{\tt *.dat
} and of result files
{\tt *.ll
}
1216 in the
{\tt test
} directory (you should then run at least some of
1217 the
{\tt *.dat
} files and compare the results to the corresponding
1219 \item a simple example showing how to use the PipLib in the
{\tt example
} directory,
1220 \item a postscript version of the present
document,
{\tt pip.ps
} in the
1221 {\tt doc
} directory,
1222 \item files needed for compilation and installation in the PIP
1227 \subsubsection{basic installation
}
1229 The
{\tt configure
} shell script attempts to guess correct values for
1230 various system-dependent variables used during compilation. It uses
1231 those values to create a
{\tt Makefile
}.
1232 The file
{\tt configure.in
} is used to create
{\tt configure
} by a program
1233 called
{\tt autoconf
}. You only need
{\tt configure.in
} if you want to change
1234 it or regenerate
{\tt configure
} using a newer version of
{\tt autoconf
}.
1236 The simplest way to compile this package is:
1238 \item {\tt cd
} to the directory containing the package's source code and type
\linebreak
1239 {\tt ./configure
} to configure the package for your system
1240 (while running,
{\tt configure
} prints some
1241 messages telling which features it is checking for),
1243 \item type
{\tt make
} to compile the package and install the program and the
1246 \item you can remove the program binaries and object files from the
1247 source code directory by typing
{\tt make clean
}. To also remove the
1248 files that
{\tt configure
} created (so you can compile the package for
1249 a different kind of computer) type
{\tt make distclean
}.
1252 PIP and the PipLib have been successfully compiled on the following systems:
1254 \item PC's under Linux, with the
{\tt gcc
} compiler,
1255 \item PC's under Windows (Cygwin), with the
{\tt gcc
} compiler (but because
1256 of some Cygwin limitations, only
32 bits version will work and user may
1257 experience some problems when linking with PipLib),
1258 \item SparcStations, with the
{\tt gcc
} compiler.
1261 \subsubsection{optional features
}
1264 \item By default,
{\tt make
} will install the package's files in
1265 {\tt /usr/local/bin
},
\linebreak {\tt /usr/local/lib
}, etc. You can specify an
1266 installation prefix other than
{\tt /usr/local
} by giving
{\tt configure
} the
1267 option
{\tt --prefix=PATH
}.
1269 \item By default, both PIP and the PipLib are compiled and installed. By giving
1270 {\tt configure
} the option
{\tt --without-pip
} you disable the compilation and
1271 installation of PIP. By giving
{\tt configure
} the option
{\tt --without-lib
}
1272 you disable the compilation and installation of the PipLib.
1274 \item By default, both int (
32 bits) and long long int (
64 bits) versions are
1275 built. Multiple precision is built too if the GMP library is found.
1276 By giving
{\tt configure
} the option
{\tt --enable-int
} you ask for int
1277 version only. By giving
{\tt configure
} the option
{\tt --enable-llint
} you
1278 ask for long long int version only. By giving
{\tt configure
} the
1279 option
{\tt --enable-gmp
} you ask for GMP version only.
1281 \item By default, PIP looks for the GMP library in the standard path
1282 (
{\tt /usr/
} or
{\tt /usr/local/
}). If the multiple precision Pip construction
1283 is needed and if the GMP library was installed elsewhere, you must must give
1284 to the
{\tt configure
} shell script the option
{\tt --with-gmp=PATH
}, where
1285 {\tt PATH
} is the GMP library installation path. Another possibility is to
1286 give the GMP include and/or library path separately by using
1287 {\tt --with-gmp-include=PATH
} and
{\tt --with-gmp-library=PATH
}.
1290 \subsubsection{uninstallation
}
1291 You can easily remove PIP and the PipLib from your system by typing
1292 {\tt make uninstall
}.
1295 Report all bugs, problems, inaccuracies in the documentation to:
1297 {\tt Paul.Feautrier@ens-lyon.fr
}
1299 {\tt Cedric.Bastoul@prism.uvsq.fr
}
1301 Praise is also appreciated.
1303 Let the power of parametric integer programming be with you.
1306 /users/prism/pf/local/biblio/totale
%
1307 ,/users/prism/pf/local/biblio/second
%
1308 ,/users/prism/pf/local/biblio/quater
%