Changeset 2636


Ignore:
Timestamp:
May 26, 2010 11:47:06 AM (11 years ago)
Author:
jwatson
Message:

Added a "noruleinit" keyword option to the Constraint and Objective classes. If specified, then the following hold:
(1) the user is explicitly taking responsibility for constructing individual index elements for instances of these classes.
(2) no warning will be output if no "rule" or "expr" keywords are specified in the constructors of these classes.
This change was motivated by the silence of pyomo if no rule is specified in a constraint constructor, making model
error diagnostics more difficult than they need be. If no rule is specified and the noruleinit keyword is absent, then
Pyomo will output a warning message indicating the situation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/base/constraint.py

    r2592 r2636  
    6262        tmprule = None
    6363        self._data = {}
     64        # a flag specified by the user to indicate that no construction
     65        # rule will be specified, and that constraints will be explicitly
     66        # added by the user. set via the "noruleinit" keyword. value doesn't
     67        # matter, as long as it isn't "None".
     68        self._no_rule_init = None         
    6469        if args == ():
    6570           self._data[None] = ObjectiveData()
     
    7681          elif key == "expr":
    7782             tmprule = kwd[key]
     83          elif key == "noruleinit":
     84             self._no_rule_init = kwd[key]             
    7885          else:
    7986             raise ValueError, "Objective constructor: unknown keyword - "+key
     
    8491        self.rule = tmprule
    8592        self.trivial=False
     93        self._constructed=False
    8694
    8795    def clear(self):
     
    134142
    135143    def construct(self, data=None):
     144        if pyomo.debug("verbose") or pyomo.debug("normal"):     #pragma:nocover
     145           print "Construcing objective "+self.name
     146        if self.rule is None:
     147           if self._no_rule_init is None:
     148              print "WARNING: No construction rule or expression specified for objective="+self.name
     149           return           
    136150        if self._constructed:
    137151            return
     
    241255        tmprule=None
    242256        self._data = {}
     257        # a flag specified by the user to indicate that no construction
     258        # rule will be specified, and that constraints will be explicitly
     259        # added by the user. set via the "noruleinit" keyword. value doesn't
     260        # matter, as long as it isn't "None".
     261        self._no_rule_init = None
    243262        #if args == ():
    244263        #   self._data[None]=ConstraintData()
     
    250269          elif key == "rule" or key == 'expr':
    251270             tmprule = kwd[key]
     271          elif key == "noruleinit":
     272             self._no_rule_init = kwd[key]
    252273          else:
    253274             raise ValueError, "Constraint constructor: unknown keyword - "+key
     
    301322           print "Construcing constraint "+self.name
    302323        if self.rule is None:
     324           if self._no_rule_init is None:
     325              print "WARNING: No construction rule or expression specified for constraint="+self.name
    303326           return
    304327        if self._constructed:
     
    348371        # index: the constraint index (should probably be renamed)
    349372        # expr: the constraint expression
    350         # model: the parent model
    351373
    352374        #
Note: See TracChangeset for help on using the changeset viewer.