Changeset 5830


Ignore:
Timestamp:
May 29, 2012 4:51:59 PM (7 years ago)
Author:
jdsiiro
Message:

Fix for r5828: the SparseIndexableComponent? handles _index_set slightly
differently from IndexedComponent?. Instead of diving down a rabbit hole
to try and get them to behave more similarly, we will instead move
SparseIndexableComponent? to use the more descriptive name,
"_implicit_subsets".

Location:
coopr.pyomo/trunk/coopr/pyomo/base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/base/block.py

    r5828 r5830  
    410410        # NB: only "old" IndexedComponent contain _index_set.
    411411        # SparseIndexedComponent does not have that attribute
    412         if val._index_set is not None:
     412        if '_index_set' in dir(val) and val._index_set is not None:
    413413            ctr=0
    414414            for tset in val._index_set:
     
    419419                    )
    420420                ctr += 1
    421             if val._index is None:
    422                 val._index = self._construct_temporary_set(
    423                     val._index_set,
    424                     val.name+"_index" )
     421            val._index = self._construct_temporary_set(
     422                val._index_set,
     423                val.name+"_index" )
     424        elif '_implicit_subsets' in dir(val) and val._implicit_subsets is not None:
     425            ctr=0
     426            for tset in val._implicit_subsets:
     427                if tset.name == "_unknown_":
     428                    self._construct_temporary_set(
     429                        tset,
     430                        val.name+"_index_"+str(ctr)
     431                        )
     432                ctr += 1
    425433        if isinstance(val._index,_SetContainer) and val._index.name == "_unknown_":
    426434            self._construct_temporary_set(val._index,val.name+"_index")
  • coopr.pyomo/trunk/coopr/pyomo/base/sparse_indexed_component.py

    r5828 r5830  
    6464            # If no indexing sets are provided, generate a dummy index
    6565            #
    66             self._index_set = None
     66            self._implicit_subsets = None
    6767            self._index = UnindexedComponent_set
    6868            self._data = {None: weakref.ref(self)}
    6969        elif len(args) == 1:
    70             self._index_set = None
     70            self._implicit_subsets = None
    7171            self._index = process_setarg(args[0])
    7272        else:
    73             self._index_set = [process_setarg(x) for x in args]
    74             self._index = self._index_set[0].cross(*(self._index_set[1:]))
     73            # NB: Pyomo requires that all modelling components are
     74            # assigned to the model.  The trick is that we allow things
     75            # like "Param([1,2,3], range(100), initialize=0)".  This
     76            # needs to create *3* sets: two SetOf components and then
     77            # the SetProduct.  That means that teh component needs to
     78            # hold on to the implicit SetOf objects until the component
     79            # is assigned to a model (where the implicit subsets can be
     80            # "transferred" to the model).
     81            tmp = [process_setarg(x) for x in args]
     82            self._implicit_subsets = tmp
     83            self._index = tmp[0].cross(*tmp[1:])
    7584        #
    7685        # Setup indices for suffix data
Note: See TracChangeset for help on using the changeset viewer.