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

Commit 684e91c

Browse files
author
Matthias Koeppe
committed
LinearFunction, LinearConstraint: Use linear_functions_parent() instead of deprecated MixedIntegerLinearProgram methods
1 parent 6375b4c commit 684e91c

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

src/sage/numerical/linear_functions.pyx

+33-24
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,15 @@ cdef class LinearFunctionOrConstraint(ModuleElement):
247247
::
248248
249249
sage: p = MixedIntegerLinearProgram()
250+
sage: LF = p.linear_functions_parent()
250251
sage: from sage.numerical.linear_functions import LinearFunction
251-
sage: p({2 : 5, 3 : 2}) <= p({2 : 3, 9 : 2})
252+
sage: LF({2 : 5, 3 : 2}) <= LF({2 : 3, 9 : 2})
252253
5*x_2 + 2*x_3 <= 3*x_2 + 2*x_9
253254
254-
sage: p({2 : 5, 3 : 2}) >= p({2 : 3, 9 : 2})
255+
sage: LF({2 : 5, 3 : 2}) >= LF({2 : 3, 9 : 2})
255256
3*x_2 + 2*x_9 <= 5*x_2 + 2*x_3
256257
257-
sage: p({2 : 5, 3 : 2}) == p({2 : 3, 9 : 2})
258+
sage: LF({2 : 5, 3 : 2}) == LF({2 : 3, 9 : 2})
258259
5*x_2 + 2*x_3 == 3*x_2 + 2*x_9
259260
260261
We can chain multiple (in)equalities::
@@ -304,8 +305,9 @@ cdef class LinearFunctionOrConstraint(ModuleElement):
304305
TESTS::
305306
306307
sage: p.<x> = MixedIntegerLinearProgram()
308+
sage: LF = p.linear_functions_parent()
307309
sage: cm = sage.structure.element.get_coercion_model()
308-
sage: cm.explain(10, p(1), operator.le)
310+
sage: cm.explain(10, LF(1), operator.le)
309311
Coercion on left operand via
310312
Conversion map:
311313
From: Integer Ring
@@ -455,7 +457,8 @@ cdef class LinearFunctionOrConstraint(ModuleElement):
455457
EXAMPLES::
456458
457459
sage: p = MixedIntegerLinearProgram()
458-
sage: f = p({2 : 5, 3 : 2})
460+
sage: LF = p.linear_functions_parent()
461+
sage: f = LF({2 : 5, 3 : 2})
459462
sage: f.__hash__() # random output
460463
103987752
461464
sage: d = {}
@@ -471,7 +474,8 @@ cdef class LinearFunctionOrConstraint(ModuleElement):
471474
EXAMPLES::
472475
473476
sage: p = MixedIntegerLinearProgram()
474-
sage: f = p({2 : 5, 3 : 2})
477+
sage: LF = p.linear_functions_parent()
478+
sage: f = LF({2 : 5, 3 : 2})
475479
sage: cmp(f, f)
476480
0
477481
sage: abs(cmp(f, f+0)) # since we are comparing by id()
@@ -665,6 +669,7 @@ cdef class LinearFunctionsParent_class(Parent):
665669
sage: LF._element_constructor_(123)
666670
123
667671
sage: p(123) # indirect doctest
672+
doctest:...: DeprecationWarning: ...
668673
123
669674
sage: type(_)
670675
<type 'sage.numerical.linear_functions.LinearFunction'>
@@ -749,19 +754,13 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
749754
750755
You should never instantiate :class:`LinearFunction`
751756
manually. Use the element constructor in the parent
752-
instead. For convenience, you can also call the
753-
:class:`MixedIntegerLinearProgram` instance directly.
757+
instead.
754758
755759
EXAMPLES:
756760
757761
For example, do this::
758762
759763
sage: p = MixedIntegerLinearProgram()
760-
sage: p({0 : 1, 3 : -8})
761-
x_0 - 8*x_3
762-
763-
or this::
764-
765764
sage: parent = p.linear_functions_parent()
766765
sage: parent({0 : 1, 3 : -8})
767766
x_0 - 8*x_3
@@ -787,13 +786,15 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
787786
With a dictionary::
788787
789788
sage: p = MixedIntegerLinearProgram()
790-
sage: p({0 : 1, 3 : -8})
789+
sage: LF = p.linear_functions_parent()
790+
sage: LF({0 : 1, 3 : -8})
791791
x_0 - 8*x_3
792792
793793
Using the constructor with a numerical value::
794794
795795
sage: p = MixedIntegerLinearProgram()
796-
sage: p(25)
796+
sage: LF = p.linear_functions_parent()
797+
sage: LF(25)
797798
25
798799
"""
799800
ModuleElement.__init__(self, parent)
@@ -840,7 +841,8 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
840841
EXAMPLE::
841842
842843
sage: p = MixedIntegerLinearProgram()
843-
sage: lf = p({0 : 1, 3 : -8})
844+
sage: LF = p.linear_functions_parent()
845+
sage: lf = LF({0 : 1, 3 : -8})
844846
sage: lf.dict()
845847
{0: 1.0, 3: -8.0}
846848
"""
@@ -912,7 +914,8 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
912914
EXAMPLE::
913915
914916
sage: p = MixedIntegerLinearProgram()
915-
sage: p({0 : 1, 3 : -8}) + p({2 : 5, 3 : 2}) - 16
917+
sage: LF = p.linear_functions_parent()
918+
sage: LF({0 : 1, 3 : -8}) + LF({2 : 5, 3 : 2}) - 16
916919
-16 + x_0 + 5*x_2 - 6*x_3
917920
"""
918921
e = dict(self._f)
@@ -928,7 +931,8 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
928931
EXAMPLE::
929932
930933
sage: p = MixedIntegerLinearProgram()
931-
sage: - p({0 : 1, 3 : -8})
934+
sage: LF = p.linear_functions_parent()
935+
sage: - LF({0 : 1, 3 : -8})
932936
-1*x_0 + 8*x_3
933937
"""
934938
P = self.parent()
@@ -941,9 +945,10 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
941945
EXAMPLE::
942946
943947
sage: p = MixedIntegerLinearProgram()
944-
sage: p({2 : 5, 3 : 2}) - 3
948+
sage: LF = p.linear_functions_parent()
949+
sage: LF({2 : 5, 3 : 2}) - 3
945950
-3 + 5*x_2 + 2*x_3
946-
sage: p({0 : 1, 3 : -8}) - p({2 : 5, 3 : 2}) - 16
951+
sage: LF({0 : 1, 3 : -8}) - LF({2 : 5, 3 : 2}) - 16
947952
-16 + x_0 - 5*x_2 - 10*x_3
948953
"""
949954
e = dict(self._f)
@@ -959,7 +964,8 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
959964
EXAMPLE::
960965
961966
sage: p = MixedIntegerLinearProgram()
962-
sage: p({2 : 5, 3 : 2}) * 3
967+
sage: LF = p.linear_functions_parent()
968+
sage: LF({2 : 5, 3 : 2}) * 3
963969
15*x_2 + 6*x_3
964970
"""
965971
P = self.parent()
@@ -972,7 +978,8 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
972978
EXAMPLE::
973979
974980
sage: p = MixedIntegerLinearProgram()
975-
sage: 3 * p({2 : 5, 3 : 2})
981+
sage: LF = p.linear_functions_parent()
982+
sage: 3 * LF({2 : 5, 3 : 2})
976983
15*x_2 + 6*x_3
977984
"""
978985
return self._rmul_(b)
@@ -1094,10 +1101,12 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
10941101
EXAMPLE::
10951102
10961103
sage: p = MixedIntegerLinearProgram(solver='GLPK')
1097-
sage: p({-1: -15, 2 : -5.1, 3 : 2/3})
1104+
sage: LF = p.linear_functions_parent()
1105+
sage: LF({-1: -15, 2 : -5.1, 3 : 2/3})
10981106
-15 - 5.1*x_2 + 0.666666666667*x_3
10991107
sage: p = MixedIntegerLinearProgram(solver='ppl')
1100-
sage: p({-1: -15, 2 : -5.1, 3 : 2/3})
1108+
sage: LF = p.linear_functions_parent()
1109+
sage: LF({-1: -15, 2 : -5.1, 3 : 2/3})
11011110
-15 - 51/10*x_2 + 2/3*x_3
11021111
"""
11031112
cdef dict d = dict(self._f)

0 commit comments

Comments
 (0)