Changeset 1415


Ignore:
Timestamp:
07/14/09 20:46:21 (5 years ago)
Author:
wehart
Message:

Optimization of the processing done to generate generic
variable/constraint names. This eliminates many many calls to Python's
string.replace() method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/coopr/pyomo/presolve/generic_varlabels.py

    r1414 r1415  
    1212import pyutilib.plugin 
    1313 
     14ignore = set(['"', ' ', "'", '`']) 
     15underscore = set(['[', ']', "(", ')', ',', '-']) 
    1416 
    1517class GenericVarLabelsPresolver(pyutilib.plugin.SingletonPlugin): 
     
    2931 
    3032    def _name_fix(self, name): 
    31          name = name.replace("\"","") 
    32          name = name.replace("%","_") 
    33          name = name.replace("[","_") 
    34          name = name.replace("]","_") 
    35          name = name.replace("(","_") 
    36          name = name.replace(")","_") 
    37          name = name.replace(" ","") 
    38          name = name.replace(",","_") 
    39          name = name.replace("-","_") 
    40          name = name.replace("'","") 
    41          name = name.replace("`","") 
    42          return name 
     33        global ignore 
     34        global underscore 
     35        tmp="" 
     36        for c in name: 
     37            if c in underscore: 
     38                tmp += '_' 
     39            elif not c in ignore: 
     40                tmp += c 
     41        return tmp 
    4342 
    4443    def presolve(self,model): 
Note: See TracChangeset for help on using the changeset viewer.