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,19 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-polyhedra
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from sage.structure.sage_object import SageObject
|
|
5
|
+
from sage.numerical.backends.generic_backend_test import GenericBackendTests
|
|
6
|
+
from sage.numerical.backends.generic_backend import GenericBackend
|
|
7
|
+
from sage.numerical.mip import MixedIntegerLinearProgram
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestCVXOPTBackend(GenericBackendTests):
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
def backend(self) -> GenericBackend:
|
|
14
|
+
return MixedIntegerLinearProgram(solver="CVXOPT").get_backend()
|
|
15
|
+
|
|
16
|
+
def test_sage_unittest_testsuite(self, sage_object: SageObject):
|
|
17
|
+
# TODO: Remove this test as soon as all old test methods are migrated
|
|
18
|
+
from sage.misc.sage_unittest import TestSuite
|
|
19
|
+
TestSuite(sage_object).run(verbose=True, raise_on_failure=True, skip=("_test_pickling","_test_solve","_test_solve_trac_18572"))
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-polyhedra
|
|
2
|
+
# sage.doctest: needs cvxopt
|
|
3
|
+
r"""
|
|
4
|
+
CVXOPT SDP Backend
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
AUTHORS:
|
|
8
|
+
|
|
9
|
+
- Ingolfur Edvardsson (2014-05): initial implementation
|
|
10
|
+
|
|
11
|
+
- Dima Pasechnik (2015-12): minor fixes
|
|
12
|
+
"""
|
|
13
|
+
#*****************************************************************************
|
|
14
|
+
# Copyright (C) 2014 Ingolfur Edvardsson <ingolfured@gmail.com>
|
|
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.numerical.sdp import SDPSolverException
|
|
24
|
+
from sage.matrix.constructor import Matrix
|
|
25
|
+
from sage.numerical.backends.matrix_sdp_backend cimport MatrixSDPBackend
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
cdef class CVXOPTSDPBackend(MatrixSDPBackend):
|
|
29
|
+
|
|
30
|
+
cdef dict answer
|
|
31
|
+
cdef dict param
|
|
32
|
+
|
|
33
|
+
def __init__(self, maximization=True, base_ring=None):
|
|
34
|
+
"""
|
|
35
|
+
Cython constructor.
|
|
36
|
+
|
|
37
|
+
EXAMPLES::
|
|
38
|
+
|
|
39
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
40
|
+
sage: p = get_solver(solver='CVXOPT')
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
from sage.rings.real_double import RDF
|
|
44
|
+
if base_ring is None:
|
|
45
|
+
base_ring = RDF
|
|
46
|
+
if base_ring is not RDF:
|
|
47
|
+
raise ValueError("only base_ring=RDF is supported")
|
|
48
|
+
MatrixSDPBackend.__init__(self, maximization, base_ring=base_ring)
|
|
49
|
+
|
|
50
|
+
self.param = {"show_progress":False,
|
|
51
|
+
"maxiters":100,
|
|
52
|
+
"abstol":1e-7,
|
|
53
|
+
"reltol":1e-6,
|
|
54
|
+
"feastol":1e-7,
|
|
55
|
+
"refinement":1 }
|
|
56
|
+
self.answer = {}
|
|
57
|
+
|
|
58
|
+
cpdef int solve(self) except -1:
|
|
59
|
+
"""
|
|
60
|
+
Solve the problem.
|
|
61
|
+
|
|
62
|
+
.. NOTE::
|
|
63
|
+
|
|
64
|
+
This method raises :class:`SDPSolverException` exceptions when
|
|
65
|
+
the solution cannot be computed for any reason (none
|
|
66
|
+
exists, or the LP solver was not able to find it, etc...)
|
|
67
|
+
|
|
68
|
+
EXAMPLES::
|
|
69
|
+
|
|
70
|
+
sage: p = SemidefiniteProgram(solver='cvxopt', maximization=False)
|
|
71
|
+
sage: x = p.new_variable()
|
|
72
|
+
sage: p.set_objective(x[0] - x[1] + x[2])
|
|
73
|
+
sage: a1 = matrix([[-7., -11.], [-11., 3.]])
|
|
74
|
+
sage: a2 = matrix([[7., -18.], [-18., 8.]])
|
|
75
|
+
sage: a3 = matrix([[-2., -8.], [-8., 1.]])
|
|
76
|
+
sage: a4 = matrix([[33., -9.], [-9., 26.]])
|
|
77
|
+
sage: b1 = matrix([[-21., -11., 0.], [-11., 10., 8.], [0., 8., 5.]])
|
|
78
|
+
sage: b2 = matrix([[0., 10., 16.], [10., -10., -10.], [16., -10., 3.]])
|
|
79
|
+
sage: b3 = matrix([[-5., 2., -17.], [2., -6., 8.], [-17., 8., 6.]])
|
|
80
|
+
sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])
|
|
81
|
+
sage: p.add_constraint(a1*x[0] + a3*x[2] <= a4)
|
|
82
|
+
sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4)
|
|
83
|
+
sage: N(p.solve(), digits=4)
|
|
84
|
+
-3.225
|
|
85
|
+
sage: p = SemidefiniteProgram(solver='cvxopt', maximization=False)
|
|
86
|
+
sage: x = p.new_variable()
|
|
87
|
+
sage: p.set_objective(x[0] - x[1] + x[2])
|
|
88
|
+
sage: a1 = matrix([[-7., -11.], [-11., 3.]])
|
|
89
|
+
sage: a2 = matrix([[7., -18.], [-18., 8.]])
|
|
90
|
+
sage: a3 = matrix([[-2., -8.], [-8., 1.]])
|
|
91
|
+
sage: a4 = matrix([[33., -9.], [-9., 26.]])
|
|
92
|
+
sage: b1 = matrix([[-21., -11., 0.], [-11., 10., 8.], [0., 8., 5.]])
|
|
93
|
+
sage: b2 = matrix([[0., 10., 16.], [10., -10., -10.], [16., -10., 3.]])
|
|
94
|
+
sage: b3 = matrix([[-5., 2., -17.], [2., -6., 8.], [-17., 8., 6.]])
|
|
95
|
+
sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])
|
|
96
|
+
sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4)
|
|
97
|
+
sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4)
|
|
98
|
+
sage: N(p.solve(), digits=4)
|
|
99
|
+
-3.154
|
|
100
|
+
"""
|
|
101
|
+
from cvxopt import matrix as c_matrix, solvers
|
|
102
|
+
from sage.rings.real_double import RDF
|
|
103
|
+
G_matrix = []
|
|
104
|
+
h_matrix = []
|
|
105
|
+
debug_g = []
|
|
106
|
+
debug_h = []
|
|
107
|
+
debug_c = []
|
|
108
|
+
|
|
109
|
+
#cvxopt minimizes on default
|
|
110
|
+
if self.is_maximize:
|
|
111
|
+
c = [-1 * float(e) for e in self.objective_function]
|
|
112
|
+
else:
|
|
113
|
+
c = [float(e) for e in self.objective_function]
|
|
114
|
+
debug_c = (c)
|
|
115
|
+
c = c_matrix(c)
|
|
116
|
+
|
|
117
|
+
row_index = -1
|
|
118
|
+
for row in self.coeffs_matrix:
|
|
119
|
+
row_index += 1
|
|
120
|
+
row.sort()
|
|
121
|
+
G_temp = []
|
|
122
|
+
add_null = [True for i in range(self.ncols())]
|
|
123
|
+
for i,m in row:
|
|
124
|
+
if i == -1:
|
|
125
|
+
h_temp = []
|
|
126
|
+
for row in m.rows():
|
|
127
|
+
row_temp = []
|
|
128
|
+
for e in row:
|
|
129
|
+
row_temp.append(-1*float(e))
|
|
130
|
+
h_temp.append(row_temp)
|
|
131
|
+
h_matrix += [c_matrix(h_temp)]
|
|
132
|
+
debug_h += [h_temp]
|
|
133
|
+
else:
|
|
134
|
+
add_null[i] = False
|
|
135
|
+
m = [float(e) for e in m.list()]
|
|
136
|
+
G_temp.append(m)
|
|
137
|
+
for j in range(self.ncols()):
|
|
138
|
+
if add_null[j]:
|
|
139
|
+
G_temp.insert(j,[float(0) for t in range(self.matrices_dim[row_index]**2)])
|
|
140
|
+
G_matrix += [c_matrix(G_temp)]
|
|
141
|
+
debug_g += [(G_temp)]
|
|
142
|
+
#raise Exception("G_matrix " + str(debug_g) + "\nh_matrix: " + str(debug_h) + "\nc_matrix: " + str(debug_c))
|
|
143
|
+
|
|
144
|
+
#solvers comes from the cvxopt library
|
|
145
|
+
for k,v in self.param.iteritems():
|
|
146
|
+
solvers.options[k] = v
|
|
147
|
+
|
|
148
|
+
self.answer = solvers.sdp(c,Gs=G_matrix,hs=h_matrix)
|
|
149
|
+
|
|
150
|
+
#possible outcomes
|
|
151
|
+
if self.answer['status'] == 'optimized':
|
|
152
|
+
pass
|
|
153
|
+
elif self.answer['status'] == 'primal infeasible':
|
|
154
|
+
raise SDPSolverException("CVXOPT: primal infeasible")
|
|
155
|
+
elif self.answer['status'] == 'dual infeasible':
|
|
156
|
+
raise SDPSolverException("CVXOPT: dual infeasible")
|
|
157
|
+
elif self.answer['status'] == 'unknown':
|
|
158
|
+
raise SDPSolverException("CVXOPT: Terminated early due to numerical difficulties or because the maximum number of iterations was reached.")
|
|
159
|
+
return 0
|
|
160
|
+
|
|
161
|
+
cpdef get_objective_value(self):
|
|
162
|
+
"""
|
|
163
|
+
Return the value of the objective function.
|
|
164
|
+
|
|
165
|
+
.. NOTE::
|
|
166
|
+
|
|
167
|
+
Behaviour is undefined unless ``solve`` has been called before.
|
|
168
|
+
|
|
169
|
+
EXAMPLES::
|
|
170
|
+
|
|
171
|
+
sage: p = SemidefiniteProgram(solver='cvxopt', maximization=False)
|
|
172
|
+
sage: x = p.new_variable()
|
|
173
|
+
sage: p.set_objective(x[0] - x[1] + x[2])
|
|
174
|
+
sage: a1 = matrix([[-7., -11.], [-11., 3.]])
|
|
175
|
+
sage: a2 = matrix([[7., -18.], [-18., 8.]])
|
|
176
|
+
sage: a3 = matrix([[-2., -8.], [-8., 1.]])
|
|
177
|
+
sage: a4 = matrix([[33., -9.], [-9., 26.]])
|
|
178
|
+
sage: b1 = matrix([[-21., -11., 0.], [-11., 10., 8.], [0., 8., 5.]])
|
|
179
|
+
sage: b2 = matrix([[0., 10., 16.], [10., -10., -10.], [16., -10., 3.]])
|
|
180
|
+
sage: b3 = matrix([[-5., 2., -17.], [2., -6., 8.], [-17., 8., 6.]])
|
|
181
|
+
sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])
|
|
182
|
+
sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4)
|
|
183
|
+
sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4)
|
|
184
|
+
sage: N(p.solve(), digits=4)
|
|
185
|
+
-3.154
|
|
186
|
+
sage: N(p.get_backend().get_objective_value(), digits=4)
|
|
187
|
+
-3.154
|
|
188
|
+
"""
|
|
189
|
+
sum = self.obj_constant_term
|
|
190
|
+
i = 0
|
|
191
|
+
for v in self.objective_function:
|
|
192
|
+
sum += v * float(self.answer['x'][i])
|
|
193
|
+
i+=1
|
|
194
|
+
return sum
|
|
195
|
+
|
|
196
|
+
cpdef _get_answer(self):
|
|
197
|
+
"""
|
|
198
|
+
Return the complete output dict of the solver.
|
|
199
|
+
|
|
200
|
+
Mainly for testing purposes
|
|
201
|
+
|
|
202
|
+
TESTS::
|
|
203
|
+
|
|
204
|
+
sage: p = SemidefiniteProgram(maximization=False, solver='cvxopt')
|
|
205
|
+
sage: x = p.new_variable()
|
|
206
|
+
sage: p.set_objective(x[0] - x[1])
|
|
207
|
+
sage: a1 = matrix([[1, 2.], [2., 3.]])
|
|
208
|
+
sage: a2 = matrix([[3, 4.], [4., 5.]])
|
|
209
|
+
sage: a3 = matrix([[5, 6.], [6., 7.]])
|
|
210
|
+
sage: b1 = matrix([[1, 1.], [1., 1.]])
|
|
211
|
+
sage: b2 = matrix([[2, 2.], [2., 2.]])
|
|
212
|
+
sage: b3 = matrix([[3, 3.], [3., 3.]])
|
|
213
|
+
sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3)
|
|
214
|
+
sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3)
|
|
215
|
+
sage: p.solve(); # tol 1e-08
|
|
216
|
+
-3.0
|
|
217
|
+
sage: p.get_backend()._get_answer()
|
|
218
|
+
{...}
|
|
219
|
+
"""
|
|
220
|
+
return self.answer
|
|
221
|
+
|
|
222
|
+
cpdef get_variable_value(self, int variable):
|
|
223
|
+
"""
|
|
224
|
+
Return the value of a variable given by the solver.
|
|
225
|
+
|
|
226
|
+
.. NOTE::
|
|
227
|
+
|
|
228
|
+
Behaviour is undefined unless ``solve`` has been called before.
|
|
229
|
+
|
|
230
|
+
EXAMPLES::
|
|
231
|
+
|
|
232
|
+
sage: p = SemidefiniteProgram(solver='cvxopt', maximization=False)
|
|
233
|
+
sage: x = p.new_variable()
|
|
234
|
+
sage: p.set_objective(x[0] - x[1] + x[2])
|
|
235
|
+
sage: a1 = matrix([[-7., -11.], [-11., 3.]])
|
|
236
|
+
sage: a2 = matrix([[7., -18.], [-18., 8.]])
|
|
237
|
+
sage: a3 = matrix([[-2., -8.], [-8., 1.]])
|
|
238
|
+
sage: a4 = matrix([[33., -9.], [-9., 26.]])
|
|
239
|
+
sage: b1 = matrix([[-21., -11., 0.], [-11., 10., 8.], [0., 8., 5.]])
|
|
240
|
+
sage: b2 = matrix([[0., 10., 16.], [10., -10., -10.], [16., -10., 3.]])
|
|
241
|
+
sage: b3 = matrix([[-5., 2., -17.], [2., -6., 8.], [-17., 8., 6.]])
|
|
242
|
+
sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])
|
|
243
|
+
sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4)
|
|
244
|
+
sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4)
|
|
245
|
+
sage: N(p.solve(), digits=4)
|
|
246
|
+
-3.154
|
|
247
|
+
sage: N(p.get_backend().get_variable_value(0), digits=3)
|
|
248
|
+
-0.368
|
|
249
|
+
sage: N(p.get_backend().get_variable_value(1), digits=4)
|
|
250
|
+
1.898
|
|
251
|
+
sage: N(p.get_backend().get_variable_value(2), digits=3)
|
|
252
|
+
-0.888
|
|
253
|
+
"""
|
|
254
|
+
return self.answer['x'][variable]
|
|
255
|
+
|
|
256
|
+
cpdef dual_variable(self, int i, sparse=False):
|
|
257
|
+
"""
|
|
258
|
+
The `i`-th dual variable.
|
|
259
|
+
|
|
260
|
+
Available after ``self.solve()`` is called, otherwise the result is
|
|
261
|
+
undefined.
|
|
262
|
+
|
|
263
|
+
- ``index`` -- integer; the constraint's id
|
|
264
|
+
|
|
265
|
+
OUTPUT: the matrix of the `i`-th dual variable
|
|
266
|
+
|
|
267
|
+
EXAMPLES::
|
|
268
|
+
|
|
269
|
+
sage: p = SemidefiniteProgram(maximization=False, solver='cvxopt')
|
|
270
|
+
sage: x = p.new_variable()
|
|
271
|
+
sage: p.set_objective(x[0] - x[1])
|
|
272
|
+
sage: a1 = matrix([[1, 2.], [2., 3.]])
|
|
273
|
+
sage: a2 = matrix([[3, 4.], [4., 5.]])
|
|
274
|
+
sage: a3 = matrix([[5, 6.], [6., 7.]])
|
|
275
|
+
sage: b1 = matrix([[1, 1.], [1., 1.]])
|
|
276
|
+
sage: b2 = matrix([[2, 2.], [2., 2.]])
|
|
277
|
+
sage: b3 = matrix([[3, 3.], [3., 3.]])
|
|
278
|
+
sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3)
|
|
279
|
+
sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3)
|
|
280
|
+
sage: p.solve() # tol 1e-08
|
|
281
|
+
-3.0
|
|
282
|
+
sage: B = p.get_backend()
|
|
283
|
+
sage: x = p.get_values(x).values()
|
|
284
|
+
sage: -(a3*B.dual_variable(0)).trace() - (b3*B.dual_variable(1)).trace() # tol 1e-07
|
|
285
|
+
-3.0
|
|
286
|
+
sage: g = sum((B.slack(j)*B.dual_variable(j)).trace() for j in range(2)); g # tol 1.5e-08
|
|
287
|
+
0.0
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
TESTS::
|
|
291
|
+
|
|
292
|
+
sage: B.dual_variable(7)
|
|
293
|
+
Traceback (most recent call last):
|
|
294
|
+
...
|
|
295
|
+
IndexError: list index out of range
|
|
296
|
+
sage: abs(g - B._get_answer()['gap']) # tol 1e-22
|
|
297
|
+
0.0
|
|
298
|
+
"""
|
|
299
|
+
cdef int n
|
|
300
|
+
n = self.answer['zs'][i].size[0]
|
|
301
|
+
assert(n == self.answer['zs'][i].size[1]) # must be square matrix
|
|
302
|
+
return Matrix(n, n, list(self.answer['zs'][i]), sparse=sparse)
|
|
303
|
+
|
|
304
|
+
cpdef slack(self, int i, sparse=False):
|
|
305
|
+
"""
|
|
306
|
+
Slack of the `i`-th constraint.
|
|
307
|
+
|
|
308
|
+
Available after ``self.solve()`` is called, otherwise the result is
|
|
309
|
+
undefined.
|
|
310
|
+
|
|
311
|
+
- ``index`` -- integer; the constraint's id
|
|
312
|
+
|
|
313
|
+
OUTPUT: the matrix of the slack of the `i`-th constraint
|
|
314
|
+
|
|
315
|
+
EXAMPLES::
|
|
316
|
+
|
|
317
|
+
sage: p = SemidefiniteProgram(maximization = False, solver='cvxopt')
|
|
318
|
+
sage: x = p.new_variable()
|
|
319
|
+
sage: p.set_objective(x[0] - x[1])
|
|
320
|
+
sage: a1 = matrix([[1, 2.], [2., 3.]])
|
|
321
|
+
sage: a2 = matrix([[3, 4.], [4., 5.]])
|
|
322
|
+
sage: a3 = matrix([[5, 6.], [6., 7.]])
|
|
323
|
+
sage: b1 = matrix([[1, 1.], [1., 1.]])
|
|
324
|
+
sage: b2 = matrix([[2, 2.], [2., 2.]])
|
|
325
|
+
sage: b3 = matrix([[3, 3.], [3., 3.]])
|
|
326
|
+
sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3)
|
|
327
|
+
sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3)
|
|
328
|
+
sage: p.solve() # tol 1e-08
|
|
329
|
+
-3.0
|
|
330
|
+
sage: B = p.get_backend()
|
|
331
|
+
sage: B1 = B.slack(1); B1 # tol 1e-08
|
|
332
|
+
[0.0 0.0]
|
|
333
|
+
[0.0 0.0]
|
|
334
|
+
sage: B1.is_positive_definite()
|
|
335
|
+
True
|
|
336
|
+
sage: x = sorted(p.get_values(x).values())
|
|
337
|
+
sage: x[0]*b1 + x[1]*b2 - b3 + B1 # tol 1e-09
|
|
338
|
+
[0.0 0.0]
|
|
339
|
+
[0.0 0.0]
|
|
340
|
+
|
|
341
|
+
TESTS::
|
|
342
|
+
|
|
343
|
+
sage: B.slack(7)
|
|
344
|
+
Traceback (most recent call last):
|
|
345
|
+
...
|
|
346
|
+
IndexError: list index out of range
|
|
347
|
+
"""
|
|
348
|
+
cdef int n
|
|
349
|
+
n = self.answer['ss'][i].size[0]
|
|
350
|
+
assert(n == self.answer['ss'][i].size[1]) # must be square matrix
|
|
351
|
+
return Matrix(n, n, list(self.answer['ss'][i]), sparse=sparse)
|
|
352
|
+
|
|
353
|
+
cpdef solver_parameter(self, name, value=None):
|
|
354
|
+
"""
|
|
355
|
+
Return or define a solver parameter.
|
|
356
|
+
|
|
357
|
+
INPUT:
|
|
358
|
+
|
|
359
|
+
- ``name`` -- string; the parameter
|
|
360
|
+
|
|
361
|
+
- ``value`` -- the parameter's value if it is to be defined,
|
|
362
|
+
or ``None`` (default) to obtain its current value
|
|
363
|
+
|
|
364
|
+
.. NOTE::
|
|
365
|
+
|
|
366
|
+
The list of available parameters is available at
|
|
367
|
+
:meth:`~sage.numerical.sdp.SemidefiniteProgram.solver_parameter`.
|
|
368
|
+
|
|
369
|
+
EXAMPLES::
|
|
370
|
+
|
|
371
|
+
sage: from sage.numerical.backends.generic_sdp_backend import get_solver
|
|
372
|
+
sage: p = get_solver(solver='CVXOPT')
|
|
373
|
+
sage: p.solver_parameter("show_progress")
|
|
374
|
+
False
|
|
375
|
+
sage: p.solver_parameter("show_progress", True)
|
|
376
|
+
sage: p.solver_parameter("show_progress")
|
|
377
|
+
True
|
|
378
|
+
"""
|
|
379
|
+
if value is None:
|
|
380
|
+
return self.param[name]
|
|
381
|
+
else:
|
|
382
|
+
self.param[name] = value
|
|
Binary file
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-polyhedra
|
|
2
|
+
##############################################################################
|
|
3
|
+
# Copyright (C) 2010 Nathann Cohen <nathann.cohen@gmail.com>
|
|
4
|
+
# Copyright (C) 2022 Matthias Koeppe <mkoeppe@math.ucdavis.edu>
|
|
5
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
6
|
+
# The full text of the GPL is available at:
|
|
7
|
+
# http://www.gnu.org/licenses/
|
|
8
|
+
##############################################################################
|
|
9
|
+
|
|
10
|
+
from sage.numerical.backends.generic_backend cimport GenericBackend
|
|
11
|
+
|
|
12
|
+
cdef class CVXPYBackend(GenericBackend):
|
|
13
|
+
|
|
14
|
+
cdef object variables
|
|
15
|
+
cdef object problem
|
|
16
|
+
cdef object prob_name
|
|
17
|
+
cdef object constraint_names
|
|
18
|
+
|
|
19
|
+
cdef object _cvxpy_solver
|
|
20
|
+
cdef object _cvxpy_solver_args
|
|
21
|
+
|
|
22
|
+
cdef list objective_coefficients
|
|
23
|
+
cdef list Matrix
|
|
24
|
+
|
|
25
|
+
cdef list row_lower_bound
|
|
26
|
+
cdef list row_upper_bound
|
|
27
|
+
cdef list col_lower_bound
|
|
28
|
+
cdef list col_upper_bound
|
|
29
|
+
|
|
30
|
+
cpdef int add_variable(self,
|
|
31
|
+
lower_bound=*,
|
|
32
|
+
upper_bound=*,
|
|
33
|
+
binary=*,
|
|
34
|
+
continuous=*,
|
|
35
|
+
integer=*,
|
|
36
|
+
obj=*,
|
|
37
|
+
name=*,
|
|
38
|
+
coefficients=*) \
|
|
39
|
+
except -1
|
|
40
|
+
|
|
41
|
+
cpdef cvxpy_problem(self)
|