@@ -2014,10 +2014,22 @@ cdef class MixedIntegerLinearProgram(SageObject):
2014
2014
x_0 is a continuous variable ( min=0. 0, max=+ oo)
2015
2015
x_1 is a continuous variable ( min=0. 0, max=+ oo)
2016
2016
2017
- Empty constraint: :
2017
+ Trivially true empty constraint:
2018
2018
2019
2019
sage: p = MixedIntegerLinearProgram( solver='GLPK')
2020
- sage: p. add_constraint( sum( []) ,min=2)
2020
+ sage: p. add_constraint( sum( []) , max=2)
2021
+ 0
2022
+ sage: p. solve( )
2023
+ 0. 0
2024
+
2025
+ Infeasible empty constraint::
2026
+
2027
+ sage: p = MixedIntegerLinearProgram( solver='GLPK')
2028
+ sage: p. add_constraint( sum( []) , min=2)
2029
+ sage: p. solve( )
2030
+ Traceback ( most recent call last) :
2031
+ ...
2032
+ MIPSolverException: GLPK: Problem has no feasible solution
2021
2033
2022
2034
Min/Max are numerical ::
2023
2035
@@ -2078,9 +2090,6 @@ cdef class MixedIntegerLinearProgram(SageObject):
2078
2090
...
2079
2091
ValueError: argument must be a linear function or constraint, got True
2080
2092
"""
2081
- if linear_function is 0 :
2082
- return
2083
-
2084
2093
from sage.numerical.linear_functions import is_LinearFunction, is_LinearConstraint
2085
2094
from sage.numerical.linear_tensor import is_LinearTensor
2086
2095
from sage.numerical.linear_tensor_constraints import is_LinearTensorConstraint
@@ -2149,8 +2158,14 @@ cdef class MixedIntegerLinearProgram(SageObject):
2149
2158
return self .add_constraint(relation.lhs() - relation.rhs(),
2150
2159
min = M(0 ) if relation.is_equation() else None ,
2151
2160
max = M(0 ), name = name)
2161
+ elif isinstance (linear_function, bool ):
2162
+ raise ValueError (' argument must be a linear function or constraint, got ' + str (linear_function))
2152
2163
else :
2153
- raise ValueError (' argument must be a linear function or constraint, got ' + str (linear_function))
2164
+ try :
2165
+ linear_function = self .linear_functions_parent()(linear_function)
2166
+ except (TypeError , ValueError ):
2167
+ raise ValueError (' argument must be a linear function or constraint, got ' + str (linear_function))
2168
+ return self .add_constraint(linear_function, max = max , min = min , name = name)
2154
2169
2155
2170
def _is_redundant_constraint (self , constraint , min_bound , max_bound ):
2156
2171
"""
0 commit comments