Changeset 5762


Ignore:
Timestamp:
May 12, 2012 4:55:50 PM (7 years ago)
Author:
wehart
Message:

Various documentation edits.

Location:
coopr.pyomo/trunk/coopr/pyomo/base
Files:
2 edited

Legend:

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

    r5759 r5762  
    2323from numvalue import NumericValue, NumericConstant, ZeroConstant, value, \
    2424     as_numeric
    25 #from set_types import *
    2625from indexed_component import IndexedComponent
    2726from misc import create_name, apply_indexed_rule
     
    124123        self.value = None
    125124        self._equality = False
     125
     126    def __str__(self):
     127        """
     128        Return a string representation of the constraint.  If the name attribute is None,
     129        then return ''.
     130        """
     131        if self.name is None:
     132            return ""
     133        else:
     134            return self.name
    126135
    127136    def __getstate__(self):
  • coopr.pyomo/trunk/coopr/pyomo/base/var.py

    r5761 r5762  
    3535                  'unused', 'used', )
    3636
     37
    3738class _VarData(NumericValue):
    38     """Holds the numeric value of a variable"""
     39    """
     40    This class defines the data for a single variable.
     41
     42    Constructor Arguments:
     43        name        The name of this variable.  Use None for a default value.
     44        domain      The domain of this variable.  Use None for a default value.
     45        component   The Var object that owns this data.
     46
     47    Public Class Attributes:
     48        active      If True, then this variable is active in the model.
     49        component   A weakref to the component object that owns this variable index.
     50        domain      The domain of this variable.
     51        fixed       If True, then this variable is treated as a fixed constant in the model.
     52        index       The index of this variable within the Var component.
     53        initial     The default initial value for this variable.
     54        lb          A lower bound for this variable.  The lower bound can be either
     55                        numeric constants, parameter values, expressions or any object that
     56                        can be called with no arguments.
     57        name        A text string that provides an easy-to-read representation of the
     58                        variable/index pair (e.g. var[x,y,z])
     59        status      An enumeration value (VarStatus) that indicates the status of the variable
     60                        value.
     61        ub          A upper bound for this variable.  The upper bound can be either
     62                        numeric constants, parameter values, expressions or any object that
     63                        can be called with no arguments.
     64        value       The numeric value of this variable.
     65    """
    3966
    4067    __slots__ = ['component','index','initial','active','lb','ub','fixed','status']
    4168
    42     # IMPT: If a specific argument is intended to be left unassigned, use the following default values in the constructor below:
    43     # name: None
    44     # domain: None
    45 
    4669    def __init__(self, name, domain, component):
    47         """Constructor"""
    48 
    49         # IMPT: The following three lines are equivalent to calling the
    50         #       basic NumericValue constructor, i.e., as follows:
    51         #       NumericValue.__init__(self, name, domain, None, False)
    52         #       That particular constructor call takes a lot of time
    53         #       for big models, and is unnecessary because we're not
    54         #       validating any values.
     70        # The following three lines are equivalent to calling the
     71        # basic NumericValue constructor, i.e., as follows:
     72        # NumericValue.__init__(self, name, domain, None, False)
    5573        self.name = name
    5674        self.domain = domain
    5775        self.value = None
    58 
    59         # NOTE: the "name" attribute (part of the base NumericValue class) is
    60         #       typically something like some_var[x,y,z] - an easy-to-read
    61         #       representation of the variable/index pair.
    62 
    63         # NOTE: the following is presently set by the parent. arguably, we
    64         #       should provide keywords to streamline initialization.
     76        #
    6577        if component is None:
    6678            self.component = None
    6779        else:
    6880            self.component = weakref.ref(component)
    69         self.index = None # the index of this variable within the "parent"
    70 
    71         # the default initial value for this variable.
     81        self.index = None
    7282        self.initial = None
    73 
    74         # is this variable an active component of the current model?
    7583        self.active = True
    76 
    77         # IMPORTANT: in contrast to the initial value, the lower and upper
    78         #             bounds of a variable can in principle be either numeric constants,
    79         #             parameter values, or expressions - anything is OK, as long as
    80         #             invoking () is legal.
    8184        self.lb = None
    8285        self.ub = None
    83 
    8486        self.fixed = False
    8587        self.status = VarStatus.undefined
    8688
    8789    def __str__(self):
    88         # the name can be None, in which case simply return "".
     90        """
     91        Return a string representation of the variable.  If the name attribute is None,
     92        then return ''
     93        """
    8994        if self.name is None:
    9095            return ""
     
    9297            return self.name
    9398
    94     #
    95     # IMPT: This class over-rides __getstate__ and __setstate__, due to the 'var' and 'component' weakrefs, and because of slots.
    96     #
    97 
    9899    def __getstate__(self):
    99 
     100        """
     101        This method must be defined because this class uses slots.
     102        """
    100103        result = NumericValue.__getstate__(self)
    101104        for i in _VarData.__slots__:
     
    106109
    107110    def __setstate__(self, state):
     111        """
     112        This method must be defined because this class uses slots.
     113        """
     114        result = NumericValue.__getstate__(self)
    108115        for (slot_name, value) in state.iteritems():
    109116            setattr(self, slot_name, value)
     
    173180                    "legal types are numeric constants or parameters"
    174181                    % (type(value),) )
    175 
    176182
    177183    def fixed_value(self):
     
    255261    """A numeric variable, which may be defined over a index"""
    256262
    257     """ Constructor
    258         Arguments:
    259            name         The name of this variable
    260            index        The index set that defines the distinct variables.
    261                           By default, this is None, indicating that there
    262                           is a single variable.
    263            domain       A set that defines the type of values that
    264                           each variable must be.
    265            default      A set that defines default values for this
    266                           variable.
    267            bounds       A rule for defining bounds values for this
    268                           variable.
    269            rule         A rule for setting up this variable with
    270                           existing model data
     263    """
     264    Constructor Arguments:
     265        name        The name of this variable
     266        index       The index set that defines the distinct variables.
     267                        By default, this is None, indicating that there
     268                        is a single variable.
     269        domain      A set that defines the type of values that
     270                        each variable must be.
     271        default     A set that defines default values for this
     272                        variable.
     273        bounds      A rule for defining bounds values for this
     274                        variable.
     275        rule        A rule for setting up this variable with
     276                        existing model data
    271277    """
    272278
     
    281287            return _VarArray.__new__(_VarArray)
    282288
    283     #
    284     # IMPT: The default __getstate__ and __setstate__ are fine - this class owns no weakrefs or slots,
    285     #       and should be able to rely on the base IndexedComponent methods.
    286     #
    287 
    288     # TODO: default and rule keywords are not used?
    289289    def __init__(self, *args, **kwd):
    290290        # Default keyword values
Note: See TracChangeset for help on using the changeset viewer.