def construct(self, values=None): OrderedSimpleSet.construct(self, values) for val in self.value: if type(val) is tuple: raise ValueError("ContinuousSet cannot contain tuples") if val.__class__ not in native_numeric_types: raise ValueError( "ContinuousSet can only contain numeric values") if self._bounds is None: raise ValueError("ContinuousSet '%s' must have at least two values indicating "\ "the range over which a differential equation is to be discretized" % (self.name)) if self._bounds[0].__class__ not in native_numeric_types: raise ValueError("Bounds on ContinuousSet must be numeric values") if self._bounds[1].__class__ not in native_numeric_types: raise ValueError("Bounds on ContinuousSet must be numeric values") # TBD: If a user specifies bounds they will be added to the set # unless the user specified bounds have been overwritten during # OrderedSimpleSet construction. This can lead to some unintuitive # behavior when the ContinuousSet is both initialized with values and # bounds are specified. The current implementation is consistent # with how 'Set' treats this situation. if self._bounds[0] not in self.value: self.add(self._bounds[0]) self._sort() if self._bounds[1] not in self.value: self.add(self._bounds[1]) self._sort() if len(self) < 2: raise ValueError("ContinuousSet '%s' must have at least two values indicating "\ "the range over which a differential equation is to be discretized" % (self.name)) self._fe = sorted(self)
def construct(self, values=None): """ Constructs a :py:class:`ContinuousSet` component """ timer = ConstructionTimer(self) OrderedSimpleSet.construct(self, values) for val in self.value: if type(val) is tuple: raise ValueError("ContinuousSet cannot contain tuples") if val.__class__ not in native_numeric_types: raise ValueError("ContinuousSet can only contain numeric " "values") if self._bounds is None: raise ValueError("ContinuousSet '%s' must have at least two values" " indicating the range over which a differential " "equation is to be discretized" % self.name) # If bounds were set using pyomo parameters, get their values lb = value(self._bounds[0]) ub = value(self._bounds[1]) self._bounds = (lb, ub) if self._bounds[0].__class__ not in native_numeric_types: raise ValueError("Bounds on ContinuousSet must be numeric values") if self._bounds[1].__class__ not in native_numeric_types: raise ValueError("Bounds on ContinuousSet must be numeric values") # TBD: If a user specifies bounds they will be added to the set # unless the user specified bounds have been overwritten during # OrderedSimpleSet construction. This can lead to some unintuitive # behavior when the ContinuousSet is both initialized with values and # bounds are specified. The current implementation is consistent # with how 'Set' treats this situation. if self._bounds[0] not in self.value: self.add(self._bounds[0]) self._sort() if self._bounds[1] not in self.value: self.add(self._bounds[1]) self._sort() if len(self) < 2: raise ValueError("ContinuousSet '%s' must have at least two values" " indicating the range over which a differential " "equation is to be discretized" % self.name) self._fe = sorted(self) timer.report()