1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
.. pplpy documentation master file
Welcome to pplpy's documentation!
=================================
Installation
------------
pplpy is available from the `Python Package Index <https://pypi.python.org/pypi/pplpy/>`_. You can hence install it with::
$ pip install pplpy
The code source can be obtained from `github <https://github.com/sagemath/pplpy>`_::
$ git clone https://github.com/sagemath/pplpy.git
Introduction
------------
.. automodule:: ppl
Using in Cython
---------------
All types from ppl are extension types and can be used with Cython. The following is a
short sample of Cython code using pplpy::
from ppl.linear_algebra cimport Variable
from ppl.constraint cimport Constraint_System
from ppl.polyhedron cimport C_Polyhedron
cdef Variable x = ppl.Variable(0)
cdef Variable y = ppl.Variable(1)
cdef Variable z = ppl.Variable(2)
cdef Constraint_System cs = Constraint_System()
cs.insert(x >= 0)
cs.insert(y >= 0)
cs.insert(x + y + z == 1)
cdef C_Polyhedron poly = C_Polyhedron(cs)
print(poly.minimized_generators())
Each extension type carries an attribute ``thisptr`` that holds a pointer to
the corresponding C++ object from ppl. Continuing the above example, one can
do::
print('dim = %lu' % poly.thisptr.space_dimension())
To avoid name collisions, the original C++ class names are prefixed with
``PPL_``, for example, the original ``Linear_Expression`` becomes
``PPL_Linear_Expression``. The Python wrapper has the same name as the original
library class, that is, just ``Linear_Expression``. All ``ppl`` declarations
are done in the ``.pxd`` file ``ppl/ppl_decl.pxd``. Only few functionalities
from ``ppl`` are exposed in ``ppl_decl.pxd``. It is also preferable to avoid
mixing C++ ``ppl`` objects with Cython ``pplpy`` extension types.
To compile a Cython extension using pplpy you need to:
- add the path of your pplpy installation to ``include_dirs``
- link with the ``ppl`` library
Here is a minimal example of a ``setup.py`` file for a unique Cython file
called ``test.pyx``::
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import ppl
extensions = [
Extension("test", ["test.pyx"], libraries=['ppl'], include_dirs=ppl.__path__, language='c++')
]
setup(ext_modules=cythonize(extensions))
Module `ppl.constraint`
-----------------------
.. automodule:: ppl.constraint
:members:
:undoc-members:
:show-inheritance:
Module `ppl.linear_algebra`
---------------------------
.. automodule:: ppl.linear_algebra
:members:
:undoc-members:
:show-inheritance:
Module `ppl.generator`
----------------------
.. automodule:: ppl.generator
:members:
:undoc-members:
:show-inheritance:
Module `ppl.polyhedron`
-----------------------
.. automodule:: ppl.polyhedron
:members:
:undoc-members:
:show-inheritance:
Module `ppl.mip_problem`
------------------------
.. automodule:: ppl.mip_problem
:members:
:undoc-members:
:show-inheritance:
Module `ppl.congruence`
-----------------------
.. automodule:: ppl.congruence
:members:
:undoc-members:
:show-inheritance:
|