Changeset 3046
- Timestamp:
- Sep 26, 2010 12:20:56 PM (11 years ago)
- Location:
- coopr.pyomo/stable
- Files:
-
- 1 deleted
- 18 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
coopr.pyomo/stable
- Property svnmerge-integrated changed
/coopr.pyomo/trunk merged: 3007-3013,3015-3017,3019-3030,3037,3041-3042
- Property svnmerge-integrated changed
-
coopr.pyomo/stable/coopr/pyomo/base/block.py
r2911 r3046 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/stable/coopr/pyomo/base/param.py
r2922 r3046 71 71 IndexedComponent.__init__(self, *args, **tkwd) 72 72 73 self._initialize = kwd.pop('initialize', {})73 self._initialize = kwd.pop('initialize', None ) 74 74 self._initialize = kwd.pop('rule', self._initialize ) 75 75 self._validate = kwd.pop('validate', None ) … … 89 89 msg = "Unknown keyword to Param constructor: '%s'" 90 90 raise ValueError, msg % kwd.values()[0] 91 92 93 def initialize(self, data): 94 self._initialize = data 91 95 92 96 … … 207 211 pass 208 212 213 if self._initialize is None: 214 self._initialize = getattr(self,'rule',{}) 209 215 # 210 216 # Construct using the initial data or the data loaded from an -
coopr.pyomo/stable/coopr/pyomo/base/sets.py
r2921 r3046 181 181 if self.domain is not None and element not in self.domain: 182 182 if use_exception: 183 raise ValueError, " Value "+str(element)+" is not valid for set "+self.name+", because it is not within set"+self.domain.name183 raise ValueError, "The value="+str(element)+" is not valid for set="+self.name+", because it is not within the domain="+self.domain.name 184 184 return False 185 185 if self.validate is not None and not self.validate(element,self.model): 186 186 if use_exception: 187 raise ValueError, " Value "+str(element)+" violates the validation rule of set"+self.name187 raise ValueError, "The value="+str(element)+" violates the validation rule of set="+self.name 188 188 return False 189 189 if self.dimen > 1 and type(element) is not tuple: 190 190 if use_exception: 191 raise ValueError, " Value "+str(element)+" is not a tuple for set "+self.name+", which has dimen"+str(self.dimen)191 raise ValueError, "The value="+str(element)+" is not a tuple for set="+self.name+", which has dimen="+str(self.dimen) 192 192 return False 193 193 elif self.dimen == 1 and type(element) is tuple: 194 194 if use_exception: 195 raise ValueError, " Value "+str(element)+" is a tuple for set "+self.name+", which has dimen"+str(self.dimen)195 raise ValueError, "The value="+str(element)+" is a tuple for set="+self.name+", which has dimen="+str(self.dimen) 196 196 return False 197 197 elif type(element) is tuple and len(element) != self.dimen: 198 198 if use_exception: 199 raise ValueError, " Value "+str(element)+" does not have dimension "+str(self.dimen)+", which is needed for set"+self.name199 raise ValueError, "The value="+str(element)+" does not have dimension="+str(self.dimen)+", which is needed for set="+self.name 200 200 return False 201 201 return True … … 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: -
coopr.pyomo/stable/coopr/pyomo/data/TableData.py
r2763 r3046 82 82 if header in self.options.param_name: 83 83 mapped_headers.append(self.options.param_name[header]) 84 else:85 mapped_headers.append(header)86 84 #print "X", mapped_headers, self.options.param_name, \ 87 85 # self.options.index, self.options.format … … 112 110 113 111 self._info = ["set",self.options.set, ":"] 114 self._info = self._info + list( mapped_headers[1:])112 self._info = self._info + list(headers[1:]) 115 113 self._info = self._info + [":="] 116 114 for row in rows: … … 119 117 elif self.options.format == 'transposed_array': 120 118 self._info = ["param",self.options.param,"(tr)",":"] \ 121 + mapped_headers[1:]119 + headers[1:] 122 120 self._info.append(":=") 123 121 for row in rows: … … 125 123 126 124 elif self.options.format == 'array': 127 self._info = ["param",self.options.param,":"] + mapped_headers[1:]125 self._info = ["param",self.options.param,":"] + headers[1:] 128 126 self._info.append(":=") 129 127 for row in rows: … … 155 153 msg = "Unknown parameter format: '%s'" 156 154 raise ValueError, msg % self.options.format 155 #print "FINAL",self._info -
coopr.pyomo/stable/coopr/pyomo/data/__init__.py
r2304 r3046 14 14 import parse_datacmds 15 15 import csv_table 16 #import db 16 import db_table -
coopr.pyomo/stable/coopr/pyomo/data/csv_table.py
r2592 r3046 35 35 def read(self): 36 36 tmp=[] 37 37 for tokens in csv.reader(self.INPUT): 38 38 if tokens != ['']: 39 39 tmp.append(tokens) -
coopr.pyomo/stable/coopr/pyomo/data/parse_datacmds.py
r3004 r3046 55 55 "WORD", 56 56 "WORDWITHINDEX", 57 "WORDWITHSQUOTEDINDEX", 57 58 "STRING", 58 59 "QUOTEDSTRING", … … 93 94 return t 94 95 96 def t_WORDWITHSQUOTEDINDEX(t): 97 r'[a-zA-Z_0-9][a-zA-Z_0-9\.\-]*\[[\'\"a-zA-Z_0-9\.\-,\* ]*\]' 98 t.type = reserved.get(t.value,'WORDWITHSQUOTEDINDEX') # Check for reserved words 99 return t 100 95 101 def t_WORD(t): 96 102 r'[a-zA-Z_0-9][a-zA-Z_0-9\.+\-]*' … … 109 115 110 116 def t_FILENAME(t): 111 r'[a-zA-Z _0-9\./\\]*(/|\\)[a-zA-Z_0-9\-\./\\]*'117 r'[a-zA-Z]+:[a-zA-Z_0-9\./\\]*(/|\\)[a-zA-Z_0-9\-\./\\]*|[a-zA-Z_0-9\./\\]*(/|\\)[a-zA-Z_0-9\-\./\\]*' 112 118 t.type = reserved.get(t.value,'FILENAME') # Check for reserved words 113 119 return t … … 184 190 | SET WORDWITHINDEX COLONEQ setdecl SEMICOLON 185 191 | SET WORDWITHINDEX COLONEQ SEMICOLON 192 | SET WORDWITHSQUOTEDINDEX COLONEQ setdecl SEMICOLON 193 | SET WORDWITHSQUOTEDINDEX COLONEQ SEMICOLON 186 194 | PARAM items COLONEQ paramdecl SEMICOLON 187 195 | IMPORT importdecl SEMICOLON … … 300 308 p[0] = [p[2]] 301 309 302 def p_ template(p):303 ''' template : LPAREN WORD index_list RPAREN310 def p_set_template(p): 311 '''set_template : LPAREN WORD index_list RPAREN 304 312 | LPAREN ASTERISK index_list RPAREN 305 313 | LPAREN WORD RPAREN … … 311 319 p[0] = p[1]+p[2]+p[3] 312 320 321 def p_param_template(p): 322 '''param_template : LBRACKET WORD index_list RBRACKET 323 | LBRACKET ASTERISK index_list RBRACKET 324 | LBRACKET WORD RBRACKET 325 | LBRACKET ASTERISK RBRACKET 326 ''' 327 if len(p) == 5: 328 p[0] = p[1]+",".join([p[2]]+p[3])+p[4] 329 else: 330 p[0] = p[1]+p[2]+p[3] 331 313 332 def p_items(p): 314 333 '''items : item items … … 322 341 '''item : WORD 323 342 | WORDWITHINDEX 343 | WORDWITHSQUOTEDINDEX 324 344 | NONWORD 325 345 | STRING … … 335 355 | RPAREN 336 356 | ASTERISK 337 | template 357 | set_template 358 | param_template 338 359 ''' 339 360 if p[1][0] == '"' and len(p[1]) > 2 and p[1][-1] == '"' and not ' ' in p[1]: … … 347 368 | QUOTEDSTRING 348 369 | FILENAME 349 | WORD COLON FILENAME350 370 ''' 351 371 if len(p) == 2: -
coopr.pyomo/stable/coopr/pyomo/data/process_data.py
r2585 r3046 17 17 from coopr.pyomo.base import pyomo 18 18 from coopr.pyomo.base.plugin import * 19 import pyutilib.common 19 20 20 21 global Lineno … … 111 112 ans=[] 112 113 i=0 113 flag=type(cmd[0]) is tuple114 114 tmp=None 115 ndx= None115 ndx=[] 116 116 while i<len(cmd): 117 117 if type(cmd[i]) is not tuple: 118 if flag:118 if len(ndx) > 0: 119 119 #if type(cmd[i]) is not tuple: 120 120 # raise ValueError, "Problem initializing set="+sname+" with input data="+str(cmd)+" - first element was interpreted as a tuple, but element="+str(i)+" is of type="+str(type(cmd[i]))+"; types must be consistent" 121 121 tmpval=tmp 122 tmpval[ndx] = _data_eval([cmd[i]])[0] 122 for kk in range(len(ndx)): 123 if i == len(cmd): 124 raise IOError, "Expected another set value to flush out a tuple pattern!" 125 tmpval[ndx[kk]] = _data_eval([cmd[i]])[0] 126 i += 1 123 127 # 124 128 # WEH - I'm not sure what the next two lines are for … … 128 132 # tmpval = util.tuplize(tmpval,d,sname) 129 133 ans.append(tuple(tmpval)) 134 continue 130 135 else: 131 136 ans.append(cmd[i]) … … 135 140 j = i 136 141 tmp=list(cmd[j]) 137 ndx=tmp.index("*") 142 ndx=[] 143 for kk in range(len(tmp)): 144 if tmp[kk] == '*': 145 ndx.append(kk) 146 #print 'NDX',ndx 138 147 i += 1 139 148 if pyomo.debug("reader"): #pragma:nocover … … 146 155 Called by _process_data to process data for a Parameter declaration 147 156 """ 157 #print 'x',cmd,_data 148 158 if pyomo.debug("reader"): #pragma:nocover 149 159 print "DEBUG: _process_param(start)",cmd … … 177 187 if pyomo.debug("reader"): #pragma:nocover 178 188 print "DEBUG: _process_param (singledef without :...:=)",cmd 189 cmd = _apply_templates(cmd) 190 #print 'cmd',cmd 179 191 if not transpose: 180 192 if pname not in _data: … … 315 327 316 328 329 def _apply_templates(cmd): 330 cmd = _data_eval(cmd) 331 template = [] 332 ilist = set() 333 ans = [] 334 i = 0 335 while i < len(cmd): 336 #print i, len(cmd), cmd[i], ilist, template, ans 337 if type(cmd[i]) is tuple and '*' in cmd[i]: 338 j = i 339 tmp=list(cmd[j]) 340 nindex = len(tmp) 341 template=tmp 342 ilist = set() 343 for kk in range(len(tmp)): 344 if tmp[kk] == '*': 345 ilist.add(kk) 346 elif len(ilist) == 0: 347 ans.append(cmd[i]) 348 else: 349 for kk in range(len(template)): 350 if kk in ilist: 351 ans.append(cmd[i]) 352 i += 1 353 else: 354 ans.append(template[kk]) 355 ans.append(cmd[i]) 356 i += 1 357 return ans 358 359 360 361 317 362 def _process_data_list(dim, cmd): 318 363 """ … … 357 402 continue 358 403 tmp = None 359 if "(" in val and ")" in val: 404 tval = val.strip() 405 if (tval[0] == "(" and tval[-1] == ")") or (tval[0] == '[' and tval[-1] == ']'): 360 406 vals = [] 361 tval = val[1:-1]407 tval = tval[1:-1] 362 408 for item in tval.split(","): 363 409 tmp=_data_eval([item]) … … 375 421 ans.append(tmp) 376 422 except ValueError: 377 ans.append(val) 423 if val[0] == "'" or val[0] == '"': 424 ans.append(val[1:-1]) 425 else: 426 ans.append(val) 378 427 if pyomo.debug("reader"): #pragma:nocover 379 428 print "DEBUG: _data_eval(end)",ans … … 473 522 options = Options(**cmd[1]) 474 523 for key in options: 475 if not key in ['range','filename','format','using',' query']:524 if not key in ['range','filename','format','using','driver','query','table','user','password']: 476 525 raise ValueError, "Unknown import option '%s'" % key 477 526 … … 484 533 # TODO: process mapping info 485 534 # 486 tmp = options.filename.split(".")[-1] 487 data = DataManagerFactory(tmp) 535 if options.using is None: 536 tmp = options.filename.split(".")[-1] 537 data = DataManagerFactory(tmp) 538 if data is None: 539 raise pyutilib.common.ApplicationError, "Cannot create data manager '%s'" % tmp 540 else: 541 data = DataManagerFactory(options.using) 542 if data is None: 543 raise pyutilib.common.ApplicationError, "Cannot create data manager '%s'" % options.using 488 544 set_name=None 489 545 param_name=None … … 518 574 param_name = None 519 575 # 520 data.initialize(options.filename, index=index, index_name=index_name, param_name=symb_map, set=set_name, param=param_name, format=options.format, range=options.range, query=options.query, using=options.using )576 data.initialize(options.filename, index=index, index_name=index_name, param_name=symb_map, set=set_name, param=param_name, format=options.format, range=options.range, query=options.query, using=options.using, table=options.table) 521 577 # 522 578 data.open() … … 527 583 raise e 528 584 data.close() 529 print "Y",_data530 585 data.process(_model, _data, _default) 531 #print "Y",_data532 586 533 587 -
coopr.pyomo/stable/coopr/pyomo/data/sheet.py
r2592 r3046 13 13 from pyutilib.excel import ExcelSpreadsheet 14 14 from pyutilib.component.core import alias 15 import pyutilib.common 15 16 16 17 … … 33 34 try: 34 35 self.sheet = ExcelSpreadsheet(self.filename) 35 except pyutilib. ApplicationError:36 except pyutilib.common.ApplicationError: 36 37 raise 37 38 -
coopr.pyomo/stable/coopr/pyomo/io/cpxlp.py
r2907 r3046 101 101 def _no_label_error ( var ): 102 102 msg = "Unable to find label for variable '%s'.\n" \ 103 'Possibly uninstantiated model. Do any constraint or objective ' \ 104 'rules reference the original Model() object, as opposed to the ' \ 105 'passed model object?' 103 'Possibly uninstantiated model. Do any constraint or objective ' \ 104 'rules reference the original Model() object, as opposed to the ' \ 105 'passed model object? Alternatively, if you are developing code, ' \ 106 'has the model instance been pre-processed?' 106 107 107 108 raise ValueError, msg % str(var) -
coopr.pyomo/stable/coopr/pyomo/preprocess/generic_varlabels.py
r2359 r3046 70 70 return tmp 71 71 72 def preprocess(self, model):72 def preprocess(self, model): 73 73 """ 74 74 The main routine to perform the preprocess … … 79 79 # variables. 80 80 # 81 Vars = model.active_components(Var)82 for var in Vars.values():81 active_variables = model.active_components(Var) 82 for var in active_variables.values(): 83 83 for V in var._varval.keys(): 84 84 var._varval[V].label = self._name_fix( var._varval[V].name ) 85 85 model._name_varmap[ var._varval[V].label ] = var._varval[V] 86 Cons = model.active_components(Constraint)87 for con in Cons.values():86 active_constraints = model.active_components(Constraint) 87 for con in active_constraints.values(): 88 88 for C in con._data: 89 89 con._data[C].label = self._name_fix( con._data[C].name ) 90 90 model._name_conmap[ con._data[C].label ] = con._data[C] 91 Objs = model.active_components(Objective)92 for obj in Objs.values():91 active_objectives = model.active_components(Objective) 92 for obj in active_objectives.values(): 93 93 for O in obj._data: 94 94 obj._data[O].label = self._name_fix( obj._data[O].name ) -
coopr.pyomo/stable/coopr/pyomo/preprocess/identify_vars.py
r3004 r3046 36 36 # 37 37 def _identify_variables(self, exp, model): 38 38 39 try: 39 40 if exp.fixed_value(): … … 73 74 if exp.id in model._var: 74 75 return 75 exp.id = self.v num76 model._var[self.v num] = exp77 self.v num+= 176 exp.id = self.var_count 77 model._var[self.var_count] = exp 78 self.var_count += 1 78 79 # 79 80 # Variable Base … … 86 87 if tmp.id in model._var: 87 88 return 88 tmp.id = self.v num89 model._var[self.v num] = tmp90 self.v num+= 189 tmp.id = self.var_count 90 model._var[self.var_count] = tmp 91 self.var_count += 1 91 92 # 92 93 # If not a constant, then this is an error … … 95 96 raise ValueError, "Unexpected expression type in identify_variables: " + str(type(exp))+" "+str(exp) 96 97 98 # 99 # this pre-processor computes a number of attributes of model components, in 100 # addition to models themselves. for VarValue, ConstraintData, and ObjectiveData, 101 # the routine assigns the "id" attribute. in addition, for VarValues, the routine 102 # sets the "status" attribute - to used or unused, depending on whether it appears 103 # in an active constraint/objective. on the Model object, the routine populates 104 # the "statistics" (variable/constraint/objective counts) attribute, and builds 105 # the _var, _con, and _obj dictionaries of a Model, which map the id attributes 106 # to the respective VarValue, ConstraintData, or ObjectiveData object. 107 # 108 # NOTE: if variables are fixed, then this preprocessor will flag them as unused 109 # and consequently not create entries for them in the model _var map. 110 # 97 111 98 112 def preprocess(self,model): … … 101 115 """ 102 116 103 Vars = model.active_components(Var)104 Con= model.active_components(Constraint)105 Obj= model.active_components(Objective)117 active_variables = model.active_components(Var) 118 active_constraints = model.active_components(Constraint) 119 active_objectives = model.active_components(Objective) 106 120 107 Con.update(model.active_components(SOSConstraint))121 active_constraints.update(model.active_components(SOSConstraint)) 108 122 109 self.v num=0110 self.c num=0111 self.o num=0123 self.var_count=0 124 self.constraint_count=0 125 self.objective_count=0 112 126 113 127 model.statistics.number_of_binary_variables = 0 … … 124 138 # Until proven otherwise, all variables are unused. 125 139 # 126 for var in Vars.values():127 for V in var._varval.keys():128 var ._varval[V].status = VarStatus.unused129 var ._varval[V].id = -1140 for var in active_variables.values(): 141 for var_value in var._varval.values(): 142 var_value.status = VarStatus.unused 143 var_value.id = -1 130 144 131 145 # … … 133 147 # used in the objective and constraints. 134 148 # 135 for key in Obj.keys():136 for ondx in Obj[key]._data:137 if not Obj[key]._data[ondx].active:149 for name, objective in active_objectives.items(): 150 for index, objective_data in objective._data.items(): 151 if not objective_data.active: 138 152 continue 139 153 try: 140 self._identify_variables( Obj[key]._data[ondx].expr, model)154 self._identify_variables(objective_data.expr, model) 141 155 except ValueError, err: 142 raise ValueError, "Problem processing objective %s (index %s): %s" % (str( key), str(ondx), str(err))156 raise ValueError, "Problem processing objective %s (index %s): %s" % (str(name), str(index), str(err)) 143 157 144 Obj[key]._data[ondx].id = self.onum 145 self.onum += 1 158 objective_data.id = self.objective_count 159 model._obj[self.objective_count] = objective_data 160 self.objective_count += 1 146 161 147 for key in Con.keys(): 148 C = Con[key] 149 for cndx in C.keys(): 150 if not C._data[cndx].active: 162 for name, constraint in active_constraints.items(): 163 for index, constraint_data in constraint._data.items(): 164 if not constraint_data.active: 151 165 continue 152 166 try: 153 self._identify_variables( C._data[cndx].body, model)167 self._identify_variables(constraint_data.body, model) 154 168 except ValueError, err: 155 raise ValueError, "Problem processing constraint %s (index %s): %s" % (str( key), str(cndx), str(err))156 C._data[cndx].id = self.cnum157 model._con[self.c num] = C._data[cndx]158 self.c num+= 1169 raise ValueError, "Problem processing constraint %s (index %s): %s" % (str(name), str(index), str(err)) 170 constraint_data.id = self.constraint_count 171 model._con[self.constraint_count] = constraint_data 172 self.constraint_count += 1 159 173 160 174 # … … 166 180 # each variable value. 167 181 # 168 for var in Vars.values():182 for var in active_variables.values(): 169 183 model.statistics.number_of_binary_variables += len(var.binary_keys()) 170 184 model.statistics.number_of_integer_variables += len(var.integer_keys()) … … 175 189 # 176 190 177 model.statistics.number_of_variables = self.v num178 model.statistics.number_of_constraints = self.c num179 model.statistics.number_of_objectives = self.o num191 model.statistics.number_of_variables = self.var_count 192 model.statistics.number_of_constraints = self.constraint_count 193 model.statistics.number_of_objectives = self.objective_count 180 194 181 195 return model -
coopr.pyomo/stable/coopr/pyomo/tests/examples/test_pyomo.py
r2611 r3046 45 45 self.pyomo('pmedian.py pmedian.dat', file=currdir+'test1.out') 46 46 self.failUnlessFileEqualsBaseline(currdir+"test1.out", currdir+"test1.txt") 47 48 def test1a(self): 49 """Simple execution of 'pyomo' with implicit rules""" 50 self.pyomo('pmedian3.py pmedian.dat', file=currdir+'test1a.out') 51 self.failUnlessFileEqualsBaseline(currdir+"test1a.out", currdir+"test1.txt") 47 52 48 53 def test2(self): -
coopr.pyomo/stable/coopr/pyomo/tests/unit/data8.dat
r2310 r3046 1 1 param A := False; 2 2 param B := True; 3 set Z := foo[*] bar 4 set Z[A] := foo[*] bar 3 set Z := foo[*] bar[ * ] bar[1,*,a,*] foo-bar hello-goodbye ; 4 set Z[A] := foo[*] bar[ * ] bar[1,*,a,*] foo-bar hello-goodbye ; -
coopr.pyomo/stable/coopr/pyomo/tests/unit/test_param.py
r3004 r3046 615 615 self.failUnlessEqual( self.instance.B['dd'], -14) 616 616 617 def test_io10(self): 618 OUTPUT=open("param.dat","w") 619 print >>OUTPUT, "data;" 620 print >>OUTPUT, "set A1 := a b c d e f g h i j k l ;" 621 print >>OUTPUT, "set A2 := 2 4 6 ;" 622 print >>OUTPUT, "param B :=" 623 print >>OUTPUT, " [*,2,*] a b 1 c d 2 e f 3" 624 print >>OUTPUT, " [*,4,*] g h 4 i j 5" 625 print >>OUTPUT, " [*,6,*] k l 6" 626 print >>OUTPUT, ";" 627 print >>OUTPUT, "end;" 628 OUTPUT.close() 629 self.model.A1=Set() 630 self.model.A2=Set() 631 self.model.B=Param(self.model.A1,self.model.A2,self.model.A1) 632 self.instance = self.model.create("param.dat") 633 self.failUnlessEqual( set(self.instance.B.keys()), set([('e', 2, 'f'), ('c', 2, 'd'), ('a', 2, 'b'), ('i', 4, 'j'), ('g', 4, 'h'), ('k', 6, 'l')])) 634 617 635 618 636 class TestParamError(PyomoModel): -
coopr.pyomo/stable/coopr/pyomo/tests/unit/test_set.py
r2867 r3046 2111 2111 self.failUnlessEqual( len(self.instance.F.keys()), 3) 2112 2112 self.failUnlessEqual( len(self.instance.F['A1']), 3) 2113 2114 def test_io8(self): 2115 OUTPUT=open(currdir+"setA.dat","w") 2116 print >>OUTPUT, "data;" 2117 print >>OUTPUT, "set E :=" 2118 print >>OUTPUT, "(A1,1,*) A1 A2" 2119 print >>OUTPUT, "(*,2,*) A2 A3" 2120 print >>OUTPUT, "(A3,3,*) A1 A3 ;" 2121 print >>OUTPUT, "end;" 2122 OUTPUT.close() 2123 self.model.E = Set(dimen=3) 2124 self.instance = self.model.create(currdir+"setA.dat") 2125 self.failUnlessEqual( len(self.instance.E), 5) 2126 2127 def test_io9(self): 2128 OUTPUT=open(currdir+"setA.dat","w") 2129 print >>OUTPUT, "data;" 2130 print >>OUTPUT, "set E :=" 2131 print >>OUTPUT, "(A1,1,A1) (A1,1,A2)" 2132 print >>OUTPUT, "(A2,2,A3)" 2133 print >>OUTPUT, "(A3,3,A1) (A3,3,A3) ;" 2134 print >>OUTPUT, "end;" 2135 OUTPUT.close() 2136 self.model.E = Set(dimen=3) 2137 self.instance = self.model.create(currdir+"setA.dat") 2138 self.failUnlessEqual( len(self.instance.E), 5) 2139 2140 def test_io10(self): 2141 OUTPUT=open(currdir+"setA.dat","w") 2142 print >>OUTPUT, "data;" 2143 print >>OUTPUT, "set A := 'A1 x' ' A2' \"A3\";" 2144 print >>OUTPUT, "set F['A1 x'] := 1 3 5;" 2145 print >>OUTPUT, "set F[\" A2\"] := 2 4 6;" 2146 print >>OUTPUT, "set F['A3'] := 3 5 7;" 2147 print >>OUTPUT, "end;" 2148 OUTPUT.close() 2149 self.model.A = Set() 2150 self.model.F = Set(self.model.A) 2151 self.instance = self.model.create(currdir+"setA.dat") 2152 self.failUnlessEqual( self.instance.F.dim(), 1) 2153 self.failUnlessEqual( len(self.instance.F.keys()), 3) 2154 self.failUnlessEqual( len(self.instance.F['A1 x']), 3) 2113 2155 2114 2156 -
coopr.pyomo/stable/coopr/pyomo/tests/unit/test_uninstantiated_model.txt
r2762 r3046 1 1 2 2 ERROR: Unable to find label for variable 'x'. 3 Possibly uninstantiated model. Do any constraint or objective rules reference the original Model() object, as opposed to the passed model object?3 Possibly uninstantiated model. Do any constraint or objective rules reference the original Model() object, as opposed to the passed model object? Alternatively, if you are developing code, has the model instance been pre-processed?
Note: See TracChangeset
for help on using the changeset viewer.