From 2ca6131670b5fe04a40a8647fa06c934afae5aca Mon Sep 17 00:00:00 2001 From: ComboProblem <102884863+ComboProblem@users.noreply.github.com> Date: Wed, 1 May 2024 09:39:11 -0700 Subject: [PATCH 1/2] fix doc tests --- src/sage/numerical/interactive_simplex_method.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sage/numerical/interactive_simplex_method.py b/src/sage/numerical/interactive_simplex_method.py index 8be308f3bc7..1bf88e4668a 100644 --- a/src/sage/numerical/interactive_simplex_method.py +++ b/src/sage/numerical/interactive_simplex_method.py @@ -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 @@ -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): @@ -4002,8 +4001,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 From cb67d637bb963041668d6640c12c3201f5f030a6 Mon Sep 17 00:00:00 2001 From: ComboProblem <102884863+ComboProblem@users.noreply.github.com> Date: Wed, 8 May 2024 10:51:26 -0700 Subject: [PATCH 2/2] removed RDF import; updated doc test to include RDF --- .../numerical/interactive_simplex_method.py | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/sage/numerical/interactive_simplex_method.py b/src/sage/numerical/interactive_simplex_method.py index 1bf88e4668a..ab2763e86aa 100644 --- a/src/sage/numerical/interactive_simplex_method.py +++ b/src/sage/numerical/interactive_simplex_method.py @@ -1173,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 ` + OUTPUT: - a :mod:`Polyhedron ` @@ -1190,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()): @@ -1205,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): @@ -2652,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()