def __init__(self, *args, **kwd): # # Default keyword values # initialize = kwd.pop('initialize', None) initialize = kwd.pop('rule', initialize) domain = kwd.pop('within', Reals) domain = kwd.pop('domain', domain) bounds = kwd.pop('bounds', None) self._dense = kwd.pop('dense', True) self._units = kwd.pop('units', None) if self._units is not None: self._units = units.get_units(self._units) # # Initialize the base class # kwd.setdefault('ctype', Var) IndexedComponent.__init__(self, *args, **kwd) # # Determine if the domain argument is a functor or other object # self._domain_init_value = None self._domain_init_rule = None if is_functor(domain): self._domain_init_rule = domain else: self._domain_init_value = domain # # Allow for functions or functors for value initialization, # without confusing with Params, etc (which have a __call__ method). # self._value_init_value = None self._value_init_rule = None if is_functor(initialize) and (not isinstance(initialize, NumericValue)): self._value_init_rule = initialize else: self._value_init_value = initialize # # Determine if the bound argument is a functor or other object # self._bounds_init_rule = None self._bounds_init_value = None if is_functor(bounds): self._bounds_init_rule = bounds elif type(bounds) is tuple: self._bounds_init_value = bounds elif bounds is not None: raise ValueError( "Variable 'bounds' keyword must be a tuple or function")
def __init__(self, *args, **kwd): # # Default keyword values # initialize = kwd.pop('initialize', None ) initialize = kwd.pop('rule', initialize ) domain = kwd.pop('within', Reals ) domain = kwd.pop('domain', domain ) bounds = kwd.pop('bounds', None ) self._dense = kwd.pop('dense', True ) # # Initialize the base class # kwd.setdefault('ctype', Var) IndexedComponent.__init__(self, *args, **kwd) # # Determine if the domain argument is a functor or other object # self._domain_init_value = None self._domain_init_rule = None if is_functor(domain): self._domain_init_rule = domain else: self._domain_init_value = domain # # Allow for functions or functors for value initialization, # without confusing with Params, etc (which have a __call__ method). # self._value_init_value = None self._value_init_rule = None if is_functor(initialize) and (not isinstance(initialize,NumericValue)): self._value_init_rule = initialize else: self._value_init_value = initialize # # Determine if the bound argument is a functor or other object # self._bounds_init_rule = None self._bounds_init_value = None if is_functor(bounds): self._bounds_init_rule = bounds elif type(bounds) is tuple: self._bounds_init_value = bounds elif bounds is not None: raise ValueError("Variable 'bounds' keyword must be a tuple or function")
def __init__(self, *args, **kwds): self._init_rule = kwds.pop('rule', None) self._init_expr = kwds.pop('initialize', None) self._init_expr = kwds.pop('expr', self._init_expr) if is_functor(self._init_expr) and \ (not isinstance(self._init_expr, NumericValue)): raise TypeError("A callable type that is not a Pyomo " "expression can not be used to initialize " "an Expression object. Use 'rule' to initalize " "with function types.") if (self._init_rule is not None) and \ (self._init_expr is not None): raise ValueError("Both a rule and an expression can not be " "used to initialized an Expression object") kwds.setdefault('ctype', Expression) IndexedComponent.__init__(self, *args, **kwds)
def __init__(self, *args, **kwd): initialize = kwd.pop('initialize', None) initialize = kwd.pop('rule', initialize) self._dense = kwd.pop('dense', True) kwd.setdefault('ctype', BooleanVar) IndexedComponent.__init__(self, *args, **kwd) # Allow for functions or functors for value initialization, # without confusing with Params, etc (which have a __call__ method). # self._value_init_value = None self._value_init_rule = None if is_functor(initialize) and (not isinstance(initialize, BooleanValue)): self._value_init_rule = initialize else: self._value_init_value = initialize
def __init__(self, *args, **kwds): self._init_rule = kwds.pop('rule', None) self._init_expr = kwds.pop('initialize', None) self._init_expr = kwds.pop('expr', self._init_expr) if is_functor(self._init_expr) and \ (not isinstance(self._init_expr, NumericValue)): raise TypeError( "A callable type that is not a Pyomo " "expression can not be used to initialize " "an Expression object. Use 'rule' to initalize " "with function types.") if (self._init_rule is not None) and \ (self._init_expr is not None): raise ValueError( "Both a rule and an expression can not be " "used to initialized an Expression object") kwds.setdefault('ctype', Expression) IndexedComponent.__init__(self, *args, **kwds)