source: pyomo/trunk/pyomo/core/plugins/transform/standard_form.py @ 9475

Last change on this file since 9475 was 9475, checked in by wehart, 4 years ago

Updating the version #.

Renaming transformations to 'base.*' if they didn't have a specific
naming. NOTE: these are in the pyomo.core package ... which seems
odd. But we agreed that 'core' provides a connotation that we don't
intend.

Adding some documentation changes for 'pyomo help -t'.

File size: 2.2 KB
Line 
1from pyomo.util.plugin import alias
2
3from pyomo.core import *
4from pyomo.core.base import Var
5from pyomo.core.plugins.transform.hierarchy import IsomorphicTransformation
6from pyomo.core.plugins.transform.nonnegative_transform import *
7from pyomo.core.plugins.transform.equality_transform import *
8
9
10class StandardForm(IsomorphicTransformation):
11    """
12    Produces a standard-form representation of the model. This form has
13    the coefficient matrix (A), the cost vector (c), and the
14    constraint vector (b), where the 'standard form' problem is
15
16    min/max c'x
17    s.t.    Ax = b
18            x >= 0
19
20    Options
21        slack_names         Default auxiliary_slack
22        excess_names        Default auxiliary_excess
23        lb_names            Default _lower_bound
24        up_names            Default _upper_bound
25        pos_suffix          Default _plus
26        neg_suffix          Default _neg
27    """
28
29    alias("base.standard_form", doc="Create an equivalent LP model in standard form.")
30
31    def __init__(self, **kwds):
32        kwds['name'] = "standard_form"
33        super(StandardForm, self).__init__(**kwds)
34
35    def apply(self, model, **kwds):
36        """
37        Tranform a model to standard form
38        """
39
40        # Optional naming schemes to pass to EqualityTransform
41        eq_kwds = {}
42        eq_kwds["slack_names"] = kwds.pop("slack_names", "auxiliary_slack")
43        eq_kwds["excess_names"] = kwds.pop("excess_names", "auxiliary_excess")
44        eq_kwds["lb_names"] = kwds.pop("lb_names", "_lower_bound")
45        eq_kwds["ub_names"] = kwds.pop("ub_names", "_upper_bound")
46
47        # Optional naming schemes to pass to NonNegativeTransformation
48        nn_kwds = {}
49        nn_kwds["pos_suffix"] = kwds.pop("pos_suffix", "_plus")
50        nn_kwds["neg_suffix"] = kwds.pop("neg_suffix", "_minus")
51
52        nonneg = NonNegativeTransformation()
53        equality = EqualityTransform()
54
55        # Since NonNegativeTransform introduces new constraints
56        # (that aren't equality constraints) we call it first.
57        #
58        # EqualityTransform introduces new variables, but they are
59        # constrainted to be nonnegative.
60        sf = nonneg(model, **nn_kwds)
61        sf = equality(sf, **eq_kwds)
62
63        return sf
Note: See TracBrowser for help on using the repository browser.