Constraints on Linear Functions Tensored with a Free Module#
Here is an example of a vector-valued linear function:
sage: mip.<x> = MixedIntegerLinearProgram('ppl') # base ring is QQ
sage: x[0] * vector([3,4]) + 1 # vector linear function
(1, 1) + (3, 4)*x_0
>>> from sage.all import *
>>> mip = MixedIntegerLinearProgram('ppl', names=('x',)); (x,) = mip._first_ngens(1)# base ring is QQ
>>> x[Integer(0)] * vector([Integer(3),Integer(4)]) + Integer(1) # vector linear function
(1, 1) + (3, 4)*x_0
Just like linear_functions
, (in)equalities
become symbolic inequalities:
sage: 3 + x[0] + 2*x[1] <= 10
3 + x_0 + 2*x_1 <= 10
sage: x[0] * vector([3,4]) + 1 <= 10
(1, 1) + (3, 4)*x_0 <= (10, 10)
sage: x[0] * matrix([[0,0,1],[0,1,0],[1,0,0]]) + x[1] * identity_matrix(3) >= 0
[0 0 0] [x_1 0 x_0]
[0 0 0] <= [0 x_0 + x_1 0 ]
[0 0 0] [x_0 0 x_1]
>>> from sage.all import *
>>> Integer(3) + x[Integer(0)] + Integer(2)*x[Integer(1)] <= Integer(10)
3 + x_0 + 2*x_1 <= 10
>>> x[Integer(0)] * vector([Integer(3),Integer(4)]) + Integer(1) <= Integer(10)
(1, 1) + (3, 4)*x_0 <= (10, 10)
>>> x[Integer(0)] * matrix([[Integer(0),Integer(0),Integer(1)],[Integer(0),Integer(1),Integer(0)],[Integer(1),Integer(0),Integer(0)]]) + x[Integer(1)] * identity_matrix(Integer(3)) >= Integer(0)
[0 0 0] [x_1 0 x_0]
[0 0 0] <= [0 x_0 + x_1 0 ]
[0 0 0] [x_0 0 x_1]
- class sage.numerical.linear_tensor_constraints.LinearTensorConstraint(parent, lhs, rhs, equality)[source]#
Bases:
Element
Formal constraint involving two module-valued linear functions.
Note
In the code, we use “linear tensor” as abbreviation for the tensor product (over the common base ring) of a
linear function
and a free module like a vector/matrix space.Warning
This class has no reason to be instantiated by the user, and is meant to be used by instances of
MixedIntegerLinearProgram
.INPUT:
parent
– the parent, aLinearTensorConstraintsParent_class
lhs
,rhs
– twosage.numerical.linear_tensor_element.LinearTensor
. The left and right hand side of the constraint (in)equality.equality
– boolean (default:False
). Whether the constraint is an equality. IfFalse
, it is a<=
inequality.
EXAMPLES:
sage: mip.<b> = MixedIntegerLinearProgram() sage: (b[2]+2*b[3]) * vector([1,2]) <= b[8] * vector([2,3]) - 5 (1.0, 2.0)*x_0 + (2.0, 4.0)*x_1 <= (-5.0, -5.0) + (2.0, 3.0)*x_2
>>> from sage.all import * >>> mip = MixedIntegerLinearProgram(names=('b',)); (b,) = mip._first_ngens(1) >>> (b[Integer(2)]+Integer(2)*b[Integer(3)]) * vector([Integer(1),Integer(2)]) <= b[Integer(8)] * vector([Integer(2),Integer(3)]) - Integer(5) (1.0, 2.0)*x_0 + (2.0, 4.0)*x_1 <= (-5.0, -5.0) + (2.0, 3.0)*x_2
- is_equation()[source]#
Whether the constraint is a chained equation
OUTPUT:
Boolean.
EXAMPLES:
sage: mip.<b> = MixedIntegerLinearProgram() sage: (b[0] * vector([1,2]) == 0).is_equation() True sage: (b[0] * vector([1,2]) >= 0).is_equation() False
>>> from sage.all import * >>> mip = MixedIntegerLinearProgram(names=('b',)); (b,) = mip._first_ngens(1) >>> (b[Integer(0)] * vector([Integer(1),Integer(2)]) == Integer(0)).is_equation() True >>> (b[Integer(0)] * vector([Integer(1),Integer(2)]) >= Integer(0)).is_equation() False
- is_less_or_equal()[source]#
Whether the constraint is a chained less-or_equal inequality
OUTPUT:
Boolean.
EXAMPLES:
sage: mip.<b> = MixedIntegerLinearProgram() sage: (b[0] * vector([1,2]) == 0).is_less_or_equal() False sage: (b[0] * vector([1,2]) >= 0).is_less_or_equal() True
>>> from sage.all import * >>> mip = MixedIntegerLinearProgram(names=('b',)); (b,) = mip._first_ngens(1) >>> (b[Integer(0)] * vector([Integer(1),Integer(2)]) == Integer(0)).is_less_or_equal() False >>> (b[Integer(0)] * vector([Integer(1),Integer(2)]) >= Integer(0)).is_less_or_equal() True
- lhs()[source]#
Return the left side of the (in)equality.
OUTPUT:
Instance of
sage.numerical.linear_tensor_element.LinearTensor
. A linear function valued in a free module.EXAMPLES:
sage: mip.<x> = MixedIntegerLinearProgram() sage: (x[0] * vector([1,2]) == 0).lhs() (1.0, 2.0)*x_0
>>> from sage.all import * >>> mip = MixedIntegerLinearProgram(names=('x',)); (x,) = mip._first_ngens(1) >>> (x[Integer(0)] * vector([Integer(1),Integer(2)]) == Integer(0)).lhs() (1.0, 2.0)*x_0
- rhs()[source]#
Return the right side of the (in)equality.
OUTPUT:
Instance of
sage.numerical.linear_tensor_element.LinearTensor
. A linear function valued in a free module.EXAMPLES:
sage: mip.<x> = MixedIntegerLinearProgram() sage: (x[0] * vector([1,2]) == 0).rhs() (0.0, 0.0)
>>> from sage.all import * >>> mip = MixedIntegerLinearProgram(names=('x',)); (x,) = mip._first_ngens(1) >>> (x[Integer(0)] * vector([Integer(1),Integer(2)]) == Integer(0)).rhs() (0.0, 0.0)
- sage.numerical.linear_tensor_constraints.LinearTensorConstraintsParent()[source]#
Return the parent for linear functions over
base_ring
.The output is cached, so only a single parent is ever constructed for a given base ring.
INPUT:
linear_functions_parent
– aLinearFunctionsParent_class
. The type of linear functions that the constraints are made out of.
OUTPUT:
The parent of the linear constraints with the given linear functions.
EXAMPLES:
sage: from sage.numerical.linear_functions import LinearFunctionsParent sage: from sage.numerical.linear_tensor import LinearTensorParent sage: from sage.numerical.linear_tensor_constraints import ....: LinearTensorConstraintsParent, LinearTensorConstraintsParent sage: LF = LinearFunctionsParent(QQ) sage: LT = LinearTensorParent(QQ^2, LF) sage: LinearTensorConstraintsParent(LT) Linear constraints in the tensor product of Vector space of dimension 2 over Rational Field and Linear functions over Rational Field
>>> from sage.all import * >>> from sage.numerical.linear_functions import LinearFunctionsParent >>> from sage.numerical.linear_tensor import LinearTensorParent >>> from sage.numerical.linear_tensor_constraints import Ellipsis.: LinearTensorConstraintsParent, LinearTensorConstraintsParent >>> LF = LinearFunctionsParent(QQ) >>> LT = LinearTensorParent(QQ**Integer(2), LF) >>> LinearTensorConstraintsParent(LT) Linear constraints in the tensor product of Vector space of dimension 2 over Rational Field and Linear functions over Rational Field
- class sage.numerical.linear_tensor_constraints.LinearTensorConstraintsParent_class(linear_tensor_parent)[source]#
Bases:
Parent
Parent for
LinearTensorConstraint
Warning
This class has no reason to be instantiated by the user, and is meant to be used by instances of
MixedIntegerLinearProgram
. Also, use theLinearTensorConstraintsParent()
factory function.INPUT/OUTPUT:
EXAMPLES:
sage: p = MixedIntegerLinearProgram() sage: LT = p.linear_functions_parent().tensor(RDF^2); LT Tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field sage: from sage.numerical.linear_tensor_constraints import LinearTensorConstraintsParent sage: LTC = LinearTensorConstraintsParent(LT); LTC Linear constraints in the tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field sage: type(LTC) <class 'sage.numerical.linear_tensor_constraints.LinearTensorConstraintsParent_class'>
>>> from sage.all import * >>> p = MixedIntegerLinearProgram() >>> LT = p.linear_functions_parent().tensor(RDF**Integer(2)); LT Tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field >>> from sage.numerical.linear_tensor_constraints import LinearTensorConstraintsParent >>> LTC = LinearTensorConstraintsParent(LT); LTC Linear constraints in the tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field >>> type(LTC) <class 'sage.numerical.linear_tensor_constraints.LinearTensorConstraintsParent_class'>
- Element[source]#
alias of
LinearTensorConstraint
- linear_functions()[source]#
Return the parent for the linear functions
OUTPUT:
Instance of
sage.numerical.linear_functions.LinearFunctionsParent_class
.EXAMPLES:
sage: mip.<x> = MixedIntegerLinearProgram() sage: ieq = (x[0] * vector([1,2]) >= 0) sage: ieq.parent().linear_functions() Linear functions over Real Double Field
>>> from sage.all import * >>> mip = MixedIntegerLinearProgram(names=('x',)); (x,) = mip._first_ngens(1) >>> ieq = (x[Integer(0)] * vector([Integer(1),Integer(2)]) >= Integer(0)) >>> ieq.parent().linear_functions() Linear functions over Real Double Field
- linear_tensors()[source]#
Return the parent for the linear functions
OUTPUT:
Instance of
sage.numerical.linear_tensor.LinearTensorParent_class
.EXAMPLES:
sage: mip.<x> = MixedIntegerLinearProgram() sage: ieq = (x[0] * vector([1,2]) >= 0) sage: ieq.parent().linear_tensors() Tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field
>>> from sage.all import * >>> mip = MixedIntegerLinearProgram(names=('x',)); (x,) = mip._first_ngens(1) >>> ieq = (x[Integer(0)] * vector([Integer(1),Integer(2)]) >= Integer(0)) >>> ieq.parent().linear_tensors() Tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field
- sage.numerical.linear_tensor_constraints.is_LinearTensorConstraint(x)[source]#
Test whether
x
is a constraint on module-valued linear functions.INPUT:
x
– anything.
OUTPUT:
Boolean.
EXAMPLES:
sage: mip.<x> = MixedIntegerLinearProgram() sage: vector_ieq = (x[0] * vector([1,2]) <= x[1] * vector([2,3])) sage: from sage.numerical.linear_tensor_constraints import is_LinearTensorConstraint sage: is_LinearTensorConstraint(vector_ieq) doctest:warning... DeprecationWarning: The function is_LinearTensorConstraint is deprecated; use 'isinstance(..., LinearTensorConstraint)' instead. See https://github.com/sagemath/sage/issues/38184 for details. True sage: is_LinearTensorConstraint('a string') False
>>> from sage.all import * >>> mip = MixedIntegerLinearProgram(names=('x',)); (x,) = mip._first_ngens(1) >>> vector_ieq = (x[Integer(0)] * vector([Integer(1),Integer(2)]) <= x[Integer(1)] * vector([Integer(2),Integer(3)])) >>> from sage.numerical.linear_tensor_constraints import is_LinearTensorConstraint >>> is_LinearTensorConstraint(vector_ieq) doctest:warning... DeprecationWarning: The function is_LinearTensorConstraint is deprecated; use 'isinstance(..., LinearTensorConstraint)' instead. See https://github.com/sagemath/sage/issues/38184 for details. True >>> is_LinearTensorConstraint('a string') False