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

Commit

Permalink
get_solver: Add optional base_ring argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Mar 28, 2016
1 parent d91c776 commit eaede28
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/sage/numerical/backends/generic_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ cdef class GenericBackend:

cdef object obj_constant_term

cpdef GenericBackend get_solver(constraint_generation = ?, solver = ?)
cpdef GenericBackend get_solver(constraint_generation = ?, solver = ?, base_ring = ?)
36 changes: 32 additions & 4 deletions src/sage/numerical/backends/generic_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ def default_mip_solver(solver = None):
else:
raise ValueError("'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'CVXOPT', 'Gurobi', 'PPL', 'InteractiveLP', or None.")

cpdef GenericBackend get_solver(constraint_generation = False, solver = None):
cpdef GenericBackend get_solver(constraint_generation = False, solver = None, base_ring = None):
"""
Return a solver according to the given preferences
Expand Down Expand Up @@ -1271,7 +1271,9 @@ cpdef GenericBackend get_solver(constraint_generation = False, solver = None):
``solver`` should then be equal to one of ``"GLPK"``, ``"Coin"``,
``"CPLEX"``, ``"CVXOPT"``,``"Gurobi"``, ``"PPL"``, ``"InteractiveLP"``,
or ``None``. If ``solver=None`` (default),
the default solver is used (see ``default_mip_solver`` method.
the default solver is used (see ``default_mip_solver`` method).
- ``base_ring`` -- Request a solver that works over this field.
- ``constraint_generation`` -- Only used when ``solver=None``.
Expand All @@ -1286,14 +1288,40 @@ cpdef GenericBackend get_solver(constraint_generation = False, solver = None):
- :func:`default_mip_solver` -- Returns/Sets the default MIP solver.
EXAMPLE::
EXAMPLES::
sage: from sage.numerical.backends.generic_backend import get_solver
sage: p = get_solver()
sage: p = get_solver(base_ring=RDF)
sage: p.base_ring()
Real Double Field
sage: p = get_solver(base_ring=QQ); p
<sage.numerical.backends.ppl_backend.PPLBackend object at ...>
sage: p.base_ring()
Rational Field
sage: p = get_solver(base_ring=AA); p
<sage.numerical.backends.interactivelp_backend.InteractiveLPBackend object at ...>
sage: p.base_ring()
Algebraic Real Field
sage: d = polytopes.dodecahedron()
sage: p = get_solver(base_ring=d.base_ring()); p
<sage.numerical.backends.interactivelp_backend.InteractiveLPBackend object at ...>
sage: p.base_ring()
Number Field in sqrt5 with defining polynomial x^2 - 5
"""
if solver is None:

solver = default_mip_solver()

if base_ring is not None:
from sage.rings.all import QQ, RDF
if base_ring is QQ:
solver = "Ppl"
elif solver in ["Interactivelp", "Ppl"] and not base_ring.is_exact():
solver = "Glpk"
elif base_ring is not RDF:
solver = "Interactivelp"

# We do not want to use Coin for constraint_generation. It just does not
# work
if solver == "Coin" and constraint_generation:
Expand Down Expand Up @@ -1328,7 +1356,7 @@ cpdef GenericBackend get_solver(constraint_generation = False, solver = None):

elif solver == "Interactivelp":
from sage.numerical.backends.interactivelp_backend import InteractiveLPBackend
return InteractiveLPBackend()
return InteractiveLPBackend(base_ring=base_ring)

else:
raise ValueError("'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'CVXOPT', 'Gurobi', 'PPL', 'InteractiveLP', or None (in which case the default one is used).")

0 comments on commit eaede28

Please sign in to comment.