def __init__(self, **kwds): # Suffix type information self._direction = None self._datatype = None self._rule = None # The suffix direction direction = kwds.pop('direction',Suffix.LOCAL) # The suffix datatype datatype = kwds.pop('datatype',Suffix.FLOAT) # The suffix construction rule # TODO: deprecate the use of 'rule' self._rule = kwds.pop('rule',None) self._rule = kwds.pop('initialize',self._rule) # Check that keyword values make sense (these function have # internal error checking). self.set_direction(direction) self.set_datatype(datatype) # Initialize base classes kwds.setdefault('ctype', Suffix) Component.__init__(self, **kwds) ComponentMap.__init__(self) if self._rule is None: self.construct()
def __init__(self, **kwds): # Suffix type information self._direction = None self._datatype = None self._rule = None # The suffix direction direction = kwds.pop('direction', Suffix.LOCAL) # The suffix datatype datatype = kwds.pop('datatype', Suffix.FLOAT) # The suffix construction rule # TODO: deprecate the use of 'rule' self._rule = kwds.pop('rule', None) self._rule = kwds.pop('initialize', self._rule) # Check that keyword values make sense (these function have # internal error checking). self.set_direction(direction) self.set_datatype(datatype) # Initialize base classes kwds.setdefault('ctype', Suffix) Component.__init__(self, **kwds) ComponentMap.__init__(self) if self._rule is None: self.construct()
def __init__(self, *args, **kwds): kwds.setdefault('ctype', ExternalFunction) Component.__init__(self, **kwds) self._constructed = True ### HACK ### # FIXME: We must declare an _index attribute because # block._add_temporary_set assumes ALL components define an # index. Sigh. self._index = None
def __init__(self, obj): self._aliased_object = None if isinstance(obj, Alias): obj = obj._aliased_object() if obj is not None: self._aliased_object = weakref.ref(obj) ctype = Alias if isinstance(obj, Component): ctype = obj.type() else: if not isinstance(obj, ComponentData): raise TypeError("Aliased object must be an " "instance of Component or ComponentData") ctype = obj.parent_component().type() Component.__init__(self, ctype=ctype)
def __init__(self, *args, **kwds): self._units = kwds.pop('units', None) if self._units is not None: self._units = units.get_units(self._units) self._arg_units = kwds.pop('arg_units', None) if self._arg_units is not None: self._arg_units = [units.get_units(u) for u in self._arg_units] kwds.setdefault('ctype', ExternalFunction) Component.__init__(self, **kwds) self._constructed = True ### HACK ### # FIXME: We must declare an _index attribute because # block._add_temporary_set assumes ALL components define an # index. Sigh. self._index = None
def __init__(self, *args, **kwds): from pyomo.core.base.sets import process_setarg # kwds.pop('noruleinit', None) Component.__init__(self, **kwds) # self._data = {} # if len(args) == 0 or (len(args) == 1 and args[0] is UnindexedComponent_set): # # If no indexing sets are provided, generate a dummy index # self._implicit_subsets = None self._index = UnindexedComponent_set elif len(args) == 1: # # If a single indexing set is provided, just process it. # self._implicit_subsets = None self._index = process_setarg(args[0]) else: # # If multiple indexing sets are provided, process them all, # and store the cross-product of these sets. The individual # sets need to stored in the Pyomo model, so the # _implicit_subsets class data is used for this temporary # storage. # # Example: Pyomo allows things like # "Param([1,2,3], range(100), initialize=0)". This # needs to create *3* sets: two SetOf components and then # the SetProduct. That means that the component needs to # hold on to the implicit SetOf objects until the component # is assigned to a model (where the implicit subsets can be # "transferred" to the model). # tmp = [process_setarg(x) for x in args] self._implicit_subsets = tmp self._index = tmp[0].cross(*tmp[1:])
def __init__(self, *args, **kwargs): """Construct a reference to an external function. There are two fundamental interfaces supported by :class:`ExternalFunction`: Python callback functions and AMPL external functions. **Python callback functions** (:class:`PythonCallbackFunction` interface) Python callback functions can be specified one of two ways: 1. FGH interface: A single external function call with a signature matching the :meth:`evaluate_fgh()` method. 2. Independent functions: One to three functions that can evaluate the function value, gradient of the function [partial derivatives] with respect to its inputs, and the Hessian of the function [partial second derivatives]. The ``function`` interface expects a function matching the prototype: .. code:: def function(*args): float The ``gradient`` and ``hessian`` interface expect functions matching the prototype: .. code:: def gradient_or_hessian(args, fixed=None): List[float] Where ``args`` is a tuple of function arguments and ``fixed`` is either None or a list of values equal in length to ``args`` indicating which arguments are currently fixed (``True``) or variable (``False``). **ASL function libraries** (:class:`AMPLExternalFunction` interface) Pyomo can also call functions compiled as part of an AMPL External Function library (see the `User-defined functions <https://www.ampl.com/REFS/HOOKING/#userdefinedfuncs>`_ section in the `Hooking your solver to AMPL <https://www.ampl.com/REFS/hooking3.pdf>`_ report). Links to these functions are declared by creating an :class:`ExternalFunction` and passing the compiled library name (or path) to the ``library`` keyword and the name of the function to the ``function`` keyword. """ self._units = kwargs.pop('units', None) if self._units is not None: self._units = units.get_units(self._units) self._arg_units = kwargs.pop('arg_units', None) if self._arg_units is not None: self._arg_units = [units.get_units(u) for u in self._arg_units] kwargs.setdefault('ctype', ExternalFunction) Component.__init__(self, **kwargs) self._constructed = True ### HACK ### # FIXME: We must declare an _index attribute because # block._add_temporary_set assumes ALL components define an # index. Sigh. self._index_set = None