source: coopr.pyomo/trunk/coopr/pyomo/presolve/numeric_varlabels.py @ 2201

Last change on this file since 2201 was 2201, checked in by wehart, 10 years ago

Update to Coopr to account for changes in PyUtilib? package names.

File size: 1.3 KB
Line 
1#  _________________________________________________________________________
2#
3#  Coopr: A COmmon Optimization Python Repository
4#  Copyright (c) 2008 Sandia Corporation.
5#  This software is distributed under the BSD License.
6#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7#  the U.S. Government retains certain rights in this software.
8#  For more information, see the FAST README.txt file.
9#  _________________________________________________________________________
10
11import pyutilib.component.core
12from coopr.pyomo.base import IPyomoPresolver, IPyomoPresolveAction
13
14
15class NumericVarLabelsPresolver(pyutilib.component.core.SingletonPlugin):
16    """
17    This plugin changes variables names to use a simple name that
18    uses the variable id.
19    """
20
21    pyutilib.component.core.implements(IPyomoPresolveAction)
22
23    def __init__(self, **kwds):
24        kwds['name'] = "numeric_varlabels"
25        pyutilib.component.core.Plugin.__init__(self, **kwds)
26
27    def rank(self):
28        return 1000
29
30    def presolve(self,model):
31        """
32        The main routine to perform the presolve
33        """
34        for id in model._var:
35            model._var[id].label = "x_"+str(id)
36            model._name_varmap[model._var[id].label] = model._var[id]
37        for id in model._con:
38            model._con[id].label = "c_"+str(id)
39        return model
40
Note: See TracBrowser for help on using the repository browser.