This Python package provides a wrapper to the C++ Parma Polyhedra Library (PPL).
The whole package started as a fork of a tiny part of the Sage software.
The names of objects and methods are the same as in the library:
>>> import ppl
>>> x = ppl.Variable(0)
>>> y = ppl.Variable(1)
>>> z = ppl.Variable(2)
>>> cs = ppl.Constraint_System()
>>> cs.insert(x >= 0)
>>> cs.insert(y >= 0)
>>> cs.insert(z >= 0)
>>> cs.insert(x + y + z == 1)
>>> poly = ppl.C_Polyhedron(cs)
>>> poly.minimized_generators()
Generator_System {point(1/1, 0/1, 0/1), point(0/1, 1/1, 0/1), point(0/1, 0/1, 1/1)}The available objects and functions from the ppl Python module are:
- Variable, Variables_Set, Linear_Expression (defined in ppl.linear_algebra)
- MIP_Problem (defined in ppl.mip_problem)
- C_Polyhedron, NNC_Polyhedron (defined in ppl.polyhedron)
- Generator, Generator_System, Poly_Gen_Relation, point, closure_point, ray, line (defined in ppl.generator)
- Constraint, Constraint_System, Poly_Con_Relation, inequality, equation, strict_inequality (defined in ppl.constraint)
The project is available at Python Package Index and can be installed with pip:
$ pip install pplpy
Note that if you have gmp and ppl installed in a non standard directory (e.g. you use brew on MacOSX) then you need to set appropriately the variables CFLAGS before calling pip. For example:
$ export CFLAGS="-I/path/to/gmp/include/ -L/path/to/gmp/lib/ -I/path/to/ppl/include/ -L/path/to/ppl/lib $CFLAGS" $ pip install pplpy
All Python classes from pplpy are extension types and can be used with Cython. Each extension type carries an attribute thisptr that holds a pointer to the corresponding C++ object from ppl.
A complete example is provided in examples/cython_example.pyx. To compile it, Cython needs the include paths of pplpy, PPL, GMP, cysignals and gmpy2; see examples/meson.build.
You can find the latest version of the source code on github: https://github.com/sagemath/pplpy
An online version of the documentation is available at https://www.sagemath.org/pplpy/
We recommend you install pixi to provide all the dependencies for pplpy. Once installed, git clone this repository and then:
$ pixi run test # to run the test suite and the Cython example $ pixi run lint # to run cython-lint $ pixi run doc # to build the documentation into html/pplpy $ pixi run python # to spawn a Python repl where you can "import ppl"
Changes to the Cython sources are automatically recompiled in all of the above
on the internal import ppl.
pplpy is distributed under the terms of the GNU General Public License (GPL) published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. See http://www.gnu.org/licenses/.