Convex Hull Representation Conversion (cddlib, lrslib)

Convex Hull
Representation Conversion (cddlib, lrslib)
Student Seminar in Combinatorics: Mathematical Software
Niklas Pfister
October 31, 2014
1 Introduction
In this report we try to give a short overview of the representation conversion problem
of convex polyhedra with the aim of understanding the two mathematical software libraries cddlib and lrslib. The report is structured into three parts. First a short and
basic introduction is given to convex polyhedra focusing on the two possible representations. In the second part a motivation for the theoretical algorithms used in cddlib
and lrslib is presented. The final section contains an investigation of the details of the
actual implementation of the cddlib library. We conclude by illustrating some of the
functionalities of the libraries applied to examples.
1.1 Polytopes
Let us begin by recalling the definition of a convex polyhedron.
Definition 1 (convex polytope/polyhedron)
Let A ∈ Rm×d and b ∈ Rm , then a convex polyhedron P corresponding to the pair (A, b)
is defined as
P := {x ∈ Rd : Ax 6 b}.
We call P a convex polytope if P is bounded.
The pair (A, b) in the definition results in m linear inequalities, which should be
understood as halfspaces of the Rd . Therefore a convex polyhedron can be seen as the
intersection of m halfspaces. To illustrate this consider the simple example of a square
in R2 given by S = {x ∈ R2 : −1 6 x1 6 1, −1 6 x2 6 1}.
2
1.5
1
0.5
0
−0.5
−1
−1.5
−2
−2
−1.5
−1
−0.5
0
0.5
1
1.5
2
Figure 1: square in the cartesian plane
2
We can reformulate S to the form used in definition 1 using the following (A, b) pair:


 
1
0
1
−1

1
0
, b =  
A=
 0
1
1 
0 −1
1
In Figure 1.1 this example is illustrated. The dotted lines represent the halfspaces.
1.2 Minkowski-Weyl Theorem
In the example of the two dimensional square it is obvious that we could also represent
S by considering all convex combinations of the vertices of the square. In this section we
will see that this is in fact possible for all polyhedra. The following important theorem
illustrates this.
Theorem 1 (Minkowski-Weyl)
For a subset P of Rd , the following statements are equivalent:
1. P is a Polyhedron, i.e., there exist A ∈ Rm×d and b ∈ Rm such that P := {x ∈ Rd :
Ax 6 b}.
2. P is finitely generated, i.e., there exist finitely many vectors vi ’s and rj ’s such that
P = conv({v1 , . . . , vs }) + cone({r1 , . . . , rt }).
Notice that conv denotes the convex hull, i.e.
X
conv({v1 , . . . , vs }) := {x : x =
ai vi , kak1 = 1 and a > 0}
i
and cone denotes the nonnegative hull, i.e.
cone({r1 , . . . , rt }) := {x : x =
X
λi ri , λi > 0}
i
Furthermore observe that 2 can be equivalently written in matrix form:
P is finitely generated, i.e., there exists V ∈ Rd×s and R ∈ Rd×t for some s and
t such that P := {x : x = Vµ + Rλ, µ > 0, kµk1 = 1, λ > 0}.
1.3 V- and H-Representation
On the basis of the Minkowski-Weyl theorem we formulate the following definition.
Definition 2 (H- and V-Representation)
Halfspace-representation: A polyhedron has H-Representation or is given in inequality
form if it is described as in 1.
Vertex-representation: A polyhedron has V-Representation or is given in generator form
if it is described as in 2.
3
Continuing the above example we get
• S is given in H-representation by
S = {x ∈ R2 : Ax 6 b}.
• S is given in V-representation by
S = conv({(1, 1), (1, −1),
(−1, −1), (1, −1)}).
At this point we are confronted with the obvious question:
How can we convert between the two representations of a Polyhedron?
This problem of computing a (minimal) V-representation from an H-representation
or vice versa is known in literature as the representation conversion problem for polyhedra.
An important property of the representation conversion problem is, that it is in fact
essentially the same converting from the V-representation to the H-representation of a
Polyhedron as converting from the V-representation to the H-representation. In order to
prove this non-trivial statement the concept of dual polytopes needs to be utilised. The
main idea is that the H-representation of dual polyhedron can be easily converted into
the V-representation of the original polyhedron and vice versa. As this goes beyond the
scope of this short introduction to polyhedra we refer the interested reader to [3] which
gives a full account on this topic.
This allows us to reduce the representation conversion problem to finding an algorithm describing one direction of the conversion. The opposite direction is then given
using the same algorithm applied to the dual polyhedron.
2 Theoretical Algorithms
In this section we want to introduce the two algorithms that are used in the cddlib and
lrslib libraries to convert from the H-representation of polyhedron to the V-representation
from a theoretical viewpoint. Our focus will be on the double description method
which is implemented in cddlib.
2.1 Representation Conversion Problem
Let us begin by emphasizing the general property of the representation conversion
problem that the size of the output is not easy to measure given the size of the input.
For example the d-dimensional cube has 2d facets and 2d vertices. This is important
when constructing an algorithm and consequently a good algorithm should
• be sensitive to the output size. Ideally bounded by a polynomial function of both
output and input size. An algorithm satisfying this property is called output polynomial.
4
• be light on the memory usage. Ideally the required memory is bounded by a polynomial of the input size. An algorithm satisfying this property is called compact.
Unfortunately for the general representation problem no such algorithm exist. However restricted to special classes of polyhedra this is possible. One example will be the
pivoting algorithm described below which is output polynomial for polyhedra that are
non-degenerate.
Remark 1
We call a polyhedron P in Rd non-degenerate if the number of edges that end in a vertex
is d. Else we call P degenerate.
2.2 Double Description Method
This is the algorithm that is implemented in the cddlib library. It is an incremental
algorithm and turns out to be particularly efficient for very degenerate polyhedra in
low dimensions.
The underlying idea of the algorithm is to add the inequalities from the H-representation
one at a time while in each step calculating the V-representation of the polyhedron
given by the current set of inequalities.
Input: Matrix A ∈ Rm×d
Output: Matrix R ∈ Rd×n such that (A, R) are a DD pair, i.e. the columns of R
generate C(A) := {x : Ax 6 0}
General Step Let K be subset of row indices {1, 2, . . . , m} of A and let Ak be the
matrix of the rows of A indexed by K. Assume (AK , R) is a DD pair.
• If A = AK we are done.
• Else take i not in K and construct the DD pair (AK+i , R 0 ).
Notice that this algorithm only solves the simplified problem where b = 0. The set
C(A) is called polar cone.
The important step in the algorithm is the construction of R 0 . We describe this by
means of Figure 2, which shows the collection of critical points J of the polar cone
C(A 0 ). In each step the hyperplane corresponding to the newly added inequality separates the space Rd into three parts: the open upper halfspace H+ , the open lower
halfspace H− and the hyperplane H0 . Intersecting each of these with the set J leads to
the three disjoint point collections J+ , J− and J0 . The new polyhedron is now simply
the intersection of the previous polytope with the closed lower halfspace. Therefore all
points that lie in J+ have to be removed and replaced by new points in J0 . This is done
by connecting all adjacent points in J− and J+ and finding where these lines intersect
with J0 . Here two points are said to be adjacent if the common set of active inequalities
is maximal among all other pairs of points.
5
Figure 2: construction of R’
Up until now we did not mention in which order the rows in A are selected. Although the algorithm will work for any order the following example illustrates that the
computational complexity strongly depends on the choice of ordering. Figure 3 shows
the size of the intermediate sets of generators for different types of row orderings in the
calculation of the V-representation for the CCP6 polytope (a 15-dimensional polytope
with 32 facets and 368 vertices).
The following types of ordering were used:
• lexmin: refers to the lexicographic ordering of the rows in A
• random: refers to a random selection of the rows in A
• maxcutoff: refers to a dynamic selection for which in each step the row is selected
for which the set J+ is the largest
• mincutoff: is the same as maxcutoff with the difference of choosing the row for
which the set J+ is smallest
As can be seen from Figure 3 the type of ordering used in the double description
method has a huge impact on the size of the intermediate point collections. In practice
it often turns out that lexmin is the most efficient order. However there is no result
that proves that this is in fact the best ordering for any class of polyhedra. Furthermore it is also true that for polyhedra that have many redundant constraints in their
H-representation maxcutoff can be substantially more efficient.
6
Figure 3: influence of ordering
2.3 Pivoting Algorithm
A completely different approach is used in the pivoting algorithms where all vertices
of a convex polytope are visited systematically. The main idea is that the graph of a
convex polytope is connected and thus can be traced systematically until all vertices
are visited (see Figure 4).
Figure 4: pivoting algorithm
We do not describe this algorithm in detail but only remark that this algorithm can be
very efficient for non-degenerate polyhedra. In fact in this case the algorithm is output
polynomial. However for very degenerate polyhedra the tracing of the graph becomes
7
quite inefficient.
A version of such a pivoting algorithm is implemented in the lrslib library.
3 Implementations cddlib and lrslib
In this section we will take a look at the C libraries cddlib and lrslib. Both libraries
rely on the same input type which makes it possible to use both libraries in the same
program. cddlib uses the double description method while lrslib uses the pivoting
algorithm. Since these two algorithm are efficient for different types of polyhedra it is
quite useful to be able to use both algorithms simultaneously.
3.1 Input
The general input type for cddlib and lrslib is given in the following form for Hrepresentations and V-representations respectively.
Figure 5: input layout
Both libraries have functions that are able to read in text files that are given in the
format illustrated in Figure 5.
3.2 Implementation Details (cddlib)
Let us focus our attention on cddlib and look at how this library works. The library
defines many new types that are then used to perform the representation conversion.
One important such type is the dd matrixdata type. It is used to save data related to
a representation of a polyhedron given in one of the formats discussed in the previous
section. The code fragment 3.2 is taken from the ”cddtypes.h” file in which all custom
types are defined. We can see how each bit of information from the input file is saved
in a variable of a certain type. For example the actual representation would be saved in
a variable of type Amatrix. In the same file one can check that this type is simply a two
dimensional array of underlying type mytype (a type that is chosen at compile time). A
8
further example is the rowrange which is saved in a variable of type dd rowrange. One
can check that every bit of information from an input file as in Figure 5 corresponds to
a variable in the dd matrixdata type.
This gives a compact and structured form to deal with the rather lengthy input in an
intuitive fashion. Furthermore as we will see later on it allows to compile the library
using different underlying number types (mytype can be for example the GNU GMP
rational type) without making any changes to the library functions.
typedef s t r u c t dd matrixdata ∗ d d M a t r i x P t r ;
typedef s t r u c t dd matrixdata {
dd rowrange rowsize ;
dd rowset l i n s e t ;
/ ∗ a s u b s e t o f rows o f l i n e a r i t y ( i e , g e n e r a t o r s o f
l i n e a r i t y s p a c e f o r V−r e p r e s e n t a t i o n , and e q u a t i o n s
f o r H−r e p r e s e n t a t i o n . ∗ /
dd colrange c o l s i z e ;
dd RepresentationType r e p r e s e n t a t i o n ;
dd NumberType numbtype ;
dd Amatrix matrix ;
dd LPObjectiveType o b j e c t i v e ;
dd Arow rowvec ;
} dd MatrixType ;
Listing 1: cdd MatrixPtr in cddtypes.h
In order to be able to understand a simple C program that uses the cddlib library we
collect some important library functions:
void d d s e t g l o b a l c o n s t a n t s ( void )
initializes global constants such as dd zero and dd purezero
void d d f r e e g l o b a l c o n s t a n t s ( void )
frees the global constants again
d d M a t r i x P t r d d P o l y F i l e 2 M a t r i x ( f , dd ErrorType ∗ e r r )
read polyhedra data from stream f into matrixdata and return a
pointer to it
dd PolyhedraPtr dd DDMatrix2Poly ( d d M a t r i x P t r matrix , dd ErrorType ∗ e r r )
store the representation given by matrix in a polyhedra data and
generate the second representation of *poly
dd PolyhedraPtr dd DDMatrix2Poly2 ( d d M a t r i x P t r matrix , dd RowOrderType
roworder , dd ErrorType ∗ e r r )
same as above with the extra argument roworder specifying the
insertion order (eg. dd MaxCutoff, dd LexMin or dd RandomRow)
d d M a t r i x P t r d d C o p y I n e q u a l i t i e s ( dd PolyhedraPtr poly )
9
copy inequality representation pointed to by poly to matrixdata and
return a pointer
d d M a t r i x P t r dd CopyGenerators ( dd PolyhedraPtr poly )
copy generator representation pointed to by poly to matrixdata and
return a pointer
A complete list can be found in the cddlib reference manual [1].
3.3 GNU GMP
As mentioned above one of the strengths of both cddlib and lrslib is that they can both
be compiled with the GNU GMP library. This allows the conversion of polytopes with
rational representation to be converted exact without the use of approximation by floating points. Although this might slightly slow down the program it can be essential to
use this functionality as it can easily happen that calculations in the representation conversion lead to floating point errors.
3.4 Examples
To illustrate the functionalities we refer to the examples included in the cddlib library
files. Programs can be compiled in floating point arithmetic with the gcc compiler using
the following syntax
gcc filename.c -lcdd
or with GNU GMP using
gcc filename.c -lcddgmp -lgmp
Notice that if cddlib or gmplib are not in the standard directory the directories have to
be manually specified.
One basic program that can be considered is for example ”testcdd1.c” in the src
folder. The folders examples-ine and examples-ext contain example polyhedra in the
H- respectively V-representation.
To see for example what effect the ordering has on the runtime. One can change
the ”testcdd1.c” file to use the function dd DDMatrix2Poly2 function described above.
If the ordering maxcutoff is then used to calculate the V-representation for an 8 or 10
dimensional cross polytope (cross8.ine, cross10.ine) one can notice a dramatic increase
in runtime compared to the lexmin ordering.
It is also interesting to see when it can be useful to use cddlib in combination with
GMP to get exact results. One example here would be the kkd18 4.ine polytope that
cannot be converted to V-representation without the use of GMP due to numeric overflow.
10
3.5 Additional Functionality
Both cddlib and lrslib contain many more functionalities apart from the basic representation conversion. One such functionality is that they both contain an LP-solver that
can be used to solve linear programming problems such as
maximize c> x
subject
Ax 6 b
More details on additional functionalities can be found in the corresponding reference
manuals (see [1], [4]).
11
4 References
References
[1] Komei Fukuda, cddlib Reference Manual. 2008.
[2] Komei Fukuda, Frequently Asked Questions in Polyhedral Computation. 2004.
[3] Komei Fukuda, Lecture: Polyhedral Computation, Spring 2014. 2014.
[4] David Avis, User’s Guide for lrs - Version 4.2b. 2012.
12