passagemath-polyhedra 10.6.37__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.
- passagemath_polyhedra/__init__.py +3 -0
- passagemath_polyhedra-10.6.37.dist-info/METADATA +367 -0
- passagemath_polyhedra-10.6.37.dist-info/METADATA.bak +369 -0
- passagemath_polyhedra-10.6.37.dist-info/RECORD +209 -0
- passagemath_polyhedra-10.6.37.dist-info/WHEEL +5 -0
- passagemath_polyhedra-10.6.37.dist-info/top_level.txt +3 -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 +3905 -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,459 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-polyhedra
|
|
2
|
+
"""
|
|
3
|
+
Matrix/Vector-Valued Linear Functions: Elements
|
|
4
|
+
|
|
5
|
+
Here is an example of a linear function tensored with a vector space::
|
|
6
|
+
|
|
7
|
+
sage: mip.<x> = MixedIntegerLinearProgram('ppl') # base ring is QQ
|
|
8
|
+
sage: lt = x[0] * vector([3,4]) + 1; lt
|
|
9
|
+
(1, 1) + (3, 4)*x_0
|
|
10
|
+
sage: type(lt)
|
|
11
|
+
<class 'sage.numerical.linear_tensor_element.LinearTensor'>
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
# ****************************************************************************
|
|
15
|
+
# Copyright (C) 2014 Volker Braun <vbraun.name@gmail.com>
|
|
16
|
+
#
|
|
17
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
18
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
19
|
+
# the License, or (at your option) any later version.
|
|
20
|
+
# https://www.gnu.org/licenses/
|
|
21
|
+
# ****************************************************************************
|
|
22
|
+
|
|
23
|
+
from cpython.object cimport *
|
|
24
|
+
|
|
25
|
+
from sage.misc.fast_methods cimport hash_by_id
|
|
26
|
+
from sage.structure.element cimport ModuleElement, Element
|
|
27
|
+
from sage.numerical.linear_functions cimport LinearFunction
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# ***************************************************************************
|
|
31
|
+
#
|
|
32
|
+
# Elements of linear functions tensored with a free module
|
|
33
|
+
#
|
|
34
|
+
# ***************************************************************************
|
|
35
|
+
|
|
36
|
+
cdef class LinearTensor(ModuleElement):
|
|
37
|
+
r"""
|
|
38
|
+
A linear function tensored with a free module.
|
|
39
|
+
|
|
40
|
+
.. warning::
|
|
41
|
+
|
|
42
|
+
You should never instantiate :class:`LinearTensor`
|
|
43
|
+
manually. Use the element constructor in the parent
|
|
44
|
+
instead.
|
|
45
|
+
|
|
46
|
+
EXAMPLES::
|
|
47
|
+
|
|
48
|
+
sage: parent = MixedIntegerLinearProgram().linear_functions_parent().tensor(RDF^2)
|
|
49
|
+
sage: parent({0: [1,2], 3: [-7,-8]})
|
|
50
|
+
(1.0, 2.0)*x_0 + (-7.0, -8.0)*x_3
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def __init__(self, parent, f):
|
|
54
|
+
r"""
|
|
55
|
+
Constructor taking a dictionary as its argument.
|
|
56
|
+
|
|
57
|
+
INPUT:
|
|
58
|
+
|
|
59
|
+
- ``parent`` -- the parent
|
|
60
|
+
:class:`~sage.numerical.linear_tensor.LinearTensorParent_class`
|
|
61
|
+
|
|
62
|
+
- ``f`` -- a linear function tensored by a free module is
|
|
63
|
+
represented as a dictionary. The values are the coefficient
|
|
64
|
+
(free module elements) of the variable represented by the
|
|
65
|
+
keys. The key ``-1`` corresponds to the constant term.
|
|
66
|
+
|
|
67
|
+
EXAMPLES:
|
|
68
|
+
|
|
69
|
+
With a dictionary::
|
|
70
|
+
|
|
71
|
+
sage: LT = MixedIntegerLinearProgram().linear_functions_parent().tensor(RDF^2)
|
|
72
|
+
sage: LT({0: [1,2], 3: [-7,-8]})
|
|
73
|
+
(1.0, 2.0)*x_0 + (-7.0, -8.0)*x_3
|
|
74
|
+
|
|
75
|
+
sage: TestSuite(LT).run(skip=['_test_an_element', '_test_elements_eq_reflexive',
|
|
76
|
+
....: '_test_elements_eq_symmetric', '_test_elements_eq_transitive',
|
|
77
|
+
....: '_test_elements_neq', '_test_additive_associativity',
|
|
78
|
+
....: '_test_elements', '_test_pickling', '_test_zero'])
|
|
79
|
+
"""
|
|
80
|
+
ModuleElement.__init__(self, parent)
|
|
81
|
+
assert isinstance(f, dict)
|
|
82
|
+
self._f = f
|
|
83
|
+
|
|
84
|
+
def __getitem__(self, indices):
|
|
85
|
+
"""
|
|
86
|
+
Return the linear function component with given tensor indices.
|
|
87
|
+
|
|
88
|
+
INPUT:
|
|
89
|
+
|
|
90
|
+
- ``indices`` -- one or more integers. The basis indices of
|
|
91
|
+
the free module. E.g. a single integer for vectors, two for
|
|
92
|
+
matrices.
|
|
93
|
+
|
|
94
|
+
EXAMPLES::
|
|
95
|
+
|
|
96
|
+
sage: p = MixedIntegerLinearProgram().linear_functions_parent().tensor(RDF^2)
|
|
97
|
+
sage: lt = p({0:[1,2], 3:[4,5]}); lt
|
|
98
|
+
(1.0, 2.0)*x_0 + (4.0, 5.0)*x_3
|
|
99
|
+
sage: lt[0]
|
|
100
|
+
x_0 + 4*x_3
|
|
101
|
+
sage: lt[1]
|
|
102
|
+
2*x_0 + 5*x_3
|
|
103
|
+
"""
|
|
104
|
+
f = dict([key, value[indices]] for key, value in self._f.items())
|
|
105
|
+
LF = self.parent().linear_functions()
|
|
106
|
+
return LF(f)
|
|
107
|
+
|
|
108
|
+
def dict(self):
|
|
109
|
+
r"""
|
|
110
|
+
Return the dictionary corresponding to the tensor product.
|
|
111
|
+
|
|
112
|
+
OUTPUT:
|
|
113
|
+
|
|
114
|
+
The linear function tensor product is represented as a
|
|
115
|
+
dictionary. The value are the coefficient (free module
|
|
116
|
+
elements) of the variable represented by the keys (which are
|
|
117
|
+
integers). The key ``-1`` corresponds to the constant term.
|
|
118
|
+
|
|
119
|
+
EXAMPLES::
|
|
120
|
+
|
|
121
|
+
sage: p = MixedIntegerLinearProgram().linear_functions_parent().tensor(RDF^2)
|
|
122
|
+
sage: lt = p({0:[1,2], 3:[4,5]})
|
|
123
|
+
sage: lt.dict()
|
|
124
|
+
{0: (1.0, 2.0), 3: (4.0, 5.0)}
|
|
125
|
+
"""
|
|
126
|
+
return dict(self._f)
|
|
127
|
+
|
|
128
|
+
def coefficient(self, x):
|
|
129
|
+
r"""
|
|
130
|
+
Return one of the coefficients.
|
|
131
|
+
|
|
132
|
+
INPUT:
|
|
133
|
+
|
|
134
|
+
- ``x`` -- a linear variable or an integer. If an integer `i`
|
|
135
|
+
is passed, then `x_i` is used as linear variable. Pass
|
|
136
|
+
``-1`` for the constant term.
|
|
137
|
+
|
|
138
|
+
OUTPUT:
|
|
139
|
+
|
|
140
|
+
A constant, that is, an element of the free module factor. The
|
|
141
|
+
coefficient of ``x`` in the linear function.
|
|
142
|
+
|
|
143
|
+
EXAMPLES::
|
|
144
|
+
|
|
145
|
+
sage: mip.<b> = MixedIntegerLinearProgram()
|
|
146
|
+
sage: lt = vector([1,2]) * b[3] + vector([4,5]) * b[0] - 5; lt
|
|
147
|
+
(-5.0, -5.0) + (1.0, 2.0)*x_0 + (4.0, 5.0)*x_1
|
|
148
|
+
sage: lt.coefficient(b[3])
|
|
149
|
+
(1.0, 2.0)
|
|
150
|
+
sage: lt.coefficient(0) # x_0 is b[3]
|
|
151
|
+
(1.0, 2.0)
|
|
152
|
+
sage: lt.coefficient(4)
|
|
153
|
+
(0.0, 0.0)
|
|
154
|
+
sage: lt.coefficient(-1)
|
|
155
|
+
(-5.0, -5.0)
|
|
156
|
+
|
|
157
|
+
TESTS::
|
|
158
|
+
|
|
159
|
+
sage: lt.coefficient(b[3] + b[4])
|
|
160
|
+
Traceback (most recent call last):
|
|
161
|
+
...
|
|
162
|
+
ValueError: x is a sum, must be a single variable
|
|
163
|
+
sage: lt.coefficient(2*b[3])
|
|
164
|
+
Traceback (most recent call last):
|
|
165
|
+
...
|
|
166
|
+
ValueError: x must have a unit coefficient
|
|
167
|
+
sage: mip.<q> = MixedIntegerLinearProgram(solver='ppl')
|
|
168
|
+
sage: lt.coefficient(q[0])
|
|
169
|
+
Traceback (most recent call last):
|
|
170
|
+
...
|
|
171
|
+
ValueError: x is from a different linear functions module
|
|
172
|
+
"""
|
|
173
|
+
if isinstance(x, LinearFunction):
|
|
174
|
+
if self.parent().linear_functions() != x.parent():
|
|
175
|
+
raise ValueError('x is from a different linear functions module')
|
|
176
|
+
if len((<LinearFunction>x)._f) != 1:
|
|
177
|
+
raise ValueError('x is a sum, must be a single variable')
|
|
178
|
+
i, = (<LinearFunction>x)._f.keys()
|
|
179
|
+
if (<LinearFunction>x)._f[i] != 1:
|
|
180
|
+
raise ValueError('x must have a unit coefficient')
|
|
181
|
+
else:
|
|
182
|
+
i = int(x)
|
|
183
|
+
try:
|
|
184
|
+
return self._f[i]
|
|
185
|
+
except KeyError:
|
|
186
|
+
return self.parent().free_module().zero()
|
|
187
|
+
|
|
188
|
+
def _repr_(self):
|
|
189
|
+
"""
|
|
190
|
+
Return a string representation.
|
|
191
|
+
|
|
192
|
+
OUTPUT: string
|
|
193
|
+
|
|
194
|
+
EXAMPLES::
|
|
195
|
+
|
|
196
|
+
sage: from sage.numerical.linear_functions import LinearFunctionsParent
|
|
197
|
+
sage: R.<s,t> = RDF[]
|
|
198
|
+
sage: LT = LinearFunctionsParent(RDF).tensor(R)
|
|
199
|
+
sage: LT.an_element() # indirect doctest
|
|
200
|
+
(s) + (5.0*s)*x_2 + (7.0*s)*x_5
|
|
201
|
+
|
|
202
|
+
sage: LT = LinearFunctionsParent(RDF).tensor(RDF^2)
|
|
203
|
+
sage: LT.an_element() # indirect doctest
|
|
204
|
+
(1.0, 0.0) + (5.0, 0.0)*x_2 + (7.0, 0.0)*x_5
|
|
205
|
+
"""
|
|
206
|
+
if self.parent().is_matrix_space():
|
|
207
|
+
return self._repr_matrix()
|
|
208
|
+
terms = []
|
|
209
|
+
for key in sorted(self._f.keys()):
|
|
210
|
+
coeff = self._f[key]
|
|
211
|
+
if coeff._is_atomic():
|
|
212
|
+
if key == -1:
|
|
213
|
+
term = '({1})'.format(key, coeff)
|
|
214
|
+
else:
|
|
215
|
+
term = '({1})*x_{0}'.format(key, coeff)
|
|
216
|
+
else:
|
|
217
|
+
if key == -1:
|
|
218
|
+
term = '{1}'.format(key, coeff)
|
|
219
|
+
else:
|
|
220
|
+
term = '{1}*x_{0}'.format(key, coeff)
|
|
221
|
+
terms.append(term)
|
|
222
|
+
return ' + '.join(terms)
|
|
223
|
+
|
|
224
|
+
def _repr_matrix(self):
|
|
225
|
+
"""
|
|
226
|
+
Return a matrix-like string representation.
|
|
227
|
+
|
|
228
|
+
OUTPUT: string
|
|
229
|
+
|
|
230
|
+
EXAMPLES::
|
|
231
|
+
|
|
232
|
+
sage: from sage.numerical.linear_functions import LinearFunctionsParent
|
|
233
|
+
sage: LT = LinearFunctionsParent(RDF).tensor(RDF^(2,2))
|
|
234
|
+
sage: LT.an_element() # indirect doctest
|
|
235
|
+
[1 + 5*x_2 + 7*x_5 1 + 5*x_2 + 7*x_5]
|
|
236
|
+
[1 + 5*x_2 + 7*x_5 1 + 5*x_2 + 7*x_5]
|
|
237
|
+
"""
|
|
238
|
+
MS = self.parent().free_module()
|
|
239
|
+
assert self.parent().is_matrix_space()
|
|
240
|
+
col_lengths = []
|
|
241
|
+
columns = []
|
|
242
|
+
for c in range(MS.ncols()):
|
|
243
|
+
column = []
|
|
244
|
+
for r in range(MS.nrows()):
|
|
245
|
+
cell = repr(self[r, c])
|
|
246
|
+
column.append(cell)
|
|
247
|
+
columns.append(column)
|
|
248
|
+
col_lengths.append(max(map(len, column)))
|
|
249
|
+
s = ''
|
|
250
|
+
for r in range(MS.nrows()):
|
|
251
|
+
if r > 0:
|
|
252
|
+
s += '\n'
|
|
253
|
+
s += '['
|
|
254
|
+
for c in range(MS.ncols()):
|
|
255
|
+
if c > 0:
|
|
256
|
+
s += ' '
|
|
257
|
+
s += columns[c][r].ljust(col_lengths[c])
|
|
258
|
+
s += ']'
|
|
259
|
+
return s
|
|
260
|
+
|
|
261
|
+
cpdef _add_(self, b):
|
|
262
|
+
r"""
|
|
263
|
+
Return sum.
|
|
264
|
+
|
|
265
|
+
INPUT:
|
|
266
|
+
|
|
267
|
+
- ``b`` -- a :class:`LinearTensor`
|
|
268
|
+
|
|
269
|
+
OUTPUT: a :class:`LinearTensor`
|
|
270
|
+
|
|
271
|
+
EXAMPLES::
|
|
272
|
+
|
|
273
|
+
sage: from sage.numerical.linear_functions import LinearFunctionsParent
|
|
274
|
+
sage: LT = LinearFunctionsParent(RDF).tensor(RDF^2)
|
|
275
|
+
sage: LT({0: [1,2], 3: [-7,-8]}) + LT({2: [5,6], 3: [2,-2]}) + 16
|
|
276
|
+
(16.0, 16.0) + (1.0, 2.0)*x_0 + (5.0, 6.0)*x_2 + (-5.0, -10.0)*x_3
|
|
277
|
+
"""
|
|
278
|
+
result = dict(self._f)
|
|
279
|
+
for key, coeff in b.dict().iteritems():
|
|
280
|
+
result[key] = self._f.get(key, 0) + coeff
|
|
281
|
+
return self.parent()(result)
|
|
282
|
+
|
|
283
|
+
cpdef _neg_(self):
|
|
284
|
+
r"""
|
|
285
|
+
Return the negative.
|
|
286
|
+
|
|
287
|
+
OUTPUT: a :class:`LinearTensor`
|
|
288
|
+
|
|
289
|
+
EXAMPLES::
|
|
290
|
+
|
|
291
|
+
sage: from sage.numerical.linear_functions import LinearFunctionsParent
|
|
292
|
+
sage: LT = LinearFunctionsParent(RDF).tensor(RDF^2)
|
|
293
|
+
sage: -LT({0: [1,2], 3: [-7,-8]})
|
|
294
|
+
(-1.0, -2.0)*x_0 + (7.0, 8.0)*x_3
|
|
295
|
+
"""
|
|
296
|
+
result = dict()
|
|
297
|
+
for key, coeff in self._f.items():
|
|
298
|
+
result[key] = -coeff
|
|
299
|
+
return self.parent()(result)
|
|
300
|
+
|
|
301
|
+
cpdef _sub_(self, b):
|
|
302
|
+
r"""
|
|
303
|
+
Return difference.
|
|
304
|
+
|
|
305
|
+
INPUT:
|
|
306
|
+
|
|
307
|
+
- ``b`` -- a :class:`LinearTensor`
|
|
308
|
+
|
|
309
|
+
OUTPUT: a :class:`LinearTensor`
|
|
310
|
+
|
|
311
|
+
EXAMPLES::
|
|
312
|
+
|
|
313
|
+
sage: from sage.numerical.linear_functions import LinearFunctionsParent
|
|
314
|
+
sage: LT = LinearFunctionsParent(RDF).tensor(RDF^2)
|
|
315
|
+
sage: LT({0: [1,2], 3: [-7,-8]}) - LT({1: [1,2]})
|
|
316
|
+
(1.0, 2.0)*x_0 + (-1.0, -2.0)*x_1 + (-7.0, -8.0)*x_3
|
|
317
|
+
sage: LT({0: [1,2], 3: [-7,-8]}) - 16
|
|
318
|
+
(-16.0, -16.0) + (1.0, 2.0)*x_0 + (-7.0, -8.0)*x_3
|
|
319
|
+
"""
|
|
320
|
+
result = dict(self._f)
|
|
321
|
+
for key, coeff in b.dict().iteritems():
|
|
322
|
+
result[key] = self._f.get(key, 0) - coeff
|
|
323
|
+
return self.parent()(result)
|
|
324
|
+
|
|
325
|
+
cpdef _lmul_(self, Element b):
|
|
326
|
+
r"""
|
|
327
|
+
Return multiplication by scalar.
|
|
328
|
+
|
|
329
|
+
INPUT:
|
|
330
|
+
|
|
331
|
+
- ``b`` -- base ring element; the scalar to multiply by
|
|
332
|
+
|
|
333
|
+
OUTPUT: a :class:`LinearTensor`
|
|
334
|
+
|
|
335
|
+
EXAMPLES::
|
|
336
|
+
|
|
337
|
+
sage: from sage.numerical.linear_functions import LinearFunctionsParent
|
|
338
|
+
sage: LT = LinearFunctionsParent(RDF).tensor(RDF^2)
|
|
339
|
+
sage: 10 * LT({0: [1,2], 3: [-7,-8]})
|
|
340
|
+
(10.0, 20.0)*x_0 + (-70.0, -80.0)*x_3
|
|
341
|
+
"""
|
|
342
|
+
result = dict()
|
|
343
|
+
for key, coeff in self._f.items():
|
|
344
|
+
result[key] = b * coeff
|
|
345
|
+
return self.parent()(result)
|
|
346
|
+
|
|
347
|
+
def __richcmp__(left, right, int op):
|
|
348
|
+
"""
|
|
349
|
+
Create an inequality or equality object.
|
|
350
|
+
|
|
351
|
+
EXAMPLES::
|
|
352
|
+
|
|
353
|
+
sage: mip.<x> = MixedIntegerLinearProgram()
|
|
354
|
+
sage: lt0 = x[0] * vector([1,2])
|
|
355
|
+
sage: lt1 = x[1] * vector([2,3])
|
|
356
|
+
sage: lt0.__le__(lt1) # indirect doctest
|
|
357
|
+
(1.0, 2.0)*x_0 <= (2.0, 3.0)*x_1
|
|
358
|
+
|
|
359
|
+
::
|
|
360
|
+
|
|
361
|
+
sage: mip.<x> = MixedIntegerLinearProgram()
|
|
362
|
+
sage: from sage.numerical.linear_functions import LinearFunction
|
|
363
|
+
sage: x[0] * vector([1,2]) <= x[1] * vector([2,3])
|
|
364
|
+
(1.0, 2.0)*x_0 <= (2.0, 3.0)*x_1
|
|
365
|
+
|
|
366
|
+
sage: x[0] * vector([1,2]) >= x[1] * vector([2,3])
|
|
367
|
+
(2.0, 3.0)*x_1 <= (1.0, 2.0)*x_0
|
|
368
|
+
|
|
369
|
+
sage: x[0] * vector([1,2]) == x[1] * vector([2,3])
|
|
370
|
+
(1.0, 2.0)*x_0 == (2.0, 3.0)*x_1
|
|
371
|
+
|
|
372
|
+
sage: x[0] * vector([1,2]) < x[1] * vector([2,3])
|
|
373
|
+
Traceback (most recent call last):
|
|
374
|
+
...
|
|
375
|
+
ValueError: strict < is not allowed, use <= instead.
|
|
376
|
+
|
|
377
|
+
sage: x[0] * vector([1,2]) > x[1] * vector([2,3])
|
|
378
|
+
Traceback (most recent call last):
|
|
379
|
+
...
|
|
380
|
+
ValueError: strict > is not allowed, use >= instead.
|
|
381
|
+
|
|
382
|
+
TESTS::
|
|
383
|
+
|
|
384
|
+
sage: lt = x[0] * vector([1,2])
|
|
385
|
+
sage: cm = sage.structure.element.get_coercion_model()
|
|
386
|
+
sage: cm.explain(10, lt, operator.le)
|
|
387
|
+
Coercion on left operand via
|
|
388
|
+
Coercion map:
|
|
389
|
+
From: Integer Ring
|
|
390
|
+
To: Tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field
|
|
391
|
+
Arithmetic performed after coercions.
|
|
392
|
+
Result lives in Tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field
|
|
393
|
+
Tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field
|
|
394
|
+
|
|
395
|
+
sage: operator.le(10, lt)
|
|
396
|
+
(10.0, 10.0) <= (1.0, 2.0)*x_0
|
|
397
|
+
sage: lt <= 1
|
|
398
|
+
(1.0, 2.0)*x_0 <= (1.0, 1.0)
|
|
399
|
+
sage: lt >= 1
|
|
400
|
+
(1.0, 1.0) <= (1.0, 2.0)*x_0
|
|
401
|
+
sage: 1 <= lt
|
|
402
|
+
(1.0, 1.0) <= (1.0, 2.0)*x_0
|
|
403
|
+
sage: 1 >= lt
|
|
404
|
+
(1.0, 2.0)*x_0 <= (1.0, 1.0)
|
|
405
|
+
"""
|
|
406
|
+
from sage.numerical.linear_tensor_constraints import \
|
|
407
|
+
LinearTensorConstraintsParent
|
|
408
|
+
LT = left.parent()
|
|
409
|
+
LC = LinearTensorConstraintsParent(LT)
|
|
410
|
+
left = LT(left)
|
|
411
|
+
right = LT(right)
|
|
412
|
+
if op == Py_LT:
|
|
413
|
+
raise ValueError("strict < is not allowed, use <= instead.")
|
|
414
|
+
elif op == Py_EQ:
|
|
415
|
+
return LC(left, right, True)
|
|
416
|
+
elif op == Py_GT:
|
|
417
|
+
raise ValueError("strict > is not allowed, use >= instead.")
|
|
418
|
+
elif op == Py_LE:
|
|
419
|
+
return LC(left, right, False)
|
|
420
|
+
elif op == Py_NE:
|
|
421
|
+
raise ValueError("inequality != is not allowed, use one of <=, ==, >=.")
|
|
422
|
+
elif op == Py_GE:
|
|
423
|
+
return LC(right, left, False)
|
|
424
|
+
else:
|
|
425
|
+
assert False # unreachable
|
|
426
|
+
|
|
427
|
+
def __hash__(self):
|
|
428
|
+
r"""
|
|
429
|
+
Return a hash.
|
|
430
|
+
|
|
431
|
+
EXAMPLES::
|
|
432
|
+
|
|
433
|
+
sage: p = MixedIntegerLinearProgram()
|
|
434
|
+
sage: lt0 = p[0] * vector([1,2])
|
|
435
|
+
sage: hash(lt0) # random output
|
|
436
|
+
103987752
|
|
437
|
+
sage: d = {}
|
|
438
|
+
sage: d[lt0] = 3
|
|
439
|
+
|
|
440
|
+
Since we hash by ``id()``, linear functions and constraints are
|
|
441
|
+
only considered equal for sets and dicts if they are the same
|
|
442
|
+
object::
|
|
443
|
+
|
|
444
|
+
sage: f = p[0] * vector([1])
|
|
445
|
+
sage: g = p[0] * vector([1])
|
|
446
|
+
sage: set([f, f])
|
|
447
|
+
{((1.0))*x_0}
|
|
448
|
+
sage: set([f, g])
|
|
449
|
+
{((1.0))*x_0, ((1.0))*x_0}
|
|
450
|
+
sage: len(set([f, f+1]))
|
|
451
|
+
2
|
|
452
|
+
|
|
453
|
+
sage: d = {}
|
|
454
|
+
sage: d[f] = 123
|
|
455
|
+
sage: d[g] = 456
|
|
456
|
+
sage: len(list(d))
|
|
457
|
+
2
|
|
458
|
+
"""
|
|
459
|
+
return hash_by_id(<void *> self)
|
|
Binary file
|
sage/numerical/mip.pxd
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-polyhedra
|
|
2
|
+
cdef extern from *:
|
|
3
|
+
cdef int BINARY = 1
|
|
4
|
+
cdef int REAL = -1
|
|
5
|
+
cdef int INTEGER = 0
|
|
6
|
+
|
|
7
|
+
from sage.sets.family cimport FiniteFamily
|
|
8
|
+
from sage.structure.sage_object cimport SageObject
|
|
9
|
+
from sage.numerical.backends.generic_backend cimport GenericBackend
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
cdef class MIPVariable
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
cdef class MixedIntegerLinearProgram(SageObject):
|
|
16
|
+
cdef GenericBackend _backend
|
|
17
|
+
cdef list _first_variable_names
|
|
18
|
+
cdef list _mipvariables
|
|
19
|
+
cdef MIPVariable _default_mipvariable
|
|
20
|
+
cdef dict _variables
|
|
21
|
+
cdef int __BINARY
|
|
22
|
+
cdef int __REAL
|
|
23
|
+
cdef int __INTEGER
|
|
24
|
+
cdef object _linear_functions_parent
|
|
25
|
+
cdef object _linear_constraints_parent
|
|
26
|
+
cpdef int number_of_constraints(self) noexcept
|
|
27
|
+
cpdef int number_of_variables(self) noexcept
|
|
28
|
+
cdef int _check_redundant
|
|
29
|
+
cdef list _constraints
|
|
30
|
+
cpdef sum(self, L)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
cdef class MIPVariable(FiniteFamily):
|
|
34
|
+
cdef MixedIntegerLinearProgram _p
|
|
35
|
+
cdef int _vtype
|
|
36
|
+
cdef str _name
|
|
37
|
+
cdef object _lower_bound
|
|
38
|
+
cdef object _upper_bound
|
|
39
|
+
cdef _matrix_rmul_impl(self, m)
|
|
40
|
+
cdef _matrix_lmul_impl(self, m)
|