@@ -1862,8 +1862,7 @@ cdef class MixedIntegerLinearProgram(SageObject):
1862
1862
1863
1863
def add_constraint (self , linear_function , max = None , min = None , name = None ,
1864
1864
return_indices = False ):
1865
- r """
1866
- Adds a constraint to the ``MixedIntegerLinearProgram``.
1865
+ r """ Adds a constraint to the ``MixedIntegerLinearProgram``.
1867
1866
1868
1867
INPUT:
1869
1868
@@ -2098,6 +2097,43 @@ cdef class MixedIntegerLinearProgram(SageObject):
2098
2097
...
2099
2098
ValueError: argument must be a linear function or constraint, got True
2100
2099
2100
+ Check that adding and removing constraints works::
2101
+
2102
+ sage: p = MixedIntegerLinearProgram( check_redundant=True)
2103
+ sage: x = p. new_variable( nonnegative=True)
2104
+ sage: p. add_constraint( x[0 ] + x[1 ] <= 3)
2105
+ sage: p. set_objective( x[0 ] + 2* x[1 ])
2106
+ sage: p. solve( )
2107
+ 6. 0
2108
+
2109
+ We add ( non-trivially) redundant constraints::
2110
+
2111
+ sage: c1 = p. add_constraint( 0 <= x[0 ] <= 3, return_indices=True) ; c1
2112
+ [1, 2 ]
2113
+ sage: p. solve( )
2114
+ 6. 0
2115
+
2116
+ We add a non-redundant constraint::
2117
+
2118
+ sage: c2 = p. add_constraint( 1 <= x[1 ] <= 2, return_indices=True) ; c2
2119
+ [3, 4 ]
2120
+ sage: p. solve( )
2121
+ 5. 0
2122
+
2123
+ We remove the redundant constraints `1` and `2`, keep in mind
2124
+ that indices change when removing constraints::
2125
+
2126
+ sage: p. remove_constraint( 1)
2127
+ sage: p. remove_constraint( 1)
2128
+ sage: p. solve( )
2129
+ 5. 0
2130
+
2131
+ We remove another constraint::
2132
+
2133
+ sage: p. remove_constraint( 2)
2134
+ sage: p. solve( )
2135
+ 6. 0
2136
+
2101
2137
"""
2102
2138
from sage.numerical.linear_functions import is_LinearFunction, is_LinearConstraint
2103
2139
from sage.numerical.linear_tensor import is_LinearTensor
0 commit comments