Changeset 9491


Ignore:
Timestamp:
Dec 14, 2014 10:50:55 PM (4 years ago)
Author:
wehart
Message:

Adding a domain property for SimpleVar? objects that
sets the initial domain value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyomo/trunk/pyomo/core/base/var.py

    r9484 r9491  
    717717        self.set_value(self.initial)
    718718
     719    #
     720    # 'domain' is a property so we can ensure that a 'bounds' attribute exists on the
     721    # domain object.
     722    #
     723    @property
     724    def domain(self):
     725        """
     726        Return the domain attribute.
     727        """
     728        return self._domain
     729
     730    @domain.setter
     731    def domain(self, domain):
     732        """
     733        Set the domain attribute to the given value.
     734        """
     735        if hasattr(domain, 'bounds'):
     736            self._domain = domain
     737            self._domain_init_value = domain
     738        else:
     739            raise ValueError("%s is not a valid domain. Variable domains must be an instance of "
     740                             "one of %s an object that declares a method for bounds (like a Pyomo Set)."
     741                             "Examples: NonNegativeReals, Integers, Binary"
     742                             % (domain, (RealSet, IntegerSet, BooleanSet)))
     743
    719744
    720745class IndexedVar(Var):
Note: See TracChangeset for help on using the changeset viewer.