|
125 | 125 | from sage.structure.all import Sequence
|
126 | 126 | from sage.structure.sequence import Sequence_generic
|
127 | 127 | from sage.structure.sage_object import SageObject
|
| 128 | +from sage.numerical.mip import MixedIntegerLinearProgram |
| 129 | + |
128 | 130 |
|
129 | 131 | from copy import copy
|
130 | 132 | import collections
|
@@ -6240,18 +6242,16 @@ def positive_integer_relations(points):
|
6240 | 6242 |
|
6241 | 6243 | INPUT:
|
6242 | 6244 |
|
6243 |
| -
|
6244 |
| - - ``points`` - lattice points given as columns of a |
6245 |
| - matrix |
6246 |
| -
|
| 6245 | + - ``points`` - lattice points given as columns of a |
| 6246 | + matrix |
6247 | 6247 |
|
6248 | 6248 | OUTPUT: matrix of relations between given points with non-negative
|
6249 | 6249 | integer coefficients
|
6250 | 6250 |
|
6251 | 6251 | EXAMPLES: This is a 3-dimensional reflexive polytope::
|
6252 | 6252 |
|
6253 | 6253 | 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)]) |
6255 | 6255 | sage: p.points()
|
6256 | 6256 | M( 1, 0, 0),
|
6257 | 6257 | M( 0, 1, 0),
|
@@ -6290,19 +6290,26 @@ def positive_integer_relations(points):
|
6290 | 6290 | for i in range(n_nonpivots):
|
6291 | 6291 | a[i, i] = -1
|
6292 | 6292 | 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) |
6296 | 6297 | new_relations = []
|
6297 | 6298 | for i in range(n_nonpivots):
|
6298 | 6299 | # Find a non-negative linear combination of relations,
|
6299 | 6300 | # 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\!': |
6304 | 6310 | 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] |
6306 | 6313 | v = relations.linear_combination_of_rows(x)
|
6307 | 6314 | new_relations.append(v)
|
6308 | 6315 |
|
|
0 commit comments