passagemath-polyhedra 10.6.31rc3__cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_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 +206 -0
- passagemath_polyhedra-10.6.31rc3.dist-info/WHEEL +6 -0
- passagemath_polyhedra-10.6.31rc3.dist-info/top_level.txt +2 -0
- passagemath_polyhedra.libs/libgmp-6e109695.so.10.5.0 +0 -0
- passagemath_polyhedra.libs/libgomp-e985bcbb.so.1.0.0 +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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.so +0 -0
- sage/numerical/backends/cvxopt_sdp_backend.pyx +382 -0
- sage/numerical/backends/cvxpy_backend.cpython-314-x86_64-linux-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.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-gnu.so +0 -0
- sage/numerical/mip.pxd +40 -0
- sage/numerical/mip.pyx +3667 -0
- sage/numerical/sdp.cpython-314-x86_64-linux-gnu.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-gnu.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,478 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-polyhedra
|
|
2
|
+
r"""
|
|
3
|
+
Matrix Backend for SDP solvers
|
|
4
|
+
|
|
5
|
+
It stores the SDP data in Sage matrices. It allows users to specify a base ring
|
|
6
|
+
and can store either floating-point SDPs or exact SDPs with rational or algebraic data.
|
|
7
|
+
|
|
8
|
+
The class does not provide a solver method. It can be used as a base class for
|
|
9
|
+
other classes implementing solvers.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
#*****************************************************************************
|
|
13
|
+
# Copyright (C) 2014 Ingolfur Edvardsson <ingolfured@gmail.com>
|
|
14
|
+
# Copyright (C) 2020 Matthias Koeppe <mkoeppe@math.ucdavis.edu>
|
|
15
|
+
#
|
|
16
|
+
# This program is free software: you can redistribute it and/or modify
|
|
17
|
+
# it under the terms of the GNU General Public License as published by
|
|
18
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
19
|
+
# (at your option) any later version.
|
|
20
|
+
# http://www.gnu.org/licenses/
|
|
21
|
+
#*****************************************************************************
|
|
22
|
+
|
|
23
|
+
from sage.matrix.constructor import matrix
|
|
24
|
+
from sage.numerical.backends.generic_sdp_backend cimport GenericSDPBackend
|
|
25
|
+
|
|
26
|
+
cdef class MatrixSDPBackend(GenericSDPBackend):
|
|
27
|
+
|
|
28
|
+
def __init__(self, maximization=True, base_ring=None):
|
|
29
|
+
"""
|
|
30
|
+
Cython constructor.
|
|
31
|
+
|
|
32
|
+
EXAMPLES::
|
|
33
|
+
|
|
34
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
35
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
36
|
+
"""
|
|
37
|
+
self.objective_function = []
|
|
38
|
+
self.name = ""
|
|
39
|
+
self.coeffs_matrix = []
|
|
40
|
+
self.obj_constant_term = 0
|
|
41
|
+
self.matrices_dim = {}
|
|
42
|
+
self.is_maximize = 1
|
|
43
|
+
|
|
44
|
+
self.row_name_var = []
|
|
45
|
+
self.col_name_var = []
|
|
46
|
+
|
|
47
|
+
if maximization:
|
|
48
|
+
self.set_sense(+1)
|
|
49
|
+
else:
|
|
50
|
+
self.set_sense(-1)
|
|
51
|
+
|
|
52
|
+
if base_ring is None:
|
|
53
|
+
from sage.rings.rational_field import QQ
|
|
54
|
+
base_ring = QQ
|
|
55
|
+
self._base_ring = base_ring
|
|
56
|
+
|
|
57
|
+
cpdef base_ring(self):
|
|
58
|
+
"""
|
|
59
|
+
The base ring.
|
|
60
|
+
|
|
61
|
+
TESTS::
|
|
62
|
+
|
|
63
|
+
sage: from sage.numerical.backends.matrix_sdp_backend import MatrixSDPBackend
|
|
64
|
+
sage: MatrixSDPBackend(base_ring=QQ).base_ring()
|
|
65
|
+
Rational Field
|
|
66
|
+
"""
|
|
67
|
+
return self._base_ring
|
|
68
|
+
|
|
69
|
+
def get_matrix(self):
|
|
70
|
+
"""
|
|
71
|
+
Get a block of a matrix coefficient.
|
|
72
|
+
|
|
73
|
+
EXAMPLES::
|
|
74
|
+
|
|
75
|
+
sage: p = SemidefiniteProgram(solver='cvxopt')
|
|
76
|
+
sage: x = p.new_variable()
|
|
77
|
+
sage: a1 = matrix([[1, 2.], [2., 3.]])
|
|
78
|
+
sage: a2 = matrix([[3, 4.], [4., 5.]])
|
|
79
|
+
sage: p.add_constraint(a1*x[0] + a2*x[1] <= a1)
|
|
80
|
+
sage: b = p.get_backend()
|
|
81
|
+
sage: b.get_matrix()[0][0]
|
|
82
|
+
(
|
|
83
|
+
[-1.0 -2.0]
|
|
84
|
+
-1, [-2.0 -3.0]
|
|
85
|
+
)
|
|
86
|
+
"""
|
|
87
|
+
return self.coeffs_matrix
|
|
88
|
+
|
|
89
|
+
cpdef int add_variable(self, obj=0.0, name=None) except -1:
|
|
90
|
+
"""
|
|
91
|
+
Add a variable.
|
|
92
|
+
|
|
93
|
+
This amounts to adding a new column of matrices to the matrix. By default,
|
|
94
|
+
the variable is both positive and real.
|
|
95
|
+
|
|
96
|
+
INPUT:
|
|
97
|
+
|
|
98
|
+
- ``obj`` -- (optional) coefficient of this variable in the objective
|
|
99
|
+
function (default: 0.0)
|
|
100
|
+
|
|
101
|
+
- ``name`` -- an optional name for the newly added variable (default:
|
|
102
|
+
``None``)
|
|
103
|
+
|
|
104
|
+
OUTPUT: the index of the newly created variable
|
|
105
|
+
|
|
106
|
+
EXAMPLES::
|
|
107
|
+
|
|
108
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
109
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
110
|
+
sage: p.ncols()
|
|
111
|
+
0
|
|
112
|
+
sage: p.add_variable()
|
|
113
|
+
0
|
|
114
|
+
sage: p.ncols()
|
|
115
|
+
1
|
|
116
|
+
sage: p.add_variable()
|
|
117
|
+
1
|
|
118
|
+
sage: p.add_variable(name='x',obj=1.0)
|
|
119
|
+
2
|
|
120
|
+
sage: p.col_name(2)
|
|
121
|
+
'x'
|
|
122
|
+
sage: p.objective_coefficient(2)
|
|
123
|
+
1.00000000000000
|
|
124
|
+
"""
|
|
125
|
+
i = 0
|
|
126
|
+
for row in self.coeffs_matrix:
|
|
127
|
+
if self.matrices_dim.get(i) is not None:
|
|
128
|
+
row.append( matrix.zero(self.matrices_dim[i], self.matrices_dim[i]) )
|
|
129
|
+
else:
|
|
130
|
+
row.append(0)
|
|
131
|
+
i += 1
|
|
132
|
+
self.col_name_var.append(name)
|
|
133
|
+
self.objective_function.append(obj)
|
|
134
|
+
return len(self.objective_function) - 1
|
|
135
|
+
|
|
136
|
+
cpdef int add_variables(self, int n, names=None) except -1:
|
|
137
|
+
"""
|
|
138
|
+
Add ``n`` variables.
|
|
139
|
+
|
|
140
|
+
This amounts to adding new columns to the matrix. By default,
|
|
141
|
+
the variables are both positive and real.
|
|
142
|
+
|
|
143
|
+
INPUT:
|
|
144
|
+
|
|
145
|
+
- ``n`` -- the number of new variables (must be > 0)
|
|
146
|
+
|
|
147
|
+
- ``names`` -- list of names (default: ``None``)
|
|
148
|
+
|
|
149
|
+
OUTPUT: the index of the variable created last
|
|
150
|
+
|
|
151
|
+
EXAMPLES::
|
|
152
|
+
|
|
153
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
154
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
155
|
+
sage: p.ncols()
|
|
156
|
+
0
|
|
157
|
+
sage: p.add_variables(5)
|
|
158
|
+
4
|
|
159
|
+
sage: p.ncols()
|
|
160
|
+
5
|
|
161
|
+
sage: p.add_variables(2, names=['a','b'])
|
|
162
|
+
6
|
|
163
|
+
"""
|
|
164
|
+
for i in range(n):
|
|
165
|
+
self.add_variable()
|
|
166
|
+
return len(self.objective_function) - 1
|
|
167
|
+
|
|
168
|
+
cpdef set_sense(self, int sense):
|
|
169
|
+
"""
|
|
170
|
+
Set the direction (maximization/minimization).
|
|
171
|
+
|
|
172
|
+
INPUT:
|
|
173
|
+
|
|
174
|
+
- ``sense`` -- integer:
|
|
175
|
+
|
|
176
|
+
* +1 => Maximization
|
|
177
|
+
* -1 => Minimization
|
|
178
|
+
|
|
179
|
+
EXAMPLES::
|
|
180
|
+
|
|
181
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
182
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
183
|
+
sage: p.is_maximization()
|
|
184
|
+
True
|
|
185
|
+
sage: p.set_sense(-1)
|
|
186
|
+
sage: p.is_maximization()
|
|
187
|
+
False
|
|
188
|
+
"""
|
|
189
|
+
if sense == 1:
|
|
190
|
+
self.is_maximize = 1
|
|
191
|
+
else:
|
|
192
|
+
self.is_maximize = 0
|
|
193
|
+
|
|
194
|
+
cpdef objective_coefficient(self, int variable, coeff=None):
|
|
195
|
+
"""
|
|
196
|
+
Set or get the coefficient of a variable in the objective
|
|
197
|
+
function
|
|
198
|
+
|
|
199
|
+
INPUT:
|
|
200
|
+
|
|
201
|
+
- ``variable`` -- integer; the variable's id
|
|
202
|
+
|
|
203
|
+
- ``coeff`` -- double; its coefficient
|
|
204
|
+
|
|
205
|
+
EXAMPLES::
|
|
206
|
+
|
|
207
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
208
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
209
|
+
sage: p.add_variable()
|
|
210
|
+
0
|
|
211
|
+
sage: p.objective_coefficient(0)
|
|
212
|
+
0.0
|
|
213
|
+
sage: p.objective_coefficient(0,2)
|
|
214
|
+
sage: p.objective_coefficient(0)
|
|
215
|
+
2.0
|
|
216
|
+
"""
|
|
217
|
+
if coeff is not None:
|
|
218
|
+
self.objective_function[variable] = float(coeff)
|
|
219
|
+
else:
|
|
220
|
+
return self.objective_function[variable]
|
|
221
|
+
|
|
222
|
+
cpdef set_objective(self, list coeff, d=0.0):
|
|
223
|
+
"""
|
|
224
|
+
Set the objective function.
|
|
225
|
+
|
|
226
|
+
INPUT:
|
|
227
|
+
|
|
228
|
+
- ``coeff`` -- list of real values, whose i-th element is the
|
|
229
|
+
coefficient of the i-th variable in the objective function
|
|
230
|
+
|
|
231
|
+
- ``d`` -- double; the constant term in the linear function (set to `0`
|
|
232
|
+
by default)
|
|
233
|
+
|
|
234
|
+
EXAMPLES::
|
|
235
|
+
|
|
236
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
237
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
238
|
+
sage: p.add_variables(5)
|
|
239
|
+
4
|
|
240
|
+
sage: p.set_objective([1, 1, 2, 1, 3])
|
|
241
|
+
sage: [p.objective_coefficient(x) for x in range(5)]
|
|
242
|
+
[1, 1, 2, 1, 3]
|
|
243
|
+
"""
|
|
244
|
+
for i in range(len(coeff)):
|
|
245
|
+
self.objective_function[i] = coeff[i]
|
|
246
|
+
self.obj_constant_term = d
|
|
247
|
+
|
|
248
|
+
cpdef add_linear_constraint(self, coefficients, name=None):
|
|
249
|
+
"""
|
|
250
|
+
Add a linear constraint.
|
|
251
|
+
|
|
252
|
+
INPUT:
|
|
253
|
+
|
|
254
|
+
- ``coefficients`` an iterable with ``(c,v)`` pairs where ``c``
|
|
255
|
+
is a variable index (integer) and ``v`` is a value (matrix).
|
|
256
|
+
The pairs come sorted by indices. If c is -1 it
|
|
257
|
+
represents the constant coefficient.
|
|
258
|
+
|
|
259
|
+
- ``name`` -- an optional name for this row (default: ``None``)
|
|
260
|
+
|
|
261
|
+
EXAMPLES::
|
|
262
|
+
|
|
263
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
264
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
265
|
+
sage: p.add_variables(2)
|
|
266
|
+
1
|
|
267
|
+
sage: p.add_linear_constraint( [(0, matrix([[33., -9.], [-9., 26.]])) , (1, matrix([[-7., -11.] ,[ -11., 3.]]) )])
|
|
268
|
+
sage: p.row(0)
|
|
269
|
+
([0, 1],
|
|
270
|
+
[
|
|
271
|
+
[ 33.0000000000000 -9.00000000000000]
|
|
272
|
+
[-9.00000000000000 26.0000000000000],
|
|
273
|
+
<BLANKLINE>
|
|
274
|
+
[-7.00000000000000 -11.0000000000000]
|
|
275
|
+
[-11.0000000000000 3.00000000000000]
|
|
276
|
+
])
|
|
277
|
+
sage: p.add_linear_constraint( [(0, matrix([[33., -9.], [-9., 26.]])) , (1, matrix([[-7., -11.] ,[ -11., 3.]]) )],name='fun')
|
|
278
|
+
sage: p.row_name(-1)
|
|
279
|
+
'fun'
|
|
280
|
+
"""
|
|
281
|
+
coefficients = list(coefficients)
|
|
282
|
+
from sage.structure.element import Matrix
|
|
283
|
+
for t in coefficients:
|
|
284
|
+
m = t[1]
|
|
285
|
+
if not isinstance(m, Matrix):
|
|
286
|
+
raise ValueError("The coefficients must be matrices")
|
|
287
|
+
if not m.is_square():
|
|
288
|
+
raise ValueError("The matrix has to be a square")
|
|
289
|
+
if self.matrices_dim.get(self.nrows()) is not None and m.dimensions()[0] != self.matrices_dim.get(self.nrows()):
|
|
290
|
+
raise ValueError("the matrices have to be of the same dimension")
|
|
291
|
+
self.coeffs_matrix.append(coefficients)
|
|
292
|
+
self.matrices_dim[self.nrows()] = m.dimensions()[0] #
|
|
293
|
+
self.row_name_var.append(name)
|
|
294
|
+
|
|
295
|
+
cpdef add_linear_constraints(self, int number, names=None):
|
|
296
|
+
"""
|
|
297
|
+
Add constraints.
|
|
298
|
+
|
|
299
|
+
INPUT:
|
|
300
|
+
|
|
301
|
+
- ``number`` -- integer; the number of constraints to add
|
|
302
|
+
|
|
303
|
+
- ``names`` -- an optional list of names (default: ``None``)
|
|
304
|
+
|
|
305
|
+
EXAMPLES::
|
|
306
|
+
|
|
307
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
308
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
309
|
+
sage: p.add_variables(5)
|
|
310
|
+
4
|
|
311
|
+
sage: p.add_linear_constraints(5)
|
|
312
|
+
sage: p.row(4)
|
|
313
|
+
([], [])
|
|
314
|
+
"""
|
|
315
|
+
for i in range(number):
|
|
316
|
+
self.add_linear_constraint(zip(range(self.ncols()+1),[matrix.zero(1,1) for i in range(self.ncols()+1)]),
|
|
317
|
+
name=None if names is None else names[i])
|
|
318
|
+
|
|
319
|
+
cpdef int ncols(self) noexcept:
|
|
320
|
+
"""
|
|
321
|
+
Return the number of columns/variables.
|
|
322
|
+
|
|
323
|
+
EXAMPLES::
|
|
324
|
+
|
|
325
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
326
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
327
|
+
sage: p.ncols()
|
|
328
|
+
0
|
|
329
|
+
sage: p.add_variables(2)
|
|
330
|
+
1
|
|
331
|
+
sage: p.ncols()
|
|
332
|
+
2
|
|
333
|
+
"""
|
|
334
|
+
|
|
335
|
+
return len(self.objective_function)
|
|
336
|
+
|
|
337
|
+
cpdef int nrows(self) noexcept:
|
|
338
|
+
"""
|
|
339
|
+
Return the number of rows/constraints.
|
|
340
|
+
|
|
341
|
+
EXAMPLES::
|
|
342
|
+
|
|
343
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
344
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
345
|
+
sage: p.nrows()
|
|
346
|
+
0
|
|
347
|
+
sage: p.add_variables(5)
|
|
348
|
+
4
|
|
349
|
+
sage: p.add_linear_constraints(2)
|
|
350
|
+
sage: p.nrows()
|
|
351
|
+
2
|
|
352
|
+
"""
|
|
353
|
+
return len(self.matrices_dim)
|
|
354
|
+
|
|
355
|
+
cpdef bint is_maximization(self) noexcept:
|
|
356
|
+
"""
|
|
357
|
+
Test whether the problem is a maximization
|
|
358
|
+
|
|
359
|
+
EXAMPLES::
|
|
360
|
+
|
|
361
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
362
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
363
|
+
sage: p.is_maximization()
|
|
364
|
+
True
|
|
365
|
+
sage: p.set_sense(-1)
|
|
366
|
+
sage: p.is_maximization()
|
|
367
|
+
False
|
|
368
|
+
"""
|
|
369
|
+
if self.is_maximize == 1:
|
|
370
|
+
return 1
|
|
371
|
+
else:
|
|
372
|
+
return 0
|
|
373
|
+
|
|
374
|
+
cpdef problem_name(self, name=None):
|
|
375
|
+
"""
|
|
376
|
+
Return or define the problem's name.
|
|
377
|
+
|
|
378
|
+
INPUT:
|
|
379
|
+
|
|
380
|
+
- ``name`` -- string; the problem's name. When set to
|
|
381
|
+
``NULL`` (default), the method returns the problem's name.
|
|
382
|
+
|
|
383
|
+
EXAMPLES::
|
|
384
|
+
|
|
385
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
386
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
387
|
+
sage: p.problem_name("There once was a french fry")
|
|
388
|
+
sage: print(p.problem_name())
|
|
389
|
+
There once was a french fry
|
|
390
|
+
"""
|
|
391
|
+
if name is None:
|
|
392
|
+
return self.name
|
|
393
|
+
|
|
394
|
+
self.name = name
|
|
395
|
+
|
|
396
|
+
cpdef row(self, int i):
|
|
397
|
+
"""
|
|
398
|
+
Return a row.
|
|
399
|
+
|
|
400
|
+
INPUT:
|
|
401
|
+
|
|
402
|
+
- ``index`` -- integer; the constraint's id
|
|
403
|
+
|
|
404
|
+
OUTPUT:
|
|
405
|
+
|
|
406
|
+
A pair ``(indices, coeffs)`` where ``indices`` lists the
|
|
407
|
+
entries whose coefficient is nonzero, and to which ``coeffs``
|
|
408
|
+
associates their coefficient on the model of the
|
|
409
|
+
``add_linear_constraint`` method.
|
|
410
|
+
|
|
411
|
+
EXAMPLES::
|
|
412
|
+
|
|
413
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
414
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
415
|
+
sage: p.add_variables(5)
|
|
416
|
+
4
|
|
417
|
+
sage: p.add_linear_constraint( [(0, matrix([[33., -9.], [-9., 26.]])) , (1, matrix([[-7., -11.] ,[ -11., 3.]]) )])
|
|
418
|
+
sage: p.row(0)
|
|
419
|
+
([0, 1],
|
|
420
|
+
[
|
|
421
|
+
[ 33.0000000000000 -9.00000000000000]
|
|
422
|
+
[-9.00000000000000 26.0000000000000],
|
|
423
|
+
<BLANKLINE>
|
|
424
|
+
[-7.00000000000000 -11.0000000000000]
|
|
425
|
+
[-11.0000000000000 3.00000000000000]
|
|
426
|
+
])
|
|
427
|
+
"""
|
|
428
|
+
indices = []
|
|
429
|
+
matrices = []
|
|
430
|
+
for index,m in self.coeffs_matrix[i]:
|
|
431
|
+
if m != matrix.zero(self.matrices_dim[i],self.matrices_dim[i]):
|
|
432
|
+
indices.append(index)
|
|
433
|
+
matrices.append(m)
|
|
434
|
+
return (indices, matrices)
|
|
435
|
+
|
|
436
|
+
cpdef row_name(self, int index):
|
|
437
|
+
"""
|
|
438
|
+
Return the ``index``-th row name.
|
|
439
|
+
|
|
440
|
+
INPUT:
|
|
441
|
+
|
|
442
|
+
- ``index`` -- integer; the row's id
|
|
443
|
+
|
|
444
|
+
EXAMPLES::
|
|
445
|
+
|
|
446
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
447
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
448
|
+
sage: p.add_linear_constraints(1, names='A')
|
|
449
|
+
sage: p.row_name(0)
|
|
450
|
+
'A'
|
|
451
|
+
"""
|
|
452
|
+
if self.row_name_var[index] is not None:
|
|
453
|
+
return self.row_name_var[index]
|
|
454
|
+
return "constraint_" + repr(index)
|
|
455
|
+
|
|
456
|
+
cpdef col_name(self, int index):
|
|
457
|
+
"""
|
|
458
|
+
Return the ``index``-th col name.
|
|
459
|
+
|
|
460
|
+
INPUT:
|
|
461
|
+
|
|
462
|
+
- ``index`` -- integer; the col's id
|
|
463
|
+
|
|
464
|
+
- ``name`` -- (``char *``) its name; when set to ``NULL``
|
|
465
|
+
(default), the method returns the current name
|
|
466
|
+
|
|
467
|
+
EXAMPLES::
|
|
468
|
+
|
|
469
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
470
|
+
sage: p = get_solver(solver = "CVXOPT")
|
|
471
|
+
sage: p.add_variable(name="I am a variable")
|
|
472
|
+
0
|
|
473
|
+
sage: p.col_name(0)
|
|
474
|
+
'I am a variable'
|
|
475
|
+
"""
|
|
476
|
+
if self.col_name_var[index] is not None:
|
|
477
|
+
return self.col_name_var[index]
|
|
478
|
+
return "x_" + repr(index)
|
|
Binary file
|