From ff01e8ee50f94783b77c4b470fd178a795b85d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20R=C3=BCth?= Date: Mon, 28 Nov 2016 02:25:03 -0500 Subject: [PATCH] faster solver for semigroups --- value_group.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/value_group.py b/value_group.py index 707e024db8..d17e4ce704 100644 --- a/value_group.py +++ b/value_group.py @@ -497,8 +497,22 @@ def _solve_linear_program(self, target): else: return None + if len(self._generators) == 1: + from sage.rings.all import NN + exp = target / self._generators[0] + if exp not in NN: + return None + return {0 : exp} + + if len(self._generators) == 2 and self._generators[0] == - self._generators[1]: + from sage.rings.all import ZZ + exp = target / self._generators[0] + if exp not in ZZ: + return None + return {0: exp, 1: 0} + from sage.numerical.mip import MixedIntegerLinearProgram, MIPSolverException - P = MixedIntegerLinearProgram(maximization=False, solver = "ppl") + P = MixedIntegerLinearProgram(maximization=False, solver="ppl") x = P.new_variable(integer=True, nonnegative=True) constraint = sum([g*x[i] for i,g in enumerate(self._generators)]) == target P.add_constraint(constraint)