Operations on LP objects

AddConstraints(L, lhs, rhs): LP, Mtrx, Mtrx
Rel: MonStgElt                    Default: "eq"

Add some constraints to the LP problem \(L\). All constraints will have the same relation, given by Rel, which may be set to "eq" for strict equality (the default), "le" for less-or-equal constraints, or "ge" for greater-or-equal constraints.

Constraints are of the form

\[\sum_{j = 1}^{n}\hbox{\tt lhs}_{ij}\quad \hbox{\tt Rel}\quad \hbox{\tt rhs}_{i1}\]

where \(lhs\) and \(rhs\) are described in Section Explicit LP Solving Functions.

NumberOfConstraints(L): LP -> RngIntElt

The number of constraints in the LP problem \(L\).

NumberOfVariables(L): LP -> RngIntElt

The number of variables in the LP problem \(L\).

EvaluateAt(L, p): LP, Mtrx -> RngIntElt

Evaluate the objective function of the LP problem \(L\) at the point \(p\) given by a matrix.

Constraint(L, n): LP, RngIntElt -> Mtrx, Mtrx, RngIntElt

The LHS, RHS, and relation (\(-1\) for \(\le\), \(0\) for \(=\), \(1\) for \(\ge\)) of the \(n\)-th constraint of the LP problem \(L\).

IntegerSolutionVariables(L): LP -> SeqEnum

Sequence of indices of the variables in the LP problem \(L\) to be solved in integers.

ObjectiveFunction(L): LP -> Mtrx

The objective function of the LP problem \(L\).

IsMaximisingFunction(L): LP -> BoolElt

Returns true if the LP problem \(L\) is set to maximise its objective function, false if set to minimise.

RemoveConstraint(L, n): LP, RngIntElt

Remove the \(n\)-th constraint from the LP problem \(L\).

SetIntegerSolutionVariables(L, I, m): LP, SeqEnum[RngIntElt], BoolElt

Set the variables of the LP problem \(L\) indexed by elements of the sequence \(I\) to be solved in integers if \(m\) is true, or in the usual ring if false.

SetLowerBound(L, n, b): LP, RngIntElt, RngElt

Set the lower bound on the \(n\)-th variable in the LP problem \(L\) to \(b\).

Note that for all LP problems in Magma there is an implicit constraint that all variables are \(\geq 0\). This constraint is overridden if a lower bound is specified by using this function (e.g., specifying a lower bound of \(-5\) works as expected), but the lower bound can currently not be completely removed.

SetMaximiseFunction(L, m): LP, BoolElt

Set the LP problem \(L\) to maximise its objective function if \(m\) is true, or to minimise the objective function if \(m\) is false.

SetObjectiveFunction(L, F): LP, Mtrx

Set the objective function of the LP problem \(L\) to the matrix \(F\).

SetUpperBound(L, n, b): LP, RngIntElt, RngElt

Set the upper bound on the \(n\)-th variable in the LP problem \(L\) to \(b\).

Solution(L): LP -> Mtrx, RngIntElt

Solve the LP problem \(L\); returns a point representing an optimal solution, and an integer representing the state of the solution.

UnsetBounds(L): LP

Remove any bounds on all variables in the LP problem \(L\).

Note that this reactivates the implicit constraint that all variables are \(\geq 0\).

Example: Filling and Solving an LP Object (ex-b5bf57)

Run in calculator (opens in a new tab)

We use an LP object to solve the LP maximising \(F(x,y) = 3x + 13y\) subject to constraints \(2x + 9y <= 40\) \(11x -8y <= 82\)

> R := RealField( );
> L := LPProcess(R, 2);
> SetObjectiveFunction(L, Matrix(R, 1, 2, [3,13]));
> lhs := Matrix(R, 2, 2, [2, 9, 11, -8]);
> rhs := Matrix(R, 2, 1, [40, 82]);
> AddConstraints(L, lhs, rhs : Rel := "le");
> SetMaximiseFunction(L, true);
> L;
LP <Real Field, 2 variables>
Maximising objective function: [ 3 13]
Subject to constraints:
1 : [2 9] <= [40]
2 : [11 -8] <= [82]
Variables bounded above by: [ ]
Variables bounded below by: [ ]
Solving in integers for variables [ ]
> Solution(L);
[9.199999999999999289 2.400000000000000355]
0

Now, we place some bounds on y:

> SetUpperBound(L, 2, R!2);
> SetLowerBound(L, 2, R!1);
> Solution(L);
[8.909090909090908283 2.000000000000000000]
0

And find integer solutions:

> SetIntegerSolutionVariables(L, [1,2], true);
> Solution(L);
[8.000000000000000000 2.000000000000000000]
0

Now, removing the 2nd constraint:

> RemoveConstraint(L, 2);
> L;
LP <Real Field, 2 variables>
Maximising objective function: [ 3 13]
Subject to constraints:
1 : [2 9] <= [40]
Variables bounded above by: [ 2:2 ]
Variables bounded below by: [ 2:1 ]
Solving in integers for variables [ 1, 2 ]
> Solution(L);
[11.00000000000000000 2.000000000000000000]
0

And removing the restriction to Integer values for y,

> SetIntegerSolutionVariables(L, [2], false);
> Solution(L);
[15.00000000000000000 1.111111111111111160]
0

Run in calculator (opens in a new tab)