def __init__(self, *args, **kwd): self._rule = kwd.pop('rule', None) self._initialize = kwd.pop('initialize', {}) self._implicit = kwd.pop('implicit', {}) self._extends = kwd.pop('extends', None) kwd.setdefault('ctype', Port) IndexedComponent.__init__(self, *args, **kwd)
def __init__(self, *args, **kwd): self._rule = kwd.pop('rule', None) kwd['ctype'] = BuildCheck IndexedComponent.__init__(self, *args, **kwd) # if not type(self._rule) is types.FunctionType: raise ValueError("BuildCheck must have an 'rule' option specified whose value is a function")
def __init__(self, *args, **kwd): kwd.setdefault('ctype', Connector) self._rule = kwd.pop('rule', None) self._initialize = kwd.pop('initialize', {}) self._implicit = kwd.pop('implicit', {}) self._extends = kwd.pop('extends', None) IndexedComponent.__init__(self, *args, **kwd) self._conval = {}
def __init__(self, *args, **kwd): kwd.setdefault('ctype', Connector) self._rule = kwd.pop('rule', None) self._initialize = kwd.pop('initialize', None) self._implicit = kwd.pop('implicit', None) self._extends = kwd.pop('extends', None) IndexedComponent.__init__(self, *args, **kwd) self._conval = {}
def __init__(self, *args, **kwd): uncset = kwd.pop('uncset', None) self._uncset = uncset bounds = kwd.pop('bounds', None) self._bounds_init_value = None if type(bounds) is tuple: self._bounds_init_value = bounds elif bounds is not None: raise ValueError("Keyword 'bounds' has to be a tuple") kwd.setdefault('ctype', UncParam) IndexedComponent.__init__(self, *args, **kwd)
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, **kwds): _init = self._pop_from_kwargs( 'Expression', kwds, ('rule', 'expr', 'initialize'), None) # Historically, Expression objects were dense (but None): # setting arg_not_specified causes Initializer to recognize # _init==None as a constant initializer returning None # # To initialize a completely empty Expression, pass either # initialize={} (to require explicit setitem before a getitem), # or initialize=NOTSET (to allow getitem before setitem) self._rule = Initializer(_init, arg_not_specified=NOTSET) kwds.setdefault('ctype', Expression) IndexedComponent.__init__(self, *args, **kwds)
def reconstruct(self, data=None): """ Reconstruct this parameter object. This is particularly useful for cases where an initialize rule is provided. An initialize rule can return an expression that is a function of other parameters, so reconstruction can account for changes in dependent parameters. Only mutable parameters can be reconstructed. Otherwise, the changes would not be propagated into expressions in objectives or constraints. """ if not self._mutable: raise RuntimeError("Cannot invoke reconstruct method of immutable param="+self.name) IndexedComponent.reconstruct(self, data=data)
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): # # 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): _init = tuple(arg for arg in (kwds.pop(_arg, None) for _arg in ('rule', 'expr', 'initialize')) if arg is not None) if len(_init) == 1: _init = _init[0] elif not _init: _init = None else: raise ValueError( "Duplicate initialization: Expression() only " "accepts one of 'rule=', 'expr=', and 'initialize='") kwds.setdefault('ctype', Expression) IndexedComponent.__init__(self, *args, **kwds) self.rule = Initializer(_init)
def __init__(self, *args, **kwd): self._rule = kwd.pop('rule', None ) self._rule = kwd.pop('initialize', self._rule ) self._validate = kwd.pop('validate', None ) self.domain = kwd.pop('domain', Any ) self.domain = kwd.pop('within', self.domain ) self._mutable = kwd.pop('mutable', Param.DefaultMutable ) self._default_val = kwd.pop('default', None ) self._dense_initialize = kwd.pop('initialize_as_dense', False) # if 'repn' in kwd: logger.error( "The 'repn' keyword is not a validate keyword argument for Param") # if self.domain is None: self.domain = Any # kwd.setdefault('ctype', Param) IndexedComponent.__init__(self, *args, **kwd)
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, **kwd): self._rule = kwd.pop('rule', _NotValid ) self._rule = kwd.pop('initialize', self._rule ) self._validate = kwd.pop('validate', None ) self.domain = kwd.pop('domain', Any ) self.domain = kwd.pop('within', self.domain ) self._mutable = kwd.pop('mutable', Param.DefaultMutable ) self._default_val = kwd.pop('default', _NotValid ) self._dense_initialize = kwd.pop('initialize_as_dense', False) # if 'repn' in kwd: logger.error( "The 'repn' keyword is not a validate keyword argument for Param") # if self.domain is None: self.domain = Any # kwd.setdefault('ctype', Param) IndexedComponent.__init__(self, *args, **kwd)
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, **kwds): _init = tuple(arg for arg in (kwds.pop(_arg, None) for _arg in ('rule', 'expr', 'initialize')) if arg is not None) if len(_init) == 1: _init = _init[0] elif not _init: _init = None else: raise ValueError( "Duplicate initialization: Expression() only " "accepts one of 'rule=', 'expr=', and 'initialize='") kwds.setdefault('ctype', Expression) IndexedComponent.__init__(self, *args, **kwds) # Historically, Expression objects were dense (but None): # setting arg_not_specified causes Initializer to recognize # _init==None as a constant initializer returning None self._rule = Initializer(_init, arg_not_specified=NOTSET)
def __init__(self, *args, **kwd): _init = self._pop_from_kwargs('Param', kwd, ('rule', 'initialize'), NOTSET) self._rule = Initializer(_init, treat_sequences_as_mappings=False, arg_not_specified=NOTSET) self.domain = self._pop_from_kwargs('Param', kwd, ('domain', 'within')) if self.domain is None: self.domain = _ImplicitAny(owner=self, name='Any') self._validate = kwd.pop('validate', None) self._mutable = kwd.pop('mutable', Param.DefaultMutable) self._default_val = kwd.pop('default', Param.NoValue) self._dense_initialize = kwd.pop('initialize_as_dense', False) self._units = kwd.pop('units', None) if self._units is not None: self._units = units.get_units(self._units) self._mutable = True kwd.setdefault('ctype', Param) IndexedComponent.__init__(self, *args, **kwd)
def __init__(self, *args, **kwargs): # # Default keyword values # self._rule_init = Initializer(self._pop_from_kwargs( 'Var', kwargs, ('rule', 'initialize'), None)) self._rule_domain = SetInitializer(self._pop_from_kwargs( 'Var', kwargs, ('domain', 'within'), Reals)) _bounds_arg = kwargs.pop('bounds', None) self._dense = kwargs.pop('dense', True) self._units = kwargs.pop('units', None) if self._units is not None: self._units = units.get_units(self._units) # # Initialize the base class # kwargs.setdefault('ctype', Var) IndexedComponent.__init__(self, *args, **kwargs) # # Now that we can call is_indexed(), process bounds initializer # if self.is_indexed(): treat_bounds_sequences_as_mappings = not ( isinstance(_bounds_arg, Sequence) and len(_bounds_arg) == 2 and not isinstance(_bounds_arg[0], Sequence) ) else: treat_bounds_sequences_as_mappings = False if not self._dense: logger.warning( "ScalarVar object '%s': dense=False is not allowed " "for scalar variables; converting to dense=True" % (self.name,)) self._dense = True self._rule_bounds = Initializer( _bounds_arg, treat_sequences_as_mappings=treat_bounds_sequences_as_mappings )
def __init__(self, *args, **kwd): self._rule = kwd.pop('rule', Param.NoValue ) self._rule = kwd.pop('initialize', self._rule ) self._validate = kwd.pop('validate', None ) self.domain = kwd.pop('domain', None ) self.domain = kwd.pop('within', self.domain ) self._mutable = kwd.pop('mutable', Param.DefaultMutable ) self._default_val = kwd.pop('default', Param.NoValue ) self._dense_initialize = kwd.pop('initialize_as_dense', False) self._units = kwd.pop('units', None) if self._units is not None: self._units = units.get_units(self._units) self._mutable = True # if 'repn' in kwd: logger.error( "The 'repn' keyword is not a validate keyword argument for Param") # if self.domain is None: self.domain = _ImplicitAny(owner=self, name='Any') # kwd.setdefault('ctype', Param) IndexedComponent.__init__(self, *args, **kwd)
def __init__(self, *args, **kwd): uncset = kwd.pop('uncset', None) self._uncset = uncset kwd.setdefault('ctype', UncParam) IndexedComponent.__init__(self, *args, **kwd)