Changeset 3041
- Timestamp:
- Sep 23, 2010 11:10:03 PM (11 years ago)
- Location:
- coopr.pyomo/trunk/coopr/pyomo/base
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.pyomo/trunk/coopr/pyomo/base/block.py
r2911 r3041 56 56 def __init__(self, *args, **kwargs): 57 57 """Constructor""" 58 59 60 else: 61 58 if 'ctype' in kwargs: 59 tkwargs = {'ctype':kwargs['ctype']} 60 else: 61 tkwargs = {'ctype':Block} 62 62 IndexedComponent.__init__(self, *args, **tkwargs) 63 63 # 64 64 self.name=kwargs.get('name', 'unknown') 65 65 self._defer_construction=True 66 66 self._parent_block = None 67 67 # 68 68 # Define component dictionary: component type -> instance … … 83 83 84 84 def concrete_mode(self): 85 85 """Configure block to immediately construct components""" 86 86 self._defer_construction=False 87 87 88 88 def symbolic_mode(self): 89 89 """Configure block to defer construction of components""" 90 90 self._defer_construction=True 91 91 92 92 def components(self, ctype=None): 93 94 95 96 97 93 """ 94 Return information about the block components. If ctype is None, return the dictionary 95 that maps {component type -> {name -> instance}}. Otherwise, return the dictionary 96 that maps {name -> instance} for the specified component type. 97 """ 98 98 if ctype is None: 99 99 return self._component … … 103 103 104 104 def active_components(self, _ctype=None): 105 106 107 108 109 105 """ 106 Returns the active components in this block. If _ctype is None, return the 107 dictionary that maps {component type -> {name -> instance}}. Otherwise, return 108 the dictionary that maps {name -> instance} for the specified component type. 109 """ 110 110 tmp = {} 111 111 if _ctype is None: … … 159 159 160 160 def _clear_attribute(self,name): 161 161 """ 162 162 Cleanup the pre-existing model attribute 163 163 """ 164 164 if name in self._declarations: 165 165 self.__dict__[name]=None 166 166 del self._component[ self._declarations[name].type() ][name] 167 167 del self._declarations[name] 168 168 … … 203 203 # curr = self._parent_block 204 204 205 frame = sys._getframe(2) 206 locals_ = frame.f_locals 207 if getattr(val,'rule',None) is None and val.name+'_rule' in locals_: 208 val.rule = locals_[val.name+'_rule'] 205 209 if not self._defer_construction: 206 210 val.construct(None) … … 289 293 else: 290 294 print >>ostream, "Model "+self.name 291 295 # 292 296 print >>ostream, "" 293 297 print >>ostream, " Variables:" … … 298 302 for ndx in VAR: 299 303 VAR[ndx].display(prefix=" ",ostream=ostream) 300 304 # 301 305 print >>ostream, "" 302 306 print >>ostream, " Objectives:" … … 308 312 OBJ[ndx].display(prefix=" ",ostream=ostream) 309 313 print >>ostream, "" 310 314 # 311 315 CON = self.active_components(Constraint) 312 316 print >>ostream, " Constraints:" -
coopr.pyomo/trunk/coopr/pyomo/base/param.py
r3019 r3041 210 210 except: 211 211 pass 212 213 if self._initialize is None: 214 self._initialize = getattr(self,'rule',None) 212 215 213 216 # -
coopr.pyomo/trunk/coopr/pyomo/base/sets.py
r3037 r3041 227 227 return 228 228 self._constructed=True 229 230 if self.initialize is None: 231 self.initialize = getattr(self,'rule',None) 229 232 # 230 233 # Construct using the values list … … 837 840 if self.virtual: #pragma:nocover 838 841 raise TypeError, "It doesn't make sense to create a virtual set array" 842 843 if self.initialize is None: 844 self.initialize = getattr(self,'rule',None) 839 845 # 840 846 # Construct using the values list … … 974 980 return 975 981 self._constructed=True 982 983 if self.initialize is None: 984 self.initialize = getattr(self,'rule',None) 985 976 986 if self.virtual: 977 987 if len(self.set_tuple) == 0:
Note: See TracChangeset
for help on using the changeset viewer.