| LpProblem([name, sense]) | An LP Problem |
| LpVariable(name[, lowBound, upBound, cat, e]) | This class models an LP Variable with the specified associated parameters |
| LpAffineExpression([e, constant, name]) | A linear combination of LpVariables. |
| LpConstraint([e, sense, name, rhs]) | An LP constraint |
| LpConstraint.makeElasticSubProblem(*args, ...) | Builds an elastic subproblem by adding variables to a hard constraint |
| FixedElasticSubProblem(constraint[, ...]) | Contains the subproblem generated by converting a fixed constraint into an elastic constraint. |
Todo
LpFractionConstraint, FractionElasticSubProblem
Bases: object
An LP Problem
Creates an LP Problem
This function creates a new LP Problem with the specified associated parameters
| Parameters: |
|
|---|---|
| Returns: | An LP Problem |
Three important attributes of the problem are:
The objective of the problem, an LpAffineExpression
An ordered dictionary of constraints of the problem - indexed by their names.
Some of the more important methods:
Solve the given Lp problem.
This function changes the problem to make it suitable for solving then calls the solver.actualSolve() method to find the solution
| Parameters: |
|
|---|
Rounds the lp variables
Sets the input variable as the objective function. Used in Columnwise Modelling
| Parameters: |
|
|---|
Write the given Lp problem to a .lp file.
This function writes the specifications (objective function, constraints, variables) of the defined Lp problem to a file.
| Parameters: |
|
|---|
Base class for LpVariable and LpConstraintVar
This class models an LP Variable with the specified associated parameters
| Parameters: |
|
|---|
adds a variable to the constraints indicated by the LpConstraintVars in e
Creates a dictionary of LP variables
| Parameters: |
|
|---|---|
| Returns: | A dictionary of LP Variables |
sets the initial value of the Variable to val may of may not be supported by the solver
Example:
>>> x = LpVariable('x',lowBound = 0, cat='Continuous')
>>> y = LpVariable('y', upBound = 5, cat='Integer')
gives
,
, an
integer.
Bases: collections.OrderedDict
A linear combination of LpVariables. Can be initialised with the following:
Examples:
>>> f=LpAffineExpression(LpElement('x'))
>>> f
1*x + 0
>>> x_name = ['x_0', 'x_1', 'x_2']
>>> x = [LpVariable(x_name[i], lowBound = 0, upBound = 10) for i in range(3) ]
>>> c = LpAffineExpression([ (x[0],1), (x[1],-3), (x[2],4)])
>>> c
1*x_0 + -3*x_1 + 4*x_2 + 0
In brief,
where (note the order):
- x[i] is an LpVariable
- a[i] is a numerical coefficient.
Calculate the sum of a list of linear expressions
| Parameters: |
|
|---|
Bases: pulp.pulp.LpAffineExpression
An LP constraint
| Parameters: |
|
|---|
Builds an elastic subproblem by adding variables to a hard constraint
uses FixedElasticSubProblem
A constraint
(equality may be replaced by
or
)
can be elasticized to the form

where
denotes some interval containing the value
.
Define the constraint in two steps:
- instantiate constraint (subclass of LpConstraint) with target
.
- call its makeElasticSubProblem() method which returns an object of type FixedElasticSubProblem (subclass of LpProblem) - its objective is the minimization of the distance of
from
.
constraint = LpConstraint(..., rhs = c)
elasticProblem = constraint.makeElasticSubProblem(
penalty = <penalty_value>,
proportionFreeBound = <freebound_value>,
proportionFreeBoundList = <freebound_list_value>,
)
specifies a symmetric
target interval
about 
specifying an asymmetric target
interval
about 
The penalty applies to the constraint at points
where
.
The magnitude of <penalty_value> can be assessed by examining
the final objective function in the .lp file written by
LpProblem.writeLP().
Example:
>>> constraint_1 = LpConstraint('ex_1',sense=1,rhs=200)
>>> elasticProblem_1 = constraint_1.makeElasticSubproblem(penalty=1, proportionFreeBound = 0.01)
>>> constraint_2 = LpConstraint('ex_2',sense=0,rhs=500)
>>> elasticProblem_2 = constraint_2.makeElasticSubproblem(penalty=1,
proportionFreeBoundList = [0.02, 0.05])
Following are the methods of the return-value:
Bases: pulp.pulp.LpProblem
Contains the subproblem generated by converting a fixed constraint
into an elastic constraint.
| Parameters: |
|
|---|
Alters the name of anonymous parts of the problem
de-elasticize constraint
The amount the actual value varies from the RHS (sense: LHS - RHS)
for elastic constraints finds the LHS value of the constraint without the free variable and or penalty variable assumes the constant is on the rhs
returns true if the penalty variables are non-zero
Make the Subproblem elastic again after deElasticize
returns an iterator that lists the combinations of orgset of length k
| Parameters: |
|
|---|---|
| Returns: | an iterator of the subsets |
example:
>>> c = combination([1,2,3,4],2)
>>> for s in c:
... print s
(1, 2)
(1, 3)
(1, 4)
(2, 3)
(2, 4)
(3, 4)
returns all permutations of orgset with up to k items
| Parameters: |
|
|---|---|
| Returns: | an iterator of the subsets |
example:
>>> c = allcombinations([1,2,3,4],2)
>>> for s in c:
... print s
(1,)
(2,)
(3,)
(4,)
(1, 2)
(1, 3)
(1, 4)
(2, 3)
(2, 4)
(3, 4)
returns an iterator that lists the permutations of orgset of length k
| Parameters: |
|
|---|---|
| Returns: | an iterator of the subsets |
example:
>>> c = permutation([1,2,3,4],2)
>>> for s in c:
... print s
(1, 2)
(1, 3)
(1, 4)
(2, 1)
(2, 3)
(2, 4)
(3, 1)
(3, 2)
(3, 4)
(4, 1)
(4, 2)
(4, 3)
returns all permutations of orgset with up to k items
| Parameters: |
|
|---|---|
| Returns: | an iterator of the subsets |
example:
>>> c = allpermutations([1,2,3,4],2)
>>> for s in c:
... print s
(1,)
(2,)
(3,)
(4,)
(1, 2)
(1, 3)
(1, 4)
(2, 1)
(2, 3)
(2, 4)
(3, 1)
(3, 2)
(3, 4)
(4, 1)
(4, 2)
(4, 3)
Returns the value of the variable/expression x, or x if it is a number
