| 1 |
===================================== |
| 2 |
:mod:`pulp`: Pulp classes |
| 3 |
===================================== |
| 4 |
.. module:: pulp |
| 5 |
|
| 6 |
.. currentmodule:: pulp |
| 7 |
|
| 8 |
.. autosummary:: |
| 9 |
|
| 10 |
LpProblem |
| 11 |
LpVariable |
| 12 |
LpAffineExpression |
| 13 |
LpConstraint |
| 14 |
LpConstraint.makeElasticSubProblem |
| 15 |
FixedElasticSubProblem |
| 16 |
|
| 17 |
.. todo:: LpFractionConstraint, FractionElasticSubProblem |
| 18 |
|
| 19 |
The LpProblem Class |
| 20 |
------------------- |
| 21 |
|
| 22 |
.. autoclass:: LpProblem |
| 23 |
:show-inheritance: |
| 24 |
|
| 25 |
Three important attributes of the problem are: |
| 26 |
|
| 27 |
.. attribute:: objective |
| 28 |
|
| 29 |
The objective of the problem, an :obj:`LpAffineExpression` |
| 30 |
|
| 31 |
.. attribute:: constraints |
| 32 |
|
| 33 |
An :class:`ordered dictionary<odict.OrderedDict>` of |
| 34 |
:class:`constraints<LpConstraint>` of the problem - indexed by their names. |
| 35 |
|
| 36 |
.. attribute:: status |
| 37 |
|
| 38 |
The return :data:`status <pulp.constants.LpStatus>` |
| 39 |
of the problem from the solver. |
| 40 |
|
| 41 |
Some of the more important methods: |
| 42 |
|
| 43 |
.. automethod:: solve |
| 44 |
.. automethod:: roundSolution |
| 45 |
.. automethod:: setObjective |
| 46 |
.. automethod:: writeLP |
| 47 |
.. automethod:: writeMPS |
| 48 |
.. automethod:: toJson |
| 49 |
.. automethod:: fromJson |
| 50 |
.. automethod:: variables |
| 51 |
|
| 52 |
Variables and Expressions |
| 53 |
------------------------- |
| 54 |
|
| 55 |
.. autoclass:: LpElement |
| 56 |
:members: |
| 57 |
|
| 58 |
---- |
| 59 |
|
| 60 |
.. autoclass:: LpVariable |
| 61 |
:members: |
| 62 |
|
| 63 |
Example: |
| 64 |
|
| 65 |
>>> x = LpVariable('x',lowBound = 0, cat='Continuous') |
| 66 |
>>> y = LpVariable('y', upBound = 5, cat='Integer') |
| 67 |
|
| 68 |
gives :math:`x \in [0,\infty)`, :math:`y \in (-\infty, 5]`, an |
| 69 |
integer. |
| 70 |
|
| 71 |
---- |
| 72 |
|
| 73 |
.. autoclass:: LpAffineExpression |
| 74 |
:show-inheritance: |
| 75 |
:members: |
| 76 |
|
| 77 |
In brief, :math:`\textsf{LpAffineExpression([(x[i],a[i]) for i in |
| 78 |
I])} = \sum_{i \in I} a_i x_i` where (note the order): |
| 79 |
|
| 80 |
* ``x[i]`` is an :class:`LpVariable` |
| 81 |
* ``a[i]`` is a numerical coefficient. |
| 82 |
|
| 83 |
---- |
| 84 |
|
| 85 |
.. autofunction:: lpSum |
| 86 |
|
| 87 |
|
| 88 |
Constraints |
| 89 |
----------- |
| 90 |
|
| 91 |
.. autoclass:: LpConstraint |
| 92 |
:show-inheritance: |
| 93 |
:members: |
| 94 |
|
| 95 |
|
| 96 |
.. autoclass:: FixedElasticSubProblem |
| 97 |
:show-inheritance: |
| 98 |
:members: |
| 99 |
|
| 100 |
Combinations and Permutations |
| 101 |
------------------------------ |
| 102 |
|
| 103 |
.. autofunction:: combination |
| 104 |
|
| 105 |
.. autofunction:: allcombinations |
| 106 |
|
| 107 |
.. autofunction:: permutation |
| 108 |
|
| 109 |
.. autofunction:: allpermutations |
| 110 |
|
| 111 |
.. autofunction:: value |
| 112 |
|