Changeset 2655


Ignore:
Timestamp:
Jun 11, 2010 10:08:09 AM (11 years ago)
Author:
khunter
Message:

No functional, just cleanup/formatting.

File:
1 edited

Legend:

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

    r2653 r2655  
    2525from set_types import *
    2626from component import Component
     27from sets import _SetContainer
    2728
    2829
     
    5354    alias("Objective", "Expressions that are minimized or maximized in a model.")
    5455
    55     def __init__(self, *args, **kwd):
     56    def __init__(self, *args, **kwargs):
    5657        """Construct an objective expression with rule to construct the
    5758           expression
    5859        """
    59         tkwd = {'ctype':Objective}
    60         IndexedComponent.__init__(self, *args, **tkwd)
    61         tmpname="unknown"
    62         tmpsense = minimize
    63         tmprule = None
     60        tkwargs = {'ctype':Objective}
     61        IndexedComponent.__init__(self, *args, **tkwargs)
     62
    6463        self._data = {}
    65         # a flag specified by the user to indicate that no construction
    66         # rule will be specified, and that constraints will be explicitly
    67         # added by the user. set via the "noruleinit" keyword. value doesn't
    68         # matter, as long as it isn't "None".
    69         self._no_rule_init = None         
    7064        if args == ():
    71            self._data[None] = ObjectiveData()
    72         self._quad_subexpr = None # this is a hack for now; we eventually want a "QuadraticObjective" class.       
    73         for key in kwd.keys():
    74           if key == "name":
    75              tmpname=kwd[key]
    76           elif key == "doc":
    77              self.doc=kwd[key]
    78           elif key == "rule":
    79              tmprule = kwd[key]
    80           elif key == "sense":
    81              tmpsense = kwd[key]
    82           elif key == "expr":
    83              tmprule = kwd[key]
    84           elif key == "noruleinit":
    85              self._no_rule_init = kwd[key]             
    86           else:
    87              raise ValueError, "Objective constructor: unknown keyword - "+key
    88         NumericValue.__init__(self,name=tmpname)
     65            self._data[None] = ObjectiveData()
     66
     67        # this is a hack for now; we eventually want a
     68        # "QuadraticObjective" class.
     69        self._quad_subexpr = None
     70
     71        tmpname  = kwargs.pop('name', 'unknown')
     72        tmpsense = kwargs.pop('sense', minimize )
     73        tmprule  = kwargs.pop('rule', None )
     74        tmprule  = kwargs.pop('expr', tmprule )
     75        self.doc = kwargs.pop('doc', None )
     76        self._no_rule_init = kwargs.get('noruleinit', None )
     77
     78        # _no_rule_init is a flag specified by the user to indicate that no
     79        # construction rule will be specified, and that constraints will be
     80        # explicitly added by the user. set via the "noruleinit" keyword. value
     81        # doesn't matter, as long as it isn't "None".
     82
     83        if ( kwargs ): # if dict not empty, there's an error.  Let user know.
     84            msg = "Creating constraint '%s': unknown option(s)\n\t%s"
     85            msg = msg % ( tmpname, ', '.join(kwargs.keys()) )
     86            raise ValueError, msg
     87
     88        NumericValue.__init__( self, name=tmpname )
     89
    8990        if None in self._data:
    9091            self._data[None].name = tmpname
    91         self.sense = tmpsense
    92         self.rule = tmprule
    93         self.trivial=False
    94         self._constructed=False
    95 
     92
     93        self.sense   = tmpsense
     94        self.rule    = tmprule
     95        self.trivial = False
     96        self._constructed = False
    9697
    9798    def clear(self):
Note: See TracChangeset for help on using the changeset viewer.