Skip to content

Commit

Permalink
sagemathgh-37864: sage.numerical.interactive_simplex_method: Remove…
Browse files Browse the repository at this point in the history
… dependency on SR

    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Author: @mkoeppe, @ComboProblem

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#37864
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed May 23, 2024
2 parents b13df98 + bd12b8f commit 5110596
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/sage/numerical/interactive_simplex_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@
from sage.misc.lazy_import import lazy_import
lazy_import("sage.plot.all", ["Graphics", "arrow", "line", "point", "rainbow", "text"])
from sage.rings.infinity import Infinity
from sage.rings.polynomial.polynomial_ring import polygen
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.polynomial.polynomial_element import Polynomial
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


# We produce rather complicated LaTeX code which needs some tweaks to be
Expand Down Expand Up @@ -316,8 +317,10 @@ def _latex_product(coefficients, variables,
t = latex(v)
else:
t = latex(c)
if SR(c).operator() in [operator.add, operator.sub]:
t = r"\left( " + t + r" \right)"
if '+' in t or '-' in t:
from sage.symbolic.ring import SR
if SR(c).operator() in [operator.add, operator.sub]:
t = r"\left( " + t + r" \right)"
t += " " + latex(v)
entries.extend([sign, t])
if drop_plus: # Don't start with +
Expand Down Expand Up @@ -1840,7 +1843,7 @@ def standard_form(self, transformation=False, **kwds):
x = newx
f = newf

objective_name = SR(kwds.get("objective_name", default_variable_name(
objective_name = polygen(ZZ, kwds.get("objective_name", default_variable_name(
"primal objective" if self.is_primal() else "dual objective")))
is_negative = self._is_negative
constant_term = self._constant_term
Expand All @@ -1849,7 +1852,7 @@ def standard_form(self, transformation=False, **kwds):
c = - c
constant_term = - constant_term
objective_name = - objective_name
kwds["objective_name"] = objective_name
kwds["objective_name"] = objective_name # polynomial, no longer a string
kwds["problem_type"] = "-max" if is_negative else "max"
kwds["is_primal"] = self.is_primal()
kwds["objective_constant_term"] = constant_term
Expand Down Expand Up @@ -2016,7 +2019,10 @@ def __init__(self, A, b, c, x="x", problem_type="max",
if objective_name is None:
objective_name = default_variable_name(
"primal objective" if is_primal else "dual objective")
self._objective_name = SR(objective_name)
if isinstance(objective_name, Polynomial):
self._objective_name = objective_name
else:
self._objective_name = polygen(ZZ, objective_name)

@staticmethod
def random_element(m, n, bound=5, special_probability=0.2,
Expand Down Expand Up @@ -3904,7 +3910,7 @@ def __init__(self, A, b, c, objective_value,
c = copy(c)
B = vector(basic_variables)
N = vector(nonbasic_variables)
self._AbcvBNz = [A, b, c, objective_value, B, N, SR(objective_name)]
self._AbcvBNz = [A, b, c, objective_value, B, N, polygen(ZZ, objective_name)]

@staticmethod
def random_element(m, n, bound=5, special_probability=0.2):
Expand Down

0 comments on commit 5110596

Please sign in to comment.