Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t/31312/interactive simplex method improve support for base fields other than qq #36

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions src/sage/numerical/interactive_simplex_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@
from sage.rings.infinity import Infinity
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.rational_field import QQ
from sage.rings.real_double import RDF
from sage.rings.integer_ring import ZZ
from sage.structure.all import SageObject
from sage.symbolic.ring import SR
Expand Down Expand Up @@ -302,7 +301,7 @@ def _latex_product(coefficients, variables,
sage: var("x, y") # needs sage.symbolic
(x, y)
sage: print(_latex_product([-1, 3], [x, y])) # needs sage.symbolic
- \mspace{-6mu}&\mspace{-6mu} x \mspace{-6mu}&\mspace{-6mu} + \mspace{-6mu}&\mspace{-6mu} 3 y
- \mspace{-6mu}&\mspace{-6mu} 1 x \mspace{-6mu}&\mspace{-6mu} + \mspace{-6mu}&\mspace{-6mu} 3 y
"""
entries = []
for c, v in zip(coefficients, variables):
Expand Down Expand Up @@ -1174,10 +1173,14 @@ def dual(self, y=None):
objective_constant_term=self._constant_term)

@cached_method
def feasible_set(self):
def feasible_set(self, backend=None):
r"""
Return the feasible set of ``self``.

INPUT:

- (optional) a backend for :mod:`Polyhedron <sage.geometry.polyhedron.constructor>`

OUTPUT:

- a :mod:`Polyhedron <sage.geometry.polyhedron.constructor>`
Expand All @@ -1191,7 +1194,18 @@ def feasible_set(self):
sage: P.feasible_set()
A 2-dimensional polyhedron in QQ^2
defined as the convex hull of 4 vertices
"""
sage: P.feasible_set(backend='cdd')
A 2-dimensional polyhedron in QQ^2
defined as the convex hull of 4 vertices
sage: from sage.rings.real_double import RDF
sage: A = ([RDF(1),RDF(1)], [RDF(3), RDF(1)])
sage: b = (1000, 1500)
sage: c = (10, 5)
sage: P = InteractiveLPProblem(A, b, c, ["C", "B"], variable_type=">=")
sage: P.feasible_set()
A 2-dimensional polyhedron in RDF^2
defined as the convex hull of 4 vertices
"""
ieqs = []
eqns = []
for a, r, b in zip(self.A().rows(), self._constraint_types, self.b()):
Expand All @@ -1206,6 +1220,8 @@ def feasible_set(self):
ieqs.append([0] + list(-n))
elif r == ">=":
ieqs.append([0] + list(n))
if backend is not None:
return Polyhedron(ieqs=ieqs, eqns=eqns, backend=backend)
return Polyhedron(ieqs=ieqs, eqns=eqns)

def is_bounded(self):
Expand Down Expand Up @@ -2653,6 +2669,31 @@ def run_simplex_method(self):
Entering: $x_{2}$. Leaving: $x_{3}$.
...
The optimal value: $6250$. An optimal solution: $\left(250,\,750\right)$.

TESTS::

sage: from sage.rings.real_double import RDF
sage: A = ([RDF(1), RDF(1)], [RDF(3), RDF(1)], [RDF(-1), RDF(-1)])
sage: b = (RDF(1000), RDF(1500), RDF(-400))
sage: c = (RDF(10), RDF(5))
sage: P = InteractiveLPProblemStandardForm(A, b, c)
sage: P.run_simplex_method()
\begin{equation*}
...
\end{equation*}
The initial dictionary is infeasible, solving auxiliary problem.
...
Entering: $x_{0}$. Leaving: $x_{5}$.
...
Entering: $x_{1}$. Leaving: $x_{0}$.
...
Back to the original problem.
...
Entering: $x_{5}$. Leaving: $x_{4}$.
...
Entering: $x_{2}$. Leaving: $x_{3}$.
...
The optimal value: $6250.0$. An optimal solution: $\left(249.99999999999997,\,750.0\right)$.
"""
output = []
d = self.initial_dictionary()
Expand Down Expand Up @@ -4002,8 +4043,8 @@ def _latex_(self):
\renewcommand{\arraystretch}{1.5} %notruncate
\begin{array}{|rcrcrcr|}
\hline
x_{3} \mspace{-6mu}&\mspace{-6mu} = \mspace{-6mu}&\mspace{-6mu} 1000 \mspace{-6mu}&\mspace{-6mu} - \mspace{-6mu}&\mspace{-6mu} x_{1} \mspace{-6mu}&\mspace{-6mu} - \mspace{-6mu}&\mspace{-6mu} x_{2}\\
x_{4} \mspace{-6mu}&\mspace{-6mu} = \mspace{-6mu}&\mspace{-6mu} 1500 \mspace{-6mu}&\mspace{-6mu} - \mspace{-6mu}&\mspace{-6mu} 3 x_{1} \mspace{-6mu}&\mspace{-6mu} - \mspace{-6mu}&\mspace{-6mu} x_{2}\\
x_{3} \mspace{-6mu}&\mspace{-6mu} = \mspace{-6mu}&\mspace{-6mu} 1000 \mspace{-6mu}&\mspace{-6mu} - \mspace{-6mu}&\mspace{-6mu} 1 x_{1} \mspace{-6mu}&\mspace{-6mu} - \mspace{-6mu}&\mspace{-6mu} 1 x_{2}\\
x_{4} \mspace{-6mu}&\mspace{-6mu} = \mspace{-6mu}&\mspace{-6mu} 1500 \mspace{-6mu}&\mspace{-6mu} - \mspace{-6mu}&\mspace{-6mu} 3 x_{1} \mspace{-6mu}&\mspace{-6mu} - \mspace{-6mu}&\mspace{-6mu} 1 x_{2}\\
\hline
z \mspace{-6mu}&\mspace{-6mu} = \mspace{-6mu}&\mspace{-6mu} 0 \mspace{-6mu}&\mspace{-6mu} + \mspace{-6mu}&\mspace{-6mu} 10 x_{1} \mspace{-6mu}&\mspace{-6mu} + \mspace{-6mu}&\mspace{-6mu} 5 x_{2}\\
\hline
Expand Down