Ignore:
Timestamp:
Dec 29, 2009 8:39:54 PM (10 years ago)
Author:
jwatson
Message:

Speed improvement to CPLEX solution reader - accessing solution attributes multiple times is expensive.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.plugins/trunk/coopr/plugins/mip/CPLEX.py

    r2048 r2065  
    323323                # skip the "constant-one" variable, used to capture/retain objective offsets in the CPLEX LP format.
    324324                if variable_name != "ONE_VAR_CONSTANT":
     325                   variable = None # cache the solution variable reference, as the getattr is expensive.
    325326                   try:
    326                        soln.variable[variable_name].value = eval(variable_value)
    327                        #print soln.variable[variable_name].value, type(soln.variable[variable_name].value)
     327                       variable = soln.variable[variable_name]
     328                       variable.value = eval(variable_value)
    328329                   except:
    329                        soln.variable[variable_name].value = variable_value
     330                       variable.value = variable_value
    330331                   if not variable_reduced_cost is None:
    331332                        try:
    332                             soln.variable[variable_name].rc = eval(variable_reduced_cost)
     333                            variable.rc = eval(variable_reduced_cost)
    333334                            if variable_status is not None:
    334335                               if variable_status == "LL":
    335                                   soln.variable[variable_name].lrc = eval(variable_reduced_cost)
     336                                  variable.lrc = eval(variable_reduced_cost)
    336337                               else:
    337                                   soln.variable[variable_name].lrc = 0.0
     338                                  variable.lrc = 0.0
    338339                               if variable_status == "UL":
    339                                   soln.variable[variable_name].urc = eval(variable_reduced_cost)
     340                                  variable.urc = eval(variable_reduced_cost)
    340341                               else:
    341                                   soln.variable[variable_name].urc = 0.0
     342                                  variable.urc = 0.0
    342343                        except:
    343344                            raise ValueError, "Unexpected reduced-cost value="+str(variable_reduced_cost)+" encountered for variable="+variable_name
     
    345346                constraint_name = None
    346347                constraint_dual = None
     348                constaint = None # cache the solution constraint reference, as the getattr is expensive.
    347349                for i in range(1,len(tokens)):
    348350                   field_name =  string.strip(tokens[i].split('=')[0])
     
    350352                   if field_name == "name":
    351353                      constraint_name = field_value
     354                      constraint = soln.constraint[constraint_name]
    352355                   elif field_name == "dual": # for LPs
    353356                      # assumes the name field is first.
    354357                      if eval(field_value) != 0.0:
    355                         soln.constraint[constraint_name].dual = eval(field_value)
     358                        constraint.dual = eval(field_value)
    356359                   elif field_name == "slack": # for MIPs
    357360                      # assumes the name field is first.
    358361                      if eval(field_value) != 0.0:
    359                         soln.constraint[constraint_name].slack = eval(field_value)
     362                        constraint.slack = eval(field_value)
    360363            elif tokens[0].startswith("problemName"):
    361364                filename = (string.strip(tokens[0].split('=')[1])).lstrip("\"").rstrip("\"")
Note: See TracChangeset for help on using the changeset viewer.