@@ -592,6 +592,9 @@ class InteractiveLPProblem(SageObject):
592
592
- ``is_primal`` -- (default: ``True``) whether this problem is primal or
593
593
dual: each problem is of course dual to its own dual, this flag is mostly
594
594
for internal use and affects default variable names only
595
+
596
+ - ``objective_constant_term`` -- (default: 0) a constant term of the
597
+ objective added to ``c * x`` when computing optimal value
595
598
596
599
EXAMPLES:
597
600
@@ -632,7 +635,7 @@ class InteractiveLPProblem(SageObject):
632
635
633
636
def __init__ (self , A , b , c , x = "x" ,
634
637
constraint_type = "<=" , variable_type = "" , problem_type = "max" ,
635
- base_ring = None , is_primal = True ):
638
+ base_ring = None , is_primal = True , objective_constant_term = 0 ):
636
639
r"""
637
640
See :class:`InteractiveLPProblem` for documentation.
638
641
@@ -671,6 +674,7 @@ def __init__(self, A, b, c, x="x",
671
674
R = PolynomialRing (base_ring , x , order = "neglex" )
672
675
x = vector (R , R .gens ()) # All variables as a vector
673
676
self ._Abcx = A , b , c , x
677
+ self ._constant_term = objective_constant_term
674
678
675
679
if constraint_type in ["<=" , ">=" , "==" ]:
676
680
constraint_type = (constraint_type , ) * m
@@ -846,11 +850,12 @@ def _solve(self):
846
850
M , S = - Infinity , None
847
851
else :
848
852
M , S = min ((c * vector (R , v ), v ) for v in F .vertices ())
849
- if self ._is_negative :
850
- M = - M
851
853
if S is not None :
852
854
S = vector (R , S )
853
855
S .set_immutable ()
856
+ M += self ._constant_term
857
+ if self ._is_negative :
858
+ M = - M
854
859
return S , M
855
860
856
861
def Abcx (self ):
@@ -1202,6 +1207,33 @@ def objective_coefficients(self):
1202
1207
(10, 5)
1203
1208
"""
1204
1209
return self ._Abcx [2 ]
1210
+
1211
+ def objective_constant_term (self ):
1212
+ r"""
1213
+ Return the constant term of the objective.
1214
+
1215
+ OUTPUT:
1216
+
1217
+ - a number
1218
+
1219
+ EXAMPLES::
1220
+
1221
+ sage: A = ([1, 1], [3, 1])
1222
+ sage: b = (1000, 1500)
1223
+ sage: c = (10, 5)
1224
+ sage: P = InteractiveLPProblem(A, b, c, ["C", "B"], variable_type=">=")
1225
+ sage: P.objective_constant_term()
1226
+ 0
1227
+ sage: P.optimal_value()
1228
+ 6250
1229
+ sage: P = InteractiveLPProblem(A, b, c, ["C", "B"],
1230
+ ....: variable_type=">=", objective_constant_term=-1250)
1231
+ sage: P.objective_constant_term()
1232
+ -1250
1233
+ sage: P.optimal_value()
1234
+ 5000
1235
+ """
1236
+ return self ._constant_term
1205
1237
1206
1238
def optimal_solution (self ):
1207
1239
r"""
0 commit comments