Dual description of polytopes.
Project description
dualdesc
Dual description for polytopes. A wrapper around pyparma, which itself wraps ppl. Mainly for easily converting between H- and V-representations. No utilities for facet enumeration, adjacencies, etc.
Usage
Constructors
This package contains one class, Polytope. Main constructors are:
Polytope.FromHalfspaces(A, b) represents the polytope defined by all points x s.t. A @ x <= b.
If there are n halfspaces and the ambient dimension is d, the shapes of these matrices are:
A:(nu, d)b:(d,)
Polytope.FromGenerators(V, R) represents the polytope defined by conv(V) + nonneg(R),
where conv is the convex combination of a set of points and nonneg is non-negative linear combinations
of a set of points, and + is Minkowski addition.
There are also Polytope.Empty(dim: int) and Polytope.Universe(dim: int) constructors.
All constructors also take a scale > 0 (default 1e5) parameter to control quantization, since ppl uses rational arithmetic.
Quantization is done as q = round(scale * x) going into ppl, and x = q / scale coming out.
Conversion
There are methods A, b = poly.get_inequalities() and V, R = poly.get_generators() which return the respective representations.
Note that PPL is lazy, and converting between representations can take a long time, so calling these methods might be slow.
Incremental construction
Incremental construction is supported via methods add_halfspace(A, b), add_point(V), and add_ray(R).
All are "vectorized", i.e. they support adding a single halfspace/point/ray, or multiple.
Since these mutate, you can also copy polytopes: poly.copy().
A simple example
The example below defines an unbounded (i.e. non-null cone part) polytope with 3 facets and 2 vertices:
import numpy as np
import dualdesc as dd
M = np.array([
[1, 0, 1], # x0 <= 1
[0, 2, 1], # 2 x1 <= 1
[1, 1, 1], # x0 + x1 <= 1
], dtype = np.float64)
A = M[:,:2]
b = M[:,-1]
poly = dd.Polytope.FromHalfspaces(A, b)
V, R = poly.to_generators()
# Vertices:
# V = [[0.5, 0.5], [1, 0]]
# Cone:
# R = [[-1, 0], [0, -1]]
Why ...?
Why not pypoman?
pypoman has more features, but only supports bounded polytopes.
Why not use pyparma directly?
It doesn't have a nice interface.
Why not use pycddlib?
pycddlib has more features (like adjacency lists), but is too low level and doesn't have a nice interface.
Why not wrap pplpy instead?
I might do this at some point, since there are issues building pyparma with Cython 3.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dualdesc-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dualdesc-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3d3fca4360ba7569632b533aab3ce8b425cb72da21bed1888f4801c2d00fd94
|
|
| MD5 |
6abde4983b963b1a4695cdf1aaa8cf1b
|
|
| BLAKE2b-256 |
c41ad4726a220fe899fb9b843c26ee1ed62d618cec94e5f675cc71da6e264fd3
|