passagemath-polyhedra 10.6.31rc3__cp314-cp314-musllinux_1_2_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of passagemath-polyhedra might be problematic. Click here for more details.
- passagemath_polyhedra-10.6.31rc3.dist-info/METADATA +367 -0
- passagemath_polyhedra-10.6.31rc3.dist-info/METADATA.bak +369 -0
- passagemath_polyhedra-10.6.31rc3.dist-info/RECORD +208 -0
- passagemath_polyhedra-10.6.31rc3.dist-info/WHEEL +5 -0
- passagemath_polyhedra-10.6.31rc3.dist-info/top_level.txt +2 -0
- passagemath_polyhedra.libs/libgcc_s-0cd532bd.so.1 +0 -0
- passagemath_polyhedra.libs/libgmp-0e7fc84e.so.10.5.0 +0 -0
- passagemath_polyhedra.libs/libgomp-8949ffbe.so.1.0.0 +0 -0
- passagemath_polyhedra.libs/libstdc++-5d72f927.so.6.0.33 +0 -0
- sage/all__sagemath_polyhedra.py +50 -0
- sage/game_theory/all.py +8 -0
- sage/game_theory/catalog.py +6 -0
- sage/game_theory/catalog_normal_form_games.py +923 -0
- sage/game_theory/cooperative_game.py +844 -0
- sage/game_theory/matching_game.py +1181 -0
- sage/game_theory/normal_form_game.py +2697 -0
- sage/game_theory/parser.py +275 -0
- sage/geometry/all__sagemath_polyhedra.py +22 -0
- sage/geometry/cone.py +6940 -0
- sage/geometry/cone_catalog.py +847 -0
- sage/geometry/cone_critical_angles.py +1027 -0
- sage/geometry/convex_set.py +1119 -0
- sage/geometry/fan.py +3743 -0
- sage/geometry/fan_isomorphism.py +389 -0
- sage/geometry/fan_morphism.py +1884 -0
- sage/geometry/hasse_diagram.py +202 -0
- sage/geometry/hyperplane_arrangement/affine_subspace.py +390 -0
- sage/geometry/hyperplane_arrangement/all.py +1 -0
- sage/geometry/hyperplane_arrangement/arrangement.py +3895 -0
- sage/geometry/hyperplane_arrangement/check_freeness.py +145 -0
- sage/geometry/hyperplane_arrangement/hyperplane.py +773 -0
- sage/geometry/hyperplane_arrangement/library.py +825 -0
- sage/geometry/hyperplane_arrangement/ordered_arrangement.py +642 -0
- sage/geometry/hyperplane_arrangement/plot.py +520 -0
- sage/geometry/integral_points.py +35 -0
- sage/geometry/integral_points_generic_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/integral_points_generic_dense.pyx +7 -0
- sage/geometry/lattice_polytope.py +5894 -0
- sage/geometry/linear_expression.py +773 -0
- sage/geometry/newton_polygon.py +767 -0
- sage/geometry/point_collection.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/point_collection.pyx +1008 -0
- sage/geometry/polyhedral_complex.py +2616 -0
- sage/geometry/polyhedron/all.py +8 -0
- sage/geometry/polyhedron/backend_cdd.py +460 -0
- sage/geometry/polyhedron/backend_cdd_rdf.py +231 -0
- sage/geometry/polyhedron/backend_field.py +347 -0
- sage/geometry/polyhedron/backend_normaliz.py +2503 -0
- sage/geometry/polyhedron/backend_number_field.py +168 -0
- sage/geometry/polyhedron/backend_polymake.py +765 -0
- sage/geometry/polyhedron/backend_ppl.py +582 -0
- sage/geometry/polyhedron/base.py +1206 -0
- sage/geometry/polyhedron/base0.py +1444 -0
- sage/geometry/polyhedron/base1.py +886 -0
- sage/geometry/polyhedron/base2.py +812 -0
- sage/geometry/polyhedron/base3.py +1845 -0
- sage/geometry/polyhedron/base4.py +1262 -0
- sage/geometry/polyhedron/base5.py +2700 -0
- sage/geometry/polyhedron/base6.py +1741 -0
- sage/geometry/polyhedron/base7.py +997 -0
- sage/geometry/polyhedron/base_QQ.py +1258 -0
- sage/geometry/polyhedron/base_RDF.py +98 -0
- sage/geometry/polyhedron/base_ZZ.py +934 -0
- sage/geometry/polyhedron/base_mutable.py +215 -0
- sage/geometry/polyhedron/base_number_field.py +122 -0
- sage/geometry/polyhedron/cdd_file_format.py +155 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/all.py +1 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/base.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd +76 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx +3859 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pxd +39 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx +1038 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/conversions.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pxd +9 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx +501 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_data_structure.pxd +207 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pxd +102 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx +2274 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pxd +370 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pyx +84 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pxd +31 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx +587 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pxd +52 -0
- sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx +560 -0
- sage/geometry/polyhedron/constructor.py +773 -0
- sage/geometry/polyhedron/double_description.py +753 -0
- sage/geometry/polyhedron/double_description_inhomogeneous.py +564 -0
- sage/geometry/polyhedron/face.py +1060 -0
- sage/geometry/polyhedron/generating_function.py +1810 -0
- sage/geometry/polyhedron/lattice_euclidean_group_element.py +178 -0
- sage/geometry/polyhedron/library.py +3502 -0
- sage/geometry/polyhedron/misc.py +121 -0
- sage/geometry/polyhedron/modules/all.py +1 -0
- sage/geometry/polyhedron/modules/formal_polyhedra_module.py +155 -0
- sage/geometry/polyhedron/palp_database.py +447 -0
- sage/geometry/polyhedron/parent.py +1279 -0
- sage/geometry/polyhedron/plot.py +1986 -0
- sage/geometry/polyhedron/ppl_lattice_polygon.py +556 -0
- sage/geometry/polyhedron/ppl_lattice_polytope.py +1257 -0
- sage/geometry/polyhedron/representation.py +1723 -0
- sage/geometry/pseudolines.py +515 -0
- sage/geometry/relative_interior.py +445 -0
- sage/geometry/toric_plotter.py +1103 -0
- sage/geometry/triangulation/all.py +2 -0
- sage/geometry/triangulation/base.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/triangulation/base.pyx +963 -0
- sage/geometry/triangulation/data.h +147 -0
- sage/geometry/triangulation/data.pxd +4 -0
- sage/geometry/triangulation/element.py +914 -0
- sage/geometry/triangulation/functions.h +10 -0
- sage/geometry/triangulation/functions.pxd +4 -0
- sage/geometry/triangulation/point_configuration.py +2256 -0
- sage/geometry/triangulation/triangulations.h +49 -0
- sage/geometry/triangulation/triangulations.pxd +7 -0
- sage/geometry/voronoi_diagram.py +319 -0
- sage/interfaces/all__sagemath_polyhedra.py +1 -0
- sage/interfaces/polymake.py +2028 -0
- sage/numerical/all.py +13 -0
- sage/numerical/all__sagemath_polyhedra.py +11 -0
- sage/numerical/backends/all.py +1 -0
- sage/numerical/backends/all__sagemath_polyhedra.py +1 -0
- sage/numerical/backends/cvxopt_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/cvxopt_backend.pyx +1006 -0
- sage/numerical/backends/cvxopt_backend_test.py +19 -0
- sage/numerical/backends/cvxopt_sdp_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/cvxopt_sdp_backend.pyx +382 -0
- sage/numerical/backends/cvxpy_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/cvxpy_backend.pxd +41 -0
- sage/numerical/backends/cvxpy_backend.pyx +934 -0
- sage/numerical/backends/cvxpy_backend_test.py +13 -0
- sage/numerical/backends/generic_backend_test.py +24 -0
- sage/numerical/backends/interactivelp_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/interactivelp_backend.pxd +36 -0
- sage/numerical/backends/interactivelp_backend.pyx +1231 -0
- sage/numerical/backends/interactivelp_backend_test.py +12 -0
- sage/numerical/backends/logging_backend.py +391 -0
- sage/numerical/backends/matrix_sdp_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/matrix_sdp_backend.pxd +15 -0
- sage/numerical/backends/matrix_sdp_backend.pyx +478 -0
- sage/numerical/backends/ppl_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/ppl_backend.pyx +1126 -0
- sage/numerical/backends/ppl_backend_test.py +13 -0
- sage/numerical/backends/scip_backend.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/backends/scip_backend.pxd +22 -0
- sage/numerical/backends/scip_backend.pyx +1289 -0
- sage/numerical/backends/scip_backend_test.py +13 -0
- sage/numerical/interactive_simplex_method.py +5338 -0
- sage/numerical/knapsack.py +665 -0
- sage/numerical/linear_functions.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/linear_functions.pxd +31 -0
- sage/numerical/linear_functions.pyx +1648 -0
- sage/numerical/linear_tensor.py +470 -0
- sage/numerical/linear_tensor_constraints.py +448 -0
- sage/numerical/linear_tensor_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/linear_tensor_element.pxd +6 -0
- sage/numerical/linear_tensor_element.pyx +459 -0
- sage/numerical/mip.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/mip.pxd +40 -0
- sage/numerical/mip.pyx +3667 -0
- sage/numerical/sdp.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/sdp.pxd +39 -0
- sage/numerical/sdp.pyx +1433 -0
- sage/rings/all__sagemath_polyhedra.py +3 -0
- sage/rings/polynomial/all__sagemath_polyhedra.py +10 -0
- sage/rings/polynomial/omega.py +982 -0
- sage/schemes/all__sagemath_polyhedra.py +2 -0
- sage/schemes/toric/all.py +10 -0
- sage/schemes/toric/chow_group.py +1248 -0
- sage/schemes/toric/divisor.py +2082 -0
- sage/schemes/toric/divisor_class.cpython-314-x86_64-linux-musl.so +0 -0
- sage/schemes/toric/divisor_class.pyx +322 -0
- sage/schemes/toric/fano_variety.py +1606 -0
- sage/schemes/toric/homset.py +650 -0
- sage/schemes/toric/ideal.py +451 -0
- sage/schemes/toric/library.py +1322 -0
- sage/schemes/toric/morphism.py +1958 -0
- sage/schemes/toric/points.py +1032 -0
- sage/schemes/toric/sheaf/all.py +1 -0
- sage/schemes/toric/sheaf/constructor.py +302 -0
- sage/schemes/toric/sheaf/klyachko.py +921 -0
- sage/schemes/toric/toric_subscheme.py +905 -0
- sage/schemes/toric/variety.py +3460 -0
- sage/schemes/toric/weierstrass.py +1078 -0
- sage/schemes/toric/weierstrass_covering.py +457 -0
- sage/schemes/toric/weierstrass_higher.py +288 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.info +10 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v03 +0 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v04 +0 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v05 +1 -0
- sage_wheels/share/reflexive_polytopes/Full2d/zzdb.v06 +1 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.info +22 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v04 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v05 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v06 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v07 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v08 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v09 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v10 +0 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v11 +1 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v12 +1 -0
- sage_wheels/share/reflexive_polytopes/Full3d/zzdb.v13 +1 -0
- sage_wheels/share/reflexive_polytopes/reflexive_polytopes_2d +80 -0
- sage_wheels/share/reflexive_polytopes/reflexive_polytopes_3d +37977 -0
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-polyhedra
|
|
2
|
+
"""
|
|
3
|
+
The polymake backend for polyhedral computations
|
|
4
|
+
|
|
5
|
+
.. NOTE::
|
|
6
|
+
|
|
7
|
+
This backend requires polymake.
|
|
8
|
+
To install it, type :code:`sage -i polymake` in the terminal.
|
|
9
|
+
|
|
10
|
+
AUTHORS:
|
|
11
|
+
|
|
12
|
+
- Matthias Köppe (2017-03): initial version
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
#*****************************************************************************
|
|
16
|
+
# Copyright (C) 2017 Matthias Köppe <mkoeppe at math.ucdavis.edu>
|
|
17
|
+
#
|
|
18
|
+
# This program is free software: you can redistribute it and/or modify
|
|
19
|
+
# it under the terms of the GNU General Public License as published by
|
|
20
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
21
|
+
# (at your option) any later version.
|
|
22
|
+
# http://www.gnu.org/licenses/
|
|
23
|
+
#*****************************************************************************
|
|
24
|
+
|
|
25
|
+
import itertools
|
|
26
|
+
|
|
27
|
+
from sage.structure.element import Element
|
|
28
|
+
|
|
29
|
+
from .base import Polyhedron_base
|
|
30
|
+
from .base_QQ import Polyhedron_QQ
|
|
31
|
+
from .base_ZZ import Polyhedron_ZZ
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#########################################################################
|
|
35
|
+
class Polyhedron_polymake(Polyhedron_base):
|
|
36
|
+
"""
|
|
37
|
+
Polyhedra with polymake.
|
|
38
|
+
|
|
39
|
+
INPUT:
|
|
40
|
+
|
|
41
|
+
- ``parent`` -- :class:`~sage.geometry.polyhedron.parent.Polyhedra`
|
|
42
|
+
the parent
|
|
43
|
+
|
|
44
|
+
- ``Vrep`` -- list ``[vertices, rays, lines]`` or ``None``; the
|
|
45
|
+
V-representation of the polyhedron. If ``None``, the polyhedron
|
|
46
|
+
is determined by the H-representation.
|
|
47
|
+
|
|
48
|
+
- ``Hrep`` -- list ``[ieqs, eqns]`` or ``None``; the
|
|
49
|
+
H-representation of the polyhedron. If ``None``, the polyhedron
|
|
50
|
+
is determined by the V-representation.
|
|
51
|
+
|
|
52
|
+
- ``polymake_polytope`` -- a polymake polytope object
|
|
53
|
+
|
|
54
|
+
Only one of ``Vrep``, ``Hrep``, or ``polymake_polytope`` can be different
|
|
55
|
+
from ``None``.
|
|
56
|
+
|
|
57
|
+
EXAMPLES::
|
|
58
|
+
|
|
59
|
+
sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], rays=[(1,1)], # optional - jupymake
|
|
60
|
+
....: lines=[], backend='polymake')
|
|
61
|
+
sage: TestSuite(p).run() # optional - jupymake
|
|
62
|
+
|
|
63
|
+
A lower-dimensional affine cone; we test that there are no mysterious
|
|
64
|
+
inequalities coming in from the homogenization::
|
|
65
|
+
|
|
66
|
+
sage: P = Polyhedron(vertices=[(1, 1)], rays=[(0, 1)], # optional - jupymake
|
|
67
|
+
....: backend='polymake')
|
|
68
|
+
sage: P.n_inequalities() # optional - jupymake
|
|
69
|
+
1
|
|
70
|
+
sage: P.equations() # optional - jupymake
|
|
71
|
+
(An equation (1, 0) x - 1 == 0,)
|
|
72
|
+
|
|
73
|
+
The empty polyhedron::
|
|
74
|
+
|
|
75
|
+
sage: Polyhedron(eqns=[[1, 0, 0]], backend='polymake') # optional - jupymake
|
|
76
|
+
The empty polyhedron in QQ^2
|
|
77
|
+
|
|
78
|
+
It can also be obtained differently::
|
|
79
|
+
|
|
80
|
+
sage: # optional - jupymake
|
|
81
|
+
sage: P=Polyhedron(ieqs=[[-2, 1, 1], [-3, -1, -1], [-4, 1, -2]],
|
|
82
|
+
....: backend='polymake')
|
|
83
|
+
sage: P
|
|
84
|
+
The empty polyhedron in QQ^2
|
|
85
|
+
sage: P.Vrepresentation()
|
|
86
|
+
()
|
|
87
|
+
sage: P.Hrepresentation()
|
|
88
|
+
(An equation -1 == 0,)
|
|
89
|
+
|
|
90
|
+
The full polyhedron::
|
|
91
|
+
|
|
92
|
+
sage: Polyhedron(eqns=[[0, 0, 0]], backend='polymake') # optional - jupymake
|
|
93
|
+
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex and 2 lines
|
|
94
|
+
sage: Polyhedron(ieqs=[[0, 0, 0]], backend='polymake') # optional - jupymake
|
|
95
|
+
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex and 2 lines
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
Quadratic fields work::
|
|
99
|
+
|
|
100
|
+
sage: V = polytopes.dodecahedron().vertices_list() # needs sage.groups sage.rings.number_field
|
|
101
|
+
sage: Polyhedron(vertices=V, backend='polymake') # optional - jupymake, needs sage.groups sage.rings.number_field
|
|
102
|
+
A 3-dimensional polyhedron
|
|
103
|
+
in (Number Field in sqrt5 with defining polynomial x^2 - 5
|
|
104
|
+
with sqrt5 = 2.236067977499790?)^3
|
|
105
|
+
defined as the convex hull of 20 vertices
|
|
106
|
+
|
|
107
|
+
TESTS:
|
|
108
|
+
|
|
109
|
+
Tests copied from various methods in :mod:`sage.geometry.polyhedron.base`::
|
|
110
|
+
|
|
111
|
+
sage: p = Polyhedron(vertices = [[1,0,0], [0,1,0], [0,0,1]], # optional - jupymake
|
|
112
|
+
....: backend='polymake')
|
|
113
|
+
sage: p.n_equations() # optional - jupymake
|
|
114
|
+
1
|
|
115
|
+
sage: p.n_inequalities() # optional - jupymake
|
|
116
|
+
3
|
|
117
|
+
|
|
118
|
+
sage: p = Polyhedron(vertices = [[t,t^2,t^3] for t in range(6)], # optional - jupymake
|
|
119
|
+
....: backend='polymake')
|
|
120
|
+
sage: p.n_facets() # optional - jupymake
|
|
121
|
+
8
|
|
122
|
+
|
|
123
|
+
sage: p = Polyhedron(vertices = [[1,0],[0,1],[1,1]], rays=[[1,1]], # optional - jupymake
|
|
124
|
+
....: backend='polymake')
|
|
125
|
+
sage: p.n_vertices() # optional - jupymake
|
|
126
|
+
2
|
|
127
|
+
|
|
128
|
+
sage: p = Polyhedron(vertices = [[1,0],[0,1]], rays=[[1,1]], # optional - jupymake
|
|
129
|
+
....: backend='polymake')
|
|
130
|
+
sage: p.n_rays() # optional - jupymake
|
|
131
|
+
1
|
|
132
|
+
|
|
133
|
+
sage: p = Polyhedron(vertices = [[0,0]], rays=[[0,1],[0,-1]], # optional - jupymake
|
|
134
|
+
....: backend='polymake')
|
|
135
|
+
sage: p.n_lines() # optional - jupymake
|
|
136
|
+
1
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
def _is_zero(self, x):
|
|
140
|
+
"""
|
|
141
|
+
Test whether ``x`` is zero.
|
|
142
|
+
|
|
143
|
+
INPUT:
|
|
144
|
+
|
|
145
|
+
- ``x`` -- a number in the base ring
|
|
146
|
+
|
|
147
|
+
OUTPUT: boolean
|
|
148
|
+
|
|
149
|
+
EXAMPLES::
|
|
150
|
+
|
|
151
|
+
sage: p = Polyhedron([(0,0)], backend='polymake') # optional - jupymake
|
|
152
|
+
sage: p._is_zero(0) # optional - jupymake
|
|
153
|
+
True
|
|
154
|
+
sage: p._is_zero(1/100000) # optional - jupymake
|
|
155
|
+
False
|
|
156
|
+
"""
|
|
157
|
+
return x == 0
|
|
158
|
+
|
|
159
|
+
def _is_nonneg(self, x):
|
|
160
|
+
"""
|
|
161
|
+
Test whether ``x`` is nonnegative.
|
|
162
|
+
|
|
163
|
+
INPUT:
|
|
164
|
+
|
|
165
|
+
- ``x`` -- a number in the base ring
|
|
166
|
+
|
|
167
|
+
OUTPUT: boolean
|
|
168
|
+
|
|
169
|
+
EXAMPLES::
|
|
170
|
+
|
|
171
|
+
sage: p = Polyhedron([(0,0)], backend='polymake') # optional - jupymake
|
|
172
|
+
sage: p._is_nonneg(1) # optional - jupymake
|
|
173
|
+
True
|
|
174
|
+
sage: p._is_nonneg(-1/100000) # optional - jupymake
|
|
175
|
+
False
|
|
176
|
+
"""
|
|
177
|
+
return x >= 0
|
|
178
|
+
|
|
179
|
+
def _is_positive(self, x):
|
|
180
|
+
"""
|
|
181
|
+
Test whether ``x`` is positive.
|
|
182
|
+
|
|
183
|
+
INPUT:
|
|
184
|
+
|
|
185
|
+
- ``x`` -- a number in the base ring
|
|
186
|
+
|
|
187
|
+
OUTPUT: boolean
|
|
188
|
+
|
|
189
|
+
EXAMPLES::
|
|
190
|
+
|
|
191
|
+
sage: p = Polyhedron([(0,0)], backend='polymake') # optional - jupymake
|
|
192
|
+
sage: p._is_positive(1) # optional - jupymake
|
|
193
|
+
True
|
|
194
|
+
sage: p._is_positive(0) # optional - jupymake
|
|
195
|
+
False
|
|
196
|
+
"""
|
|
197
|
+
return x > 0
|
|
198
|
+
|
|
199
|
+
def __init__(self, parent, Vrep, Hrep, polymake_polytope=None, **kwds):
|
|
200
|
+
"""
|
|
201
|
+
Initialize the polyhedron.
|
|
202
|
+
|
|
203
|
+
See :class:`Polyhedron_polymake` for a description of the input
|
|
204
|
+
data.
|
|
205
|
+
|
|
206
|
+
TESTS:
|
|
207
|
+
|
|
208
|
+
sage: # optional - jupymake
|
|
209
|
+
sage: p = Polyhedron(backend='polymake')
|
|
210
|
+
sage: TestSuite(p).run()
|
|
211
|
+
sage: p = Polyhedron(vertices=[(1, 1)], rays=[(0, 1)],
|
|
212
|
+
....: backend='polymake')
|
|
213
|
+
sage: TestSuite(p).run()
|
|
214
|
+
|
|
215
|
+
We skip the Lawrence test because it involves numerically unstable
|
|
216
|
+
floating point arithmetic::
|
|
217
|
+
|
|
218
|
+
sage: p = Polyhedron(vertices=[(-1,-1), (1,0), (1,1), (0,1)], # optional - jupymake
|
|
219
|
+
....: backend='polymake')
|
|
220
|
+
sage: TestSuite(p).run(skip='_test_lawrence') # optional - jupymake
|
|
221
|
+
|
|
222
|
+
::
|
|
223
|
+
|
|
224
|
+
sage: # optional - jupymake
|
|
225
|
+
sage: p = Polyhedron(rays=[[1,1]], backend='polymake')
|
|
226
|
+
sage: TestSuite(p).run()
|
|
227
|
+
sage: p = Polyhedron(rays=[[1]], backend='polymake')
|
|
228
|
+
sage: TestSuite(p).run()
|
|
229
|
+
sage: p = Polyhedron(rays=[[1,1,1]], lines=[[1,0,0]], backend='polymake')
|
|
230
|
+
sage: TestSuite(p).run()
|
|
231
|
+
sage: p = Polyhedron(vertices=[[]], backend='polymake')
|
|
232
|
+
sage: TestSuite(p).run()
|
|
233
|
+
"""
|
|
234
|
+
if polymake_polytope is not None:
|
|
235
|
+
if Hrep is not None or Vrep is not None:
|
|
236
|
+
raise ValueError("only one of Vrep, Hrep, or polymake_polytope can be different from None")
|
|
237
|
+
Element.__init__(self, parent=parent)
|
|
238
|
+
self._init_from_polymake_polytope(polymake_polytope)
|
|
239
|
+
else:
|
|
240
|
+
Polyhedron_base.__init__(self, parent, Vrep, Hrep, **kwds)
|
|
241
|
+
|
|
242
|
+
def _init_from_polymake_polytope(self, polymake_polytope):
|
|
243
|
+
"""
|
|
244
|
+
Construct polyhedron from a Polymake polytope object.
|
|
245
|
+
|
|
246
|
+
TESTS::
|
|
247
|
+
|
|
248
|
+
sage: p = Polyhedron(backend='polymake') # optional - jupymake
|
|
249
|
+
sage: from sage.geometry.polyhedron.backend_polymake import Polyhedron_polymake
|
|
250
|
+
sage: Polyhedron_polymake._init_from_Hrepresentation(p, [], []) # indirect doctest # optional - jupymake
|
|
251
|
+
"""
|
|
252
|
+
self._polymake_polytope = polymake_polytope
|
|
253
|
+
self._init_Vrepresentation_from_polymake()
|
|
254
|
+
self._init_Hrepresentation_from_polymake()
|
|
255
|
+
|
|
256
|
+
def _init_from_Vrepresentation(self, vertices, rays, lines, minimize=True, verbose=False):
|
|
257
|
+
r"""
|
|
258
|
+
Construct polyhedron from V-representation data.
|
|
259
|
+
|
|
260
|
+
INPUT:
|
|
261
|
+
|
|
262
|
+
- ``vertices`` -- list of points; each point can be specified
|
|
263
|
+
as any iterable container of
|
|
264
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
265
|
+
|
|
266
|
+
- ``rays`` -- list of rays; each ray can be specified as any
|
|
267
|
+
iterable container of
|
|
268
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
269
|
+
|
|
270
|
+
- ``lines`` -- list of lines; each line can be specified as
|
|
271
|
+
any iterable container of
|
|
272
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
273
|
+
|
|
274
|
+
- ``verbose`` -- boolean (default: ``False``); whether to print
|
|
275
|
+
verbose output for debugging purposes
|
|
276
|
+
|
|
277
|
+
EXAMPLES::
|
|
278
|
+
|
|
279
|
+
sage: p = Polyhedron(backend='polymake') # optional - jupymake
|
|
280
|
+
sage: from sage.geometry.polyhedron.backend_polymake import Polyhedron_polymake
|
|
281
|
+
sage: Polyhedron_polymake._init_from_Vrepresentation(p, [], [], []) # optional - jupymake
|
|
282
|
+
"""
|
|
283
|
+
from sage.interfaces.polymake import polymake
|
|
284
|
+
data = self._polymake_Vrepresentation_data(vertices, rays, lines)
|
|
285
|
+
polymake_field = polymake(self.base_ring().fraction_field())
|
|
286
|
+
p = polymake.new_object("Polytope<{}>".format(polymake_field), **data)
|
|
287
|
+
self._init_from_polymake_polytope(p)
|
|
288
|
+
|
|
289
|
+
def _polymake_Vrepresentation_data(self, vertices, rays, lines, minimal=False):
|
|
290
|
+
r"""
|
|
291
|
+
Compute a dictionary with V-representation input for a polymake Polytope object.
|
|
292
|
+
|
|
293
|
+
INPUT:
|
|
294
|
+
|
|
295
|
+
- ``vertices`` -- list of points; each point can be specified
|
|
296
|
+
as any iterable container of
|
|
297
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
298
|
+
|
|
299
|
+
- ``rays`` -- list of rays; each ray can be specified as any
|
|
300
|
+
iterable container of
|
|
301
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
302
|
+
|
|
303
|
+
- ``lines`` -- list of lines; each line can be specified as
|
|
304
|
+
any iterable container of
|
|
305
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
306
|
+
|
|
307
|
+
- ``minimal`` -- boolean (default: ``False``); whether the input is already minimal
|
|
308
|
+
|
|
309
|
+
.. WARNING::
|
|
310
|
+
|
|
311
|
+
If ``minimal`` the representation is assumed to be correct.
|
|
312
|
+
It is not checked.
|
|
313
|
+
"""
|
|
314
|
+
if not minimal:
|
|
315
|
+
return dict(CONE_AMBIENT_DIM=1+self.parent().ambient_dim(),
|
|
316
|
+
POINTS=( [ [1] + list(v) for v in vertices ]
|
|
317
|
+
+ [ [0] + list(r) for r in rays ]),
|
|
318
|
+
INPUT_LINEALITY=[ [0] + list(l) for l in lines ])
|
|
319
|
+
else:
|
|
320
|
+
return dict(CONE_AMBIENT_DIM=1+self.parent().ambient_dim(),
|
|
321
|
+
VERTICES=( [ [1] + list(v) for v in vertices ]
|
|
322
|
+
+ [ [0] + list(r) for r in rays ]),
|
|
323
|
+
LINEALITY_SPACE=[ [0] + list(l) for l in lines ])
|
|
324
|
+
|
|
325
|
+
def _init_from_Hrepresentation(self, ieqs, eqns, minimize=True, verbose=False):
|
|
326
|
+
r"""
|
|
327
|
+
Construct polyhedron from H-representation data.
|
|
328
|
+
|
|
329
|
+
INPUT:
|
|
330
|
+
|
|
331
|
+
- ``ieqs`` -- list of inequalities; each line can be specified
|
|
332
|
+
as any iterable container of
|
|
333
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
334
|
+
|
|
335
|
+
- ``eqns`` -- list of equalities; each line can be specified
|
|
336
|
+
as any iterable container of
|
|
337
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
338
|
+
|
|
339
|
+
- ``minimize`` -- boolean (default: ``True``); ignored
|
|
340
|
+
|
|
341
|
+
- ``verbose`` -- boolean (default: ``False``); whether to print
|
|
342
|
+
verbose output for debugging purposes
|
|
343
|
+
|
|
344
|
+
EXAMPLES::
|
|
345
|
+
|
|
346
|
+
sage: p = Polyhedron(backend='polymake') # optional - jupymake
|
|
347
|
+
sage: from sage.geometry.polyhedron.backend_polymake import Polyhedron_polymake
|
|
348
|
+
sage: Polyhedron_polymake._init_from_Hrepresentation(p, [], []) # optional - jupymake
|
|
349
|
+
"""
|
|
350
|
+
from sage.interfaces.polymake import polymake
|
|
351
|
+
data = self._polymake_Hrepresentation_data(ieqs, eqns)
|
|
352
|
+
polymake_field = polymake(self.base_ring().fraction_field())
|
|
353
|
+
p = polymake.new_object("Polytope<{}>".format(polymake_field), **data)
|
|
354
|
+
self._init_from_polymake_polytope(p)
|
|
355
|
+
|
|
356
|
+
def _polymake_Hrepresentation_data(self, ieqs, eqns, minimal=False):
|
|
357
|
+
r"""
|
|
358
|
+
Compute a dictionary with H-representation input for a polymake Polytope object.
|
|
359
|
+
|
|
360
|
+
INPUT:
|
|
361
|
+
|
|
362
|
+
- ``ieqs`` -- list of inequalities; each line can be specified
|
|
363
|
+
as any iterable container of
|
|
364
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
365
|
+
|
|
366
|
+
- ``eqns`` -- list of equalities; each line can be specified
|
|
367
|
+
as any iterable container of
|
|
368
|
+
:meth:`~sage.geometry.polyhedron.base.base_ring` elements
|
|
369
|
+
|
|
370
|
+
- ``minimal`` -- boolean (default: ``False``); whether the input is already minimal
|
|
371
|
+
|
|
372
|
+
.. WARNING::
|
|
373
|
+
|
|
374
|
+
If ``minimal`` the representation is assumed to be correct.
|
|
375
|
+
It is not checked.
|
|
376
|
+
"""
|
|
377
|
+
if ieqs is None:
|
|
378
|
+
ieqs = []
|
|
379
|
+
if eqns is None:
|
|
380
|
+
eqns = []
|
|
381
|
+
# Polymake 3.0r2 and 3.1 crash with a segfault for a test case
|
|
382
|
+
# using QuadraticExtension, when some all-zero inequalities are input.
|
|
383
|
+
# https://forum.polymake.org/viewtopic.php?f=8&t=547
|
|
384
|
+
# Filter them out.
|
|
385
|
+
ieqs = [ list(v) for v in ieqs if not all(self._is_zero(x) for x in v) ]
|
|
386
|
+
# We do a similar filtering for equations.
|
|
387
|
+
# Since Polymake 3.2, we can not give all zero vectors in equations
|
|
388
|
+
eqns = [ list(v) for v in eqns if not all(self._is_zero(x) for x in v) ]
|
|
389
|
+
if not ieqs:
|
|
390
|
+
# Put in one trivial (all-zero) inequality. This is so that
|
|
391
|
+
# the ambient dimension is set correctly.
|
|
392
|
+
# Since Polymake 3.2, the constant should not be zero.
|
|
393
|
+
ieqs.append([1] + [0]*self.ambient_dim())
|
|
394
|
+
if not minimal:
|
|
395
|
+
return dict(EQUATIONS=eqns,
|
|
396
|
+
INEQUALITIES=ieqs)
|
|
397
|
+
else:
|
|
398
|
+
return dict(AFFINE_HULL=eqns,
|
|
399
|
+
FACETS=ieqs)
|
|
400
|
+
|
|
401
|
+
def _init_from_Vrepresentation_and_Hrepresentation(self, Vrep, Hrep):
|
|
402
|
+
"""
|
|
403
|
+
Construct polyhedron from V-representation and H-representation data.
|
|
404
|
+
|
|
405
|
+
See :class:`Polyhedron_base` for a description of ``Vrep`` and ``Hrep``.
|
|
406
|
+
|
|
407
|
+
.. WARNING::
|
|
408
|
+
|
|
409
|
+
The representation is assumed to be correct.
|
|
410
|
+
It is not checked.
|
|
411
|
+
|
|
412
|
+
EXAMPLES::
|
|
413
|
+
|
|
414
|
+
sage: from sage.geometry.polyhedron.parent import Polyhedra_polymake
|
|
415
|
+
sage: from sage.geometry.polyhedron.backend_polymake import Polyhedron_polymake
|
|
416
|
+
sage: parent = Polyhedra_polymake(ZZ, 1, 'polymake')
|
|
417
|
+
sage: Vrep = [[[0], [1]], [], []]
|
|
418
|
+
sage: Hrep = [[[0, 1], [1, -1]], []]
|
|
419
|
+
sage: p = Polyhedron_polymake(parent, Vrep, Hrep, # indirect doctest # optional - jupymake
|
|
420
|
+
....: Vrep_minimal=True, Hrep_minimal=True)
|
|
421
|
+
sage: p # optional - jupymake
|
|
422
|
+
A 1-dimensional polyhedron in ZZ^1 defined as the convex hull of 2 vertices
|
|
423
|
+
"""
|
|
424
|
+
Vrep = [list(x) for x in Vrep]
|
|
425
|
+
Hrep = [list(x) for x in Hrep]
|
|
426
|
+
p = self._polymake_polytope_from_Vrepresentation_and_Hrepresentation(Vrep, Hrep)
|
|
427
|
+
if p is None:
|
|
428
|
+
self._init_empty_polyhedron()
|
|
429
|
+
return
|
|
430
|
+
|
|
431
|
+
self._polymake_polytope = p
|
|
432
|
+
|
|
433
|
+
# As the conversion from polymake to sage is slow,
|
|
434
|
+
# we skip it.
|
|
435
|
+
parent = self.parent()
|
|
436
|
+
vertices, rays, lines = Vrep
|
|
437
|
+
inequalities, equations = Hrep
|
|
438
|
+
self._Vrepresentation = []
|
|
439
|
+
self._Hrepresentation = []
|
|
440
|
+
for x in vertices:
|
|
441
|
+
parent._make_Vertex(self, x)
|
|
442
|
+
for x in rays:
|
|
443
|
+
parent._make_Ray(self, x)
|
|
444
|
+
for x in lines:
|
|
445
|
+
parent._make_Line(self, x)
|
|
446
|
+
for x in inequalities:
|
|
447
|
+
parent._make_Inequality(self, x)
|
|
448
|
+
for x in equations:
|
|
449
|
+
parent._make_Equation(self, x)
|
|
450
|
+
self._Vrepresentation = tuple(self._Vrepresentation)
|
|
451
|
+
self._Hrepresentation = tuple(self._Hrepresentation)
|
|
452
|
+
|
|
453
|
+
def _polymake_polytope_from_Vrepresentation_and_Hrepresentation(self, Vrep, Hrep):
|
|
454
|
+
if not any(Vrep):
|
|
455
|
+
# The empty polyhedron.
|
|
456
|
+
return
|
|
457
|
+
|
|
458
|
+
from sage.interfaces.polymake import polymake
|
|
459
|
+
data = self._polymake_Vrepresentation_data(*Vrep, minimal=True)
|
|
460
|
+
|
|
461
|
+
if any(Vrep[1:]):
|
|
462
|
+
from sage.matrix.constructor import Matrix
|
|
463
|
+
polymake_rays = [r for r in data['VERTICES'] if r[0] == 0]
|
|
464
|
+
if Matrix(data['VERTICES']).rank() == Matrix(polymake_rays).rank() + 1:
|
|
465
|
+
# The recession cone is full-dimensional.
|
|
466
|
+
# In this case the homogenized inequalities
|
|
467
|
+
# do not ensure nonnegativy in the last coordinate.
|
|
468
|
+
# In the homogeneous cone the far face is a facet.
|
|
469
|
+
Hrep[0] += [[1] + [0]*self.ambient_dim()]
|
|
470
|
+
data.update(self._polymake_Hrepresentation_data(*Hrep, minimal=True))
|
|
471
|
+
|
|
472
|
+
polymake_field = polymake(self.base_ring().fraction_field())
|
|
473
|
+
return polymake.new_object("Polytope<{}>".format(polymake_field), **data)
|
|
474
|
+
|
|
475
|
+
def _init_Vrepresentation_from_polymake(self):
|
|
476
|
+
r"""
|
|
477
|
+
Create the Vrepresentation objects from the polymake polyhedron.
|
|
478
|
+
|
|
479
|
+
EXAMPLES::
|
|
480
|
+
|
|
481
|
+
sage: p = Polyhedron(vertices=[(0,1/2),(2,0),(4,5/6)], # indirect doctest # optional - jupymake
|
|
482
|
+
....: backend='polymake')
|
|
483
|
+
sage: set(p.Hrepresentation()) # optional - jupymake
|
|
484
|
+
{An inequality (1, 4) x - 2 >= 0,
|
|
485
|
+
An inequality (1, -12) x + 6 >= 0,
|
|
486
|
+
An inequality (-5, 12) x + 10 >= 0}
|
|
487
|
+
sage: set(p.Vrepresentation()) # optional - jupymake
|
|
488
|
+
{A vertex at (0, 1/2), A vertex at (2, 0), A vertex at (4, 5/6)}
|
|
489
|
+
"""
|
|
490
|
+
self._Vrepresentation = []
|
|
491
|
+
parent = self.parent()
|
|
492
|
+
p = self._polymake_polytope
|
|
493
|
+
for g in p.VERTICES.sage():
|
|
494
|
+
d = g[0]
|
|
495
|
+
if d == 0:
|
|
496
|
+
parent._make_Ray(self, g[1:])
|
|
497
|
+
elif d == 1:
|
|
498
|
+
parent._make_Vertex(self, g[1:])
|
|
499
|
+
else:
|
|
500
|
+
raise NotImplementedError("Non-normalized vertex encountered: {}".format(g))
|
|
501
|
+
for g in p.LINEALITY_SPACE.sage():
|
|
502
|
+
d = g[0]
|
|
503
|
+
if d == 0:
|
|
504
|
+
parent._make_Line(self, g[1:])
|
|
505
|
+
else:
|
|
506
|
+
raise NotImplementedError("Non-homogeneous line encountered: {}".format(g))
|
|
507
|
+
self._Vrepresentation = tuple(self._Vrepresentation)
|
|
508
|
+
|
|
509
|
+
def _init_Hrepresentation_from_polymake(self):
|
|
510
|
+
r"""
|
|
511
|
+
Create the Hrepresentation objects from the polymake polyhedron.
|
|
512
|
+
|
|
513
|
+
EXAMPLES::
|
|
514
|
+
|
|
515
|
+
sage: p = Polyhedron(vertices=[(0,1/2), (2,0), (4,5/6)], # indirect doctest # optional - jupymake
|
|
516
|
+
....: backend='polymake')
|
|
517
|
+
sage: set(p.Hrepresentation()) # optional - jupymake
|
|
518
|
+
{An inequality (1, 4) x - 2 >= 0,
|
|
519
|
+
An inequality (1, -12) x + 6 >= 0,
|
|
520
|
+
An inequality (-5, 12) x + 10 >= 0}
|
|
521
|
+
sage: set(p.Vrepresentation()) # optional - jupymake
|
|
522
|
+
{A vertex at (0, 1/2), A vertex at (2, 0), A vertex at (4, 5/6)}
|
|
523
|
+
"""
|
|
524
|
+
p = self._polymake_polytope
|
|
525
|
+
if not p.FEASIBLE:
|
|
526
|
+
self._init_empty_polyhedron()
|
|
527
|
+
else:
|
|
528
|
+
self._Hrepresentation = []
|
|
529
|
+
parent = self.parent()
|
|
530
|
+
for g in p.FACETS.sage():
|
|
531
|
+
if all(x == 0 for x in g[1:]):
|
|
532
|
+
# Ignore vertical inequality
|
|
533
|
+
pass
|
|
534
|
+
else:
|
|
535
|
+
parent._make_Inequality(self, g)
|
|
536
|
+
for g in p.AFFINE_HULL.sage():
|
|
537
|
+
parent._make_Equation(self, g)
|
|
538
|
+
self._Hrepresentation = tuple(self._Hrepresentation)
|
|
539
|
+
|
|
540
|
+
@classmethod
|
|
541
|
+
def _from_polymake_polytope(cls, parent, polymake_polytope):
|
|
542
|
+
r"""
|
|
543
|
+
Initialize a polyhedron from a polymake Polytope object.
|
|
544
|
+
|
|
545
|
+
TESTS::
|
|
546
|
+
|
|
547
|
+
sage: from sage.geometry.polyhedron.backend_polymake import Polyhedron_polymake
|
|
548
|
+
sage: from sage.geometry.polyhedron.parent import Polyhedra
|
|
549
|
+
sage: P=Polyhedron(ieqs=[[1, 0, 2], [3, 0, -2], [3, 2, -2]])
|
|
550
|
+
sage: PP = polymake(P) # optional - jupymake
|
|
551
|
+
sage: parent = Polyhedra(QQ, 2, backend='polymake') # optional - jupymake
|
|
552
|
+
sage: Q=Polyhedron_polymake._from_polymake_polytope(parent, PP) # optional - jupymake
|
|
553
|
+
"""
|
|
554
|
+
if parent is None:
|
|
555
|
+
from .parent import Polyhedra
|
|
556
|
+
from sage.rings.rational_field import QQ
|
|
557
|
+
if polymake_polytope.typeof()[0] == 'Polymake::polytope::Polytope__Rational':
|
|
558
|
+
base_ring = QQ
|
|
559
|
+
else:
|
|
560
|
+
from sage.structure.element import coercion_model
|
|
561
|
+
data = [g.sage()
|
|
562
|
+
for g in itertools.chain(polymake_polytope.VERTICES,
|
|
563
|
+
polymake_polytope.LINEALITY_SPACE,
|
|
564
|
+
polymake_polytope.FACETS,
|
|
565
|
+
polymake_polytope.AFFINE_HULL)]
|
|
566
|
+
if data:
|
|
567
|
+
base_ring = coercion_model.common_parent(*data).base_ring()
|
|
568
|
+
else:
|
|
569
|
+
base_ring = QQ
|
|
570
|
+
ambient_dim = polymake_polytope.AMBIENT_DIM().sage()
|
|
571
|
+
parent = Polyhedra(base_ring=base_ring, ambient_dim=ambient_dim, backend='polymake')
|
|
572
|
+
return cls(parent, None, None, polymake_polytope=polymake_polytope)
|
|
573
|
+
|
|
574
|
+
def _polymake_(self, polymake):
|
|
575
|
+
"""
|
|
576
|
+
Return a polymake "Polytope" object corresponding to ``self``.
|
|
577
|
+
|
|
578
|
+
EXAMPLES::
|
|
579
|
+
|
|
580
|
+
sage: P = Polyhedron(vertices=[[1, 0], [0, 1], [0, 0]], backend='polymake') # optional - jupymake
|
|
581
|
+
sage: PP = polymake(P) # optional - jupymake
|
|
582
|
+
sage: PP.N_VERTICES # optional - jupymake
|
|
583
|
+
3
|
|
584
|
+
"""
|
|
585
|
+
if self._polymake_polytope.parent() is polymake:
|
|
586
|
+
# Same polymake interface, can just return our object
|
|
587
|
+
return self._polymake_polytope
|
|
588
|
+
return super()._polymake_(polymake)
|
|
589
|
+
|
|
590
|
+
def __getstate__(self):
|
|
591
|
+
r"""
|
|
592
|
+
Remove the polymake polytope object for pickling.
|
|
593
|
+
|
|
594
|
+
TESTS::
|
|
595
|
+
|
|
596
|
+
sage: P = polytopes.simplex(backend='polymake') # optional - jupymake
|
|
597
|
+
sage: P.__getstate__() # optional - jupymake
|
|
598
|
+
(Polyhedra in QQ^4,
|
|
599
|
+
{'_Hrepresentation': (An inequality (0, -1, -1, -1) x + 1 >= 0,
|
|
600
|
+
An inequality (0, 1, 0, 0) x + 0 >= 0,
|
|
601
|
+
An inequality (0, 0, 1, 0) x + 0 >= 0,
|
|
602
|
+
An inequality (0, 0, 0, 1) x + 0 >= 0,
|
|
603
|
+
An equation (1, 1, 1, 1) x - 1 == 0),
|
|
604
|
+
'_Vrepresentation': (A vertex at (1, 0, 0, 0),
|
|
605
|
+
A vertex at (0, 1, 0, 0),
|
|
606
|
+
A vertex at (0, 0, 1, 0),
|
|
607
|
+
A vertex at (0, 0, 0, 1)),
|
|
608
|
+
'_pickle_equations': [(-1, 1, 1, 1, 1)],
|
|
609
|
+
'_pickle_inequalities': [(1, 0, -1, -1, -1),
|
|
610
|
+
(0, 0, 1, 0, 0),
|
|
611
|
+
(0, 0, 0, 1, 0),
|
|
612
|
+
(0, 0, 0, 0, 1)],
|
|
613
|
+
'_pickle_lines': [],
|
|
614
|
+
'_pickle_rays': [],
|
|
615
|
+
'_pickle_vertices': [(1, 0, 0, 0),
|
|
616
|
+
(0, 1, 0, 0),
|
|
617
|
+
(0, 0, 1, 0),
|
|
618
|
+
(0, 0, 0, 1)]})
|
|
619
|
+
"""
|
|
620
|
+
state = super().__getstate__()
|
|
621
|
+
state = (state[0], state[1].copy())
|
|
622
|
+
# Remove the unpicklable entries.
|
|
623
|
+
if '_polymake_polytope' in state[1]:
|
|
624
|
+
del state[1]['_polymake_polytope']
|
|
625
|
+
state[1]["_pickle_vertices"] = [v._vector for v in self.vertices()]
|
|
626
|
+
state[1]["_pickle_rays"] = [v._vector for v in self.rays()]
|
|
627
|
+
state[1]["_pickle_lines"] = [v._vector for v in self.lines()]
|
|
628
|
+
state[1]["_pickle_inequalities"] = [v._vector for v in self.inequalities()]
|
|
629
|
+
state[1]["_pickle_equations"] = [v._vector for v in self.equations()]
|
|
630
|
+
return state
|
|
631
|
+
|
|
632
|
+
def __setstate__(self, state):
|
|
633
|
+
r"""
|
|
634
|
+
Initialize the polymake polytope object after pickling.
|
|
635
|
+
|
|
636
|
+
TESTS:
|
|
637
|
+
|
|
638
|
+
Test that the obtained cone is valid::
|
|
639
|
+
|
|
640
|
+
sage: # optional - jupymake
|
|
641
|
+
sage: from sage.geometry.polyhedron.backend_polymake import Polyhedron_polymake
|
|
642
|
+
sage: P = polytopes.permutahedron(4, backend='polymake')
|
|
643
|
+
sage: P1 = loads(dumps(P))
|
|
644
|
+
sage: P2 = Polyhedron_polymake(P1.parent(), None, None, P1._polymake_polytope)
|
|
645
|
+
sage: P._test_polymake_pickling(other=P2)
|
|
646
|
+
|
|
647
|
+
sage: # optional - jupymake
|
|
648
|
+
sage: P = Polyhedron(lines=[[1,0], [0,1]], backend='polymake')
|
|
649
|
+
sage: P1 = loads(dumps(P))
|
|
650
|
+
sage: P2 = Polyhedron_polymake(P1.parent(), None, None, P1._polymake_polytope)
|
|
651
|
+
sage: P._test_polymake_pickling(other=P2)
|
|
652
|
+
|
|
653
|
+
sage: P = Polyhedron(backend='polymake') # optional - jupymake
|
|
654
|
+
sage: P1 = loads(dumps(P)) # optional - jupymake
|
|
655
|
+
sage: P._test_polymake_pickling(other=P1) # optional - jupymake
|
|
656
|
+
|
|
657
|
+
sage: # optional - jupymake
|
|
658
|
+
sage: P = polytopes.permutahedron(4, backend='polymake') * Polyhedron(lines=[[1]], backend='polymake')
|
|
659
|
+
sage: P1 = loads(dumps(P))
|
|
660
|
+
sage: P2 = Polyhedron_polymake(P1.parent(), None, None, P1._polymake_polytope)
|
|
661
|
+
sage: P._test_polymake_pickling(other=P2)
|
|
662
|
+
|
|
663
|
+
sage: # optional - jupymake, needs sage.rings.number_field
|
|
664
|
+
sage: print("Possible output"); P = polytopes.dodecahedron(backend='polymake')
|
|
665
|
+
Possible output...
|
|
666
|
+
sage: P1 = loads(dumps(P))
|
|
667
|
+
sage: P2 = Polyhedron_polymake(P1.parent(), None, None, P1._polymake_polytope)
|
|
668
|
+
sage: P._test_polymake_pickling(other=P2)
|
|
669
|
+
"""
|
|
670
|
+
if "_pickle_vertices" in state[1]:
|
|
671
|
+
vertices = state[1].pop("_pickle_vertices")
|
|
672
|
+
rays = state[1].pop("_pickle_rays")
|
|
673
|
+
lines = state[1].pop("_pickle_lines")
|
|
674
|
+
inequalities = state[1].pop("_pickle_inequalities")
|
|
675
|
+
equations = state[1].pop("_pickle_equations")
|
|
676
|
+
else:
|
|
677
|
+
vertices = None
|
|
678
|
+
|
|
679
|
+
super().__setstate__(state)
|
|
680
|
+
|
|
681
|
+
if vertices is None:
|
|
682
|
+
vertices = self.vertices()
|
|
683
|
+
rays = self.rays()
|
|
684
|
+
lines = self.lines()
|
|
685
|
+
inequalities = self.inequalities()
|
|
686
|
+
equations = self.equations()
|
|
687
|
+
|
|
688
|
+
p = self._polymake_polytope_from_Vrepresentation_and_Hrepresentation([vertices, rays, lines], [inequalities, equations])
|
|
689
|
+
if p is not None:
|
|
690
|
+
self._polymake_polytope = p
|
|
691
|
+
|
|
692
|
+
def _test_polymake_pickling(self, tester=None, other=None, **options):
|
|
693
|
+
"""
|
|
694
|
+
Run tests to see that our polymake pickling/unpickling works.
|
|
695
|
+
|
|
696
|
+
INPUT:
|
|
697
|
+
|
|
698
|
+
- ``other`` -- a pickling polytope of ``self`` to be tested against
|
|
699
|
+
|
|
700
|
+
TESTS::
|
|
701
|
+
|
|
702
|
+
sage: polytopes.cross_polytope(3, backend='polymake')._test_polymake_pickling() # optional - jupymake
|
|
703
|
+
"""
|
|
704
|
+
if tester is None:
|
|
705
|
+
tester = self._tester(**options)
|
|
706
|
+
|
|
707
|
+
if other is None:
|
|
708
|
+
from sage.misc.persist import loads, dumps
|
|
709
|
+
other = loads(dumps(self))
|
|
710
|
+
|
|
711
|
+
tester.assertEqual(self, other)
|
|
712
|
+
|
|
713
|
+
if not hasattr(self, '_polymake_polytope'):
|
|
714
|
+
tester.assertFalse(hasattr(other, '_polymake_polytope'))
|
|
715
|
+
return
|
|
716
|
+
|
|
717
|
+
P = self._polymake_polytope
|
|
718
|
+
P1 = other._polymake_polytope
|
|
719
|
+
|
|
720
|
+
tester.assertEqual(P.F_VECTOR, P1.F_VECTOR)
|
|
721
|
+
tester.assertEqual(P.VERTICES, P1.VERTICES)
|
|
722
|
+
tester.assertEqual(P.LINEALITY_SPACE, P1.LINEALITY_SPACE)
|
|
723
|
+
tester.assertEqual(P.FACETS, P1.FACETS)
|
|
724
|
+
tester.assertEqual(P.AFFINE_HULL, P1.AFFINE_HULL)
|
|
725
|
+
|
|
726
|
+
#########################################################################
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
class Polyhedron_QQ_polymake(Polyhedron_polymake, Polyhedron_QQ):
|
|
730
|
+
r"""
|
|
731
|
+
Polyhedra over `\QQ` with polymake.
|
|
732
|
+
|
|
733
|
+
INPUT:
|
|
734
|
+
|
|
735
|
+
- ``Vrep`` -- list ``[vertices, rays, lines]`` or ``None``
|
|
736
|
+
- ``Hrep`` -- list ``[ieqs, eqns]`` or ``None``
|
|
737
|
+
|
|
738
|
+
EXAMPLES::
|
|
739
|
+
|
|
740
|
+
sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], # optional - jupymake
|
|
741
|
+
....: rays=[(1,1)], lines=[],
|
|
742
|
+
....: backend='polymake', base_ring=QQ)
|
|
743
|
+
sage: TestSuite(p).run() # optional - jupymake
|
|
744
|
+
"""
|
|
745
|
+
pass
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
#########################################################################
|
|
749
|
+
class Polyhedron_ZZ_polymake(Polyhedron_polymake, Polyhedron_ZZ):
|
|
750
|
+
r"""
|
|
751
|
+
Polyhedra over `\ZZ` with polymake.
|
|
752
|
+
|
|
753
|
+
INPUT:
|
|
754
|
+
|
|
755
|
+
- ``Vrep`` -- list ``[vertices, rays, lines]`` or ``None``
|
|
756
|
+
- ``Hrep`` -- list ``[ieqs, eqns]`` or ``None``
|
|
757
|
+
|
|
758
|
+
EXAMPLES::
|
|
759
|
+
|
|
760
|
+
sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], # optional - jupymake
|
|
761
|
+
....: rays=[(1,1)], lines=[],
|
|
762
|
+
....: backend='polymake', base_ring=ZZ)
|
|
763
|
+
sage: TestSuite(p).run() # optional - jupymake
|
|
764
|
+
"""
|
|
765
|
+
pass
|