passagemath-cddlib

raw JSON →
10.8.4 verified Fri May 01 auth: no python

Python binding for cddlib, implementing double description method for convex polyhedra (V- and H-representation). Part of the passagemath ecosystem. Current version 10.8.4, requires Python >=3.11 <3.15. Release cadence is irregular, following the passagemath umbrella releases.

pip install passagemath-cddlib
error ImportError: No module named 'cdd'
cause The import 'import cdd' is used instead of the correct namespaced import.
fix
Use: from passagemath.cddlib import cdd
error ValueError: invalid RepType. Use RepType.GENERATOR for V-representation, RepType.INEQUALITY for H-representation.
cause The matrix rep_type must be set explicitly before constructing Polyhedron, or the format is wrong.
fix
Before creating Polyhedron, set mat.rep_type = cdd.RepType.GENERATOR (or INEQUALITY) correctly.
error passagemath.cddlib.cdd.LinIndepError: number of rows less than number of columns
cause The input matrix has too few rows (inequalities) or the dimension is incorrect. The cdd library requires at least as many rows as dimension.
fix
Ensure your matrix has at least as many rows as the ambient dimension (including constant column). For example, for 2D, at least 2 rows.
gotcha The cddlib library uses a non-standard matrix format: each row is [b, -A] for inequality Ax + b >= 0. Use cdd.matrix_from_array() and set rep_type. For H-representation each row is [constant, -coefficients].
fix Always consult the renorm module or carefully convert your inequalities to the cdd format. Use the matrix_from_array helper and manually set rep_type.
gotcha The passagemath ecosystem may conflict with the standalone 'cdd' package if installed. Both provide a 'cdd' module, but passagemath-cddlib uses a namespaced import.
fix Do not install both 'cdd' and 'passagemath-cddlib' in the same environment. Use only 'passagemath-cddlib' and import from 'passagemath.cddlib.cdd'.
deprecated Older versions (<10.0) used the package 'cdd' directly, but that package is now separate and unmaintained. Migrate to 'passagemath-cddlib' for updates.
fix Uninstall 'cdd' and install 'passagemath-cddlib'. Change imports to 'from passagemath.cddlib import cdd'.

Create a polyhedron from V-representation and print its H-representation. Uses the cddlib matrix convention.

from passagemath.cddlib import cdd
import os
# Create a polytope from H-representation (inequalities)
# Example: nonnegative orthant in 2D
mat = [
    [1.0, 0.0],  # 1*x >= 0? Actually line: 1*x + 0*y >= 0
    [0.0, 1.0],  # 0*x + 1*y >= 0
]
lin = [1, 1]  # all inequalities are linear (not inequalities but equalities? use linearity)
# Actually define inequalities: x >= 0, y >= 0
# But cdd uses row major: each row is [b, -A]
# For standard form Ax <= b, we need to convert.
# Let's use a simpler example: simplex
# Represent the triangle with vertices (0,0), (1,0), (0,1) in V-rep
V = cdd.matrix_from_array([
    [0, 0, 1],  # (0,0) with 1 for inhomogeneous
    [1, 0, 1],
    [0, 1, 1]
])
V.rep_type = cdd.RepType.GENERATOR
poly = cdd.Polyhedron(V)
# Check H-representation
H = poly.get_inequalities()
print('H-representation:')
print(H.array)