File: elastic.rst

package info (click to toggle)
python-pulp 1.6.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,508 kB
  • sloc: python: 6,003; sh: 36; makefile: 25
file content (62 lines) | stat: -rw-r--r-- 2,301 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Elastic Constraints
^^^^^^^^^^^^^^^^^^^
.. currentmodule:: pulp

A constraint :math:`C(x) = c` (equality may be replaced by :math:`\le`
or :math:`\ge`)
can be elasticized to the form

.. math::   C(x) \in D

where :math:`D` denotes some interval containing the value
:math:`c`.

Define the constraint in two steps:

  #.  instantiate constraint (subclass of :class:`LpConstraint`) with target :math:`c`.
  #.  call its :meth:`~LpConstraint.makeElasticSubProblem` method which returns
      an object of type :class:`FixedElasticSubProblem` 
      (subclass of :class:`LpProblem`) - its objective is the minimization 
      of the distance of :math:`C(x)` from :math:`D`.

.. code-block:: python

   constraint = LpConstraint(..., rhs = c)
   elasticProblem = constraint.makeElasticSubProblem(
                          penalty = <penalty_value>,
                          proportionFreeBound = <freebound_value>,
                          proportionFreeBoundList = <freebound_list_value>,
                          )

where:
  *  ``<penalty_value>`` is a real number
  *  ``<freebound_value>`` :math:`a \in [0,1]` specifies a symmetric
     target interval :math:`D = (c(1-a),c(1+a))` about :math:`c`
  *  ``<freebound_list_value> = [a,b]``, a list of 
     proportions :math:`a, b \in [0,1]` specifying an asymmetric target 
     interval :math:`D = (c(1-a),c(1+b))` about :math:`c`

The penalty applies to the constraint at points :math:`x` where
:math:`C(x) \not \in D`.
The magnitude of ``<penalty_value>`` can be assessed by examining
the final objective function in the ``.lp`` file written by
:meth:`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])

#.    constraint_1 has a penalty-free target interval of 1% either side of the rhs value, 200
#.    constraint_2 has a penalty-free target interval of
      - 2% on left and 5% on the right side of the rhs value, 500

.. image:: _static/freebound.*
   :height:  5in
   :alt:  Freebound interval

Following are the methods of the return-value: