Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit c954f72

Browse files
author
Frédéric Chapoton
committed
avoid using maxima linear programming in lattice polytopes
1 parent 769ff19 commit c954f72

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/sage/geometry/lattice_polytope.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
from sage.structure.all import Sequence
126126
from sage.structure.sequence import Sequence_generic
127127
from sage.structure.sage_object import SageObject
128+
from sage.numerical.mip import MixedIntegerLinearProgram
129+
128130

129131
from copy import copy
130132
import collections
@@ -6240,18 +6242,16 @@ def positive_integer_relations(points):
62406242
62416243
INPUT:
62426244
6243-
6244-
- ``points`` - lattice points given as columns of a
6245-
matrix
6246-
6245+
- ``points`` - lattice points given as columns of a
6246+
matrix
62476247
62486248
OUTPUT: matrix of relations between given points with non-negative
62496249
integer coefficients
62506250
62516251
EXAMPLES: This is a 3-dimensional reflexive polytope::
62526252
62536253
sage: p = LatticePolytope([(1,0,0), (0,1,0),
6254-
... (-1,-1,0), (0,0,1), (-1,0,-1)])
6254+
....: (-1,-1,0), (0,0,1), (-1,0,-1)])
62556255
sage: p.points()
62566256
M( 1, 0, 0),
62576257
M( 0, 1, 0),
@@ -6290,19 +6290,26 @@ def positive_integer_relations(points):
62906290
for i in range(n_nonpivots):
62916291
a[i, i] = -1
62926292
a = nonpivot_relations.stack(a).transpose()
6293-
a = sage_matrix_to_maxima(a)
6294-
maxima.load("simplex")
6295-
6293+
# a = sage_matrix_to_maxima(a)
6294+
# maxima.load("simplex")
6295+
MIP = MixedIntegerLinearProgram(maximization=False)
6296+
w = MIP.new_variable(integer=True, nonnegative=True)
62966297
new_relations = []
62976298
for i in range(n_nonpivots):
62986299
# Find a non-negative linear combination of relations,
62996300
# such that all components are non-negative and the i-th one is 1
6300-
b = [0]*i + [1] + [0]*(n_nonpivots - i - 1)
6301-
c = [0]*(n+i) + [1] + [0]*(n_nonpivots - i - 1)
6302-
x = maxima.linear_program(a, b, c)
6303-
if x.str() == r'?Problem\not\feasible\!':
6301+
b = vector([0] * i + [1] + [0] * (n_nonpivots - i - 1))
6302+
c = [0] * (n + i) + [1] + [0] * (n_nonpivots - i - 1)
6303+
MIP.add_constraint(a * w == b)
6304+
MIP.set_objective(sum(ci * w[i] for i, ci in enumerate(c)))
6305+
# x = maxima.linear_program(a, b, c)
6306+
try:
6307+
x = MIP.solve()
6308+
except MIPSolverException:
6309+
# if x.str() == r'?Problem\not\feasible\!':
63046310
raise ValueError("cannot find required relations")
6305-
x = x.sage()[0][:n]
6311+
x = MIP.get_values(w).values()[:n]
6312+
# x = x.sage()[0][:n]
63066313
v = relations.linear_combination_of_rows(x)
63076314
new_relations.append(v)
63086315

0 commit comments

Comments
 (0)