[Next][Prev] [Right] [Left] [Up] [Index] [Root]

Operations on LP objects

AddConstraints(L, lhs, rhs) : LP, Mtrx, Mtrx ->
    Rel: MonStgElt                      Default: "eq"
Add some constraints to 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)( LHS_(ij)) ( Rel) ( RHS_(i1))

NumberOfConstraints(L) : LP -> RngIntElt
The number of constraints in L.
NumberOfVariables(L) : LP -> RngIntElt
The number of variables in L.
EvaluateAt(L, p) : LP, Mtrx -> RngIntElt
Evaluate the objective function of L at the point p.
Constraint(L, n) : LP, RngIntElt -> Mtrx, Mtrx, RngIntElt
The LHS, RHS and relation (-1 for <= , 0 for =, 1 for >= ) of the n-th constraint of L.
IntegerSolutionVariables(L) : LP -> SeqEnum
Sequence of indices of the variables in L to be solved in integers.
ObjectiveFunction(L) : LP -> Mtrx
The objective function of L.
IsMaximisingFunction(L) : LP -> BoolElt
Returns true if L is set to maximise its objective function, false if set to minimise.
RemoveConstraint(L, n) : LP, RngIntElt ->
Remove the n-th constraint from L.
SetIntegerSolutionVariables(L, I, m) : LP, SeqEnum[RngIntElt], BoolElt ->
Set the variables of L indexed by elements of 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 of n in L to b.
SetMaximiseFunction(L, m) : LP, BoolElt ->
Set 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 L to F.
SetUpperBound(L, n, b) : LP, RngIntElt, RngElt ->
Set the upper bound on the n-th variable in 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 L.

Example LP_FillingLPObject (H100E4)

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
 [Next][Prev] [Right] [Left] [Up] [Index] [Root]