Changeset 2872


Ignore:
Timestamp:
Jul 28, 2010 1:45:11 PM (9 years ago)
Author:
prsteel
Message:

Resolves issues with repeated call to identify_vars. The _varmap
attribute was not getting reset, so cloned models could have problems
with variable references.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/preprocess/identify_vars.py

    r2789 r2872  
    1111
    1212import pyutilib.component.core
    13 from coopr.pyomo.base import expr, _VarBase, Var, Constraint, Objective, \
    14      SOSConstraint
    15 from coopr.pyomo.base.var import _VarValue, VarStatus
     13from coopr.pyomo.base import expr, Constraint, Objective, SOSConstraint
     14from coopr.pyomo.base.var import  _VarValue, VarStatus, _VarArray, _VarBase, Var
    1615from coopr.pyomo.base.numvalue import NumericConstant
    1716from coopr.pyomo.base import IPyomoPresolver, IPyomoPresolveAction
     
    4443            # to return a value. Let
    4544            msg = str(e)
    46             msg += "\n    Do all constraints and objectives return a value?"
     45
     46            if isinstance(exp, _VarArray):
     47                msg += "\n    Have you properly indexed '%s'?" % str(exp)
     48            else:
     49                msg += "\n    Do all constraints and objectives return a " + \
     50                       "value?"
    4751            raise AttributeError, msg
    4852               
     
    9599        The main routine to perform the preprocess
    96100        """
    97        
     101
    98102        Vars = model.active_components(Var)
    99103        Con = model.active_components(Constraint)
     
    101105
    102106        Con.update(model.active_components(SOSConstraint))
    103        
     107
    104108        self.vnum=0
    105109        self.cnum=0
     
    109113        model.statistics.number_of_integer_variables = 0
    110114        model.statistics.number_of_continuous_variables = 0
     115
     116        #
     117        # Reset the _var map. Failing to reset can cause problems in cloned
     118        # instances.
     119        #
     120        model._var = {}
    111121       
    112122        #
     
    117127                var._varval[V].status = VarStatus.unused
    118128                var._varval[V].id = -1
    119                
     129
    120130        #
    121131        # Call identify_variables to find the variables that are
     
    133143                Obj[key]._data[ondx].id = self.onum
    134144                self.onum += 1
    135                
     145
    136146        for key in Con.keys():
    137147            C = Con[key]
     
    164174        #
    165175
    166         model.statistics.number_of_variables=self.vnum
    167         model.statistics.number_of_constraints=self.cnum
    168         model.statistics.number_of_objectives=self.onum
     176        model.statistics.number_of_variables = self.vnum
     177        model.statistics.number_of_constraints = self.cnum
     178        model.statistics.number_of_objectives = self.onum
    169179
    170180        return model
Note: See TracChangeset for help on using the changeset viewer.