{"id":16693460,"url":"https://github.com/stephane-caron/pypoman","last_synced_at":"2025-04-05T06:02:14.364Z","repository":{"id":48811292,"uuid":"129934246","full_name":"stephane-caron/pypoman","owner":"stephane-caron","description":"Python module for polyhedral geometry","archived":false,"fork":false,"pushed_at":"2025-03-03T09:43:29.000Z","size":5587,"stargazers_count":70,"open_issues_count":0,"forks_count":10,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-02T01:03:16.431Z","etag":null,"topics":["double-description","geometry","polyhedron","projection","python","vertex-enumeration"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stephane-caron.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-17T16:28:59.000Z","updated_at":"2025-03-21T10:04:46.000Z","dependencies_parsed_at":"2023-01-22T07:15:19.339Z","dependency_job_id":"ef4740bd-8d32-4473-92f7-4ad1095d489a","html_url":"https://github.com/stephane-caron/pypoman","commit_stats":{"total_commits":160,"total_committers":3,"mean_commits":"53.333333333333336","dds":0.31875,"last_synced_commit":"e22a7a77ac6a04828c3aef74824377dde71e44ea"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephane-caron%2Fpypoman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephane-caron%2Fpypoman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephane-caron%2Fpypoman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephane-caron%2Fpypoman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephane-caron","download_url":"https://codeload.github.com/stephane-caron/pypoman/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294514,"owners_count":20915340,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["double-description","geometry","polyhedron","projection","python","vertex-enumeration"],"created_at":"2024-10-12T16:30:39.561Z","updated_at":"2025-04-05T06:02:14.337Z","avatar_url":"https://github.com/stephane-caron.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polyhedron manipulation in Python\n\n[![Build](https://img.shields.io/github/actions/workflow/status/stephane-caron/pypoman/ci.yml?branch=main)](https://github.com/stephane-caron/pypoman/actions)\n[![Documentation](https://img.shields.io/github/actions/workflow/status/stephane-caron/pypoman/docs.yml?branch=main\u0026label=docs)](https://stephane-caron.github.io/pypoman/)\n[![Coverage](https://coveralls.io/repos/github/stephane-caron/pypoman/badge.svg?branch=main)](https://coveralls.io/github/stephane-caron/pypoman?branch=main)\n[![PyPI version](https://img.shields.io/pypi/v/pypoman?color=blue)](https://pypi.org/project/pypoman/)\n[![PyPI downloads](https://img.shields.io/pypi/dm/pypoman?color=blue)](https://pypistats.org/packages/pypoman)\n\nThis library interfaces common operations over [convex polyhedra](https://en.wikipedia.org/wiki/Convex_polyhedron) such as [polytope projection](https://stephane-caron.github.io/pypoman/index.html#module-pypoman.projection) and [vertex enumeration](https://stephane-caron.github.io/pypoman/index.html#module-pypoman.duality). Check out the [documentation](https://stephane-caron.github.io/pypoman/) for details.\n\n## Installation\n\n### Using conda\n\nInstall the cdd dependency first:\n\n```console\n$ conda install cddlib\n```\n\nThen install `pypoman` from PyPI:\n\n```console\n$ pip install pypoman\n```\n\nIt won't need to build cdd from source as it is installed from conda-forge.\n\n### Building from source\n\nInstall system packages for cdd and GLPK, for instance on Debian-based Linux distributions:\n\n```console\n$ sudo apt-get install cython libcdd-dev libglpk-dev libgmp3-dev\n```\n\nYou can then install the library from PyPI as follows. This approach will likely require building cdd from source.\n\n```console\n$ pip install pypoman\n```\n\nSome functions, such as point-polytope projection and polygon intersection, are optional and not installed by default. To enable all of them, run:\n\n```console\n$ pip install pypoman[all]\n```\n\n## Examples\n\n### Vertex enumeration\n\nWe can compute the list of vertices of a polytope described in halfspace representation by $A x \\leq b$:\n\n```python\nimport numpy as np\nfrom pypoman import compute_polytope_vertices\n\nA = np.array([\n    [-1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],\n    [0, -1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],\n    [0,  0, -1,  0,  0,  0,  0,  0,  0,  0,  0,  0],\n    [0,  0,  0, -1,  0,  0,  0,  0,  0,  0,  0,  0],\n    [0,  0,  0,  0, -1,  0,  0,  0,  0,  0,  0,  0],\n    [0,  0,  0,  0,  0, -1,  0,  0,  0,  0,  0,  0],\n    [0,  0,  0,  0,  0,  0, -1,  0,  0,  0,  0,  0],\n    [0,  0,  0,  0,  0,  0,  0, -1,  0,  0,  0,  0],\n    [0,  0,  0,  0,  0,  0,  0,  0, -1,  0,  0,  0],\n    [0,  0,  0,  0,  0,  0,  0,  0,  0, -1,  0,  0],\n    [0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1,  0],\n    [0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1],\n    [1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0],\n    [0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,  0],\n    [0,  0,  0,  0,  0,  0,  1,  1,  1,  0,  0,  0],\n    [0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1],\n    [1,  0,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0],\n    [0,  1,  0,  0,  1,  0,  0,  1,  0,  0,  1,  0],\n    [0,  0,  1,  0,  0,  1,  0,  0,  1,  0,  0,  1]])\nb = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 2, 2, 1, 2, 3])\n\nvertices = compute_polytope_vertices(A, b)\n```\n\n### Halfspace enumeration\n\nThe other way round, assume we know the vertices of a polytope, and want to get its halfspace representation $A x \\leq b$.\n\n```python\nimport numpy as np\nfrom pypoman import compute_polytope_halfspaces\n\nvertices = map(\n    np.array,\n    [[1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1], [0, 1, 1]],\n)\n\nA, b = compute_polytope_halfspaces(vertices)\n```\n\n### Polytope projection\n\nLet us project an $n$-dimensional polytope $A x \\leq b$ over $x = [x_1\\ \\ldots\\ x_n]$ onto its first two coordinates $proj(x) = [x_1 x_2]$:\n\n```python\nfrom numpy import array, eye, ones, vstack, zeros\nfrom pypoman import plot_polygon, project_polytope\n\nn = 10  # dimension of the original polytope\np = 2   # dimension of the projected polytope\n\n# Original polytope:\n# - inequality constraints: \\forall i, |x_i| \u003c= 1\n# - equality constraint: sum_i x_i = 0\nA = vstack([+eye(n), -eye(n)])\nb = ones(2 * n)\nC = ones(n).reshape((1, n))\nd = array([0])\nineq = (A, b)  # A * x \u003c= b\neq = (C, d)    # C * x == d\n\n# Projection is proj(x) = [x_0 x_1]\nE = zeros((p, n))\nE[0, 0] = 1.\nE[1, 1] = 1.\nf = zeros(p)\nproj = (E, f)  # proj(x) = E * x + f\n\nvertices = project_polytope(proj, ineq, eq, method='bretl')\n```\n\nWe can then plot the projected polytope:\n\n```python\nimport pylab\n\npylab.ion()\npylab.figure()\nplot_polygon(vertices)\n```\n\n## See also\n\n- A short introduction to [Polyhedra and polytopes](https://scaron.info/blog/polyhedra-and-polytopes.html)\n- Komei Fukuda's [Frequently Asked Questions in Polyhedral Computation](https://www.inf.ethz.ch/personal/fukudak/polyfaq/polyfaq.html)\n- The [Polyhedron](http://doc.sagemath.org/html/en/reference/discrete_geometry/sage/geometry/polyhedron/constructor.html) class in [Sage](http://www.sagemath.org/)\n- [StabiliPy](https://github.com/haudren/stabilipy): a Python package implementing a more general recursive method for polytope projection\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephane-caron%2Fpypoman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephane-caron%2Fpypoman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephane-caron%2Fpypoman/lists"}