Changeset 2631


Ignore:
Timestamp:
May 24, 2010 11:25:03 AM (11 years ago)
Author:
jwatson
Message:

Fixing parser bug in CBC plugin - testing failed to catch a change a while back, as this has been broken for some time...

File:
1 edited

Legend:

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

    r2593 r2631  
    312312        results.problem.number_of_objectives=1
    313313
    314         processing_constraints=None # None means header, True means constraints, False means variables.
     314        processing_constraints = None # None means header, True means constraints, False means variables.
     315        header_processed = False
    315316        INPUT = open(self.soln_file,"r")
    316317        for line in INPUT:
    317318          tokens = re.split('[ \t]+',line.strip())
    318           #print "LINE",line,len(tokens)
    319           if tokens[0] in ("Optimal", "Status"):
    320              # TBD - this logic isn't correct/complete. flush out as necessary.             
    321              continue
    322           if tokens[0] == "0": # indicates section start.
     319          # these are the only header entries CBC will generate (identified via browsing CbcSolver.cpp)
     320          if tokens[0] in ("Optimal", "Infeasible", "Unbounded", "Stopped", "Integer", "Status"):
     321             if tokens[0] == "Optimal":
     322                solution.status = SolutionStatus.optimal
     323                solution.gap = 0.0
     324                solution.objective['f'].value = eval(tokens[-1])
     325             elif tokens[0] == "Infeasible":
     326                solution.status = SolutionStatus.infeasible
     327                solution.gap = None
     328                return
     329             else:
     330                print "***WARNING: CBC plugin currently not processing solution status="+tokens[0]+" correctly. Full status line is: "+string.strip(line)
     331             header_processed = True
     332
     333          elif tokens[0] == "0": # indicates section start.
    323334             if processing_constraints is None:
    324335                processing_constraints = True
     
    326337                processing_constraints = False
    327338             else:
    328                 raise RuntimeError, "CBC encountered unexpected line=("+line.strip()+") in solution file="+self.soln_file+"; constraint and variable sections already processed!"
     339                raise RuntimeError, "CBC plugin encountered unexpected line=("+line.strip()+") in solution file="+self.soln_file+"; constraint and variable sections already processed!"
    329340
    330341          if (processing_constraints is True) and (extract_duals is True):
     
    332343             constraint_ax = eval(tokens[2]) # CBC reports the constraint row times the solution vector - not the slack.
    333344             constraint_dual = eval(tokens[3])
    334 
    335345             solution.constraint[constraint].dual = constraint_dual
    336346
     
    339349             variable_value = eval(tokens[2])
    340350             solution.variable[variable_name].value = variable_value
    341 
    342351             if extract_reduced_costs is True:
    343352                variable_reduced_cost = eval(tokens[3]) # currently ignored.
    344353                solution.variable[variable_name].rc = variable_reduced_cost
     354               
     355          elif header_processed is True:
     356             pass
     357         
    345358          else:
    346              raise RuntimeError, "CBC encountered unexpected line=("+line.strip()+") in solution file="+self.soln_file+"; expecting header, but found data!"
     359             raise RuntimeError, "CBC plugin encountered unexpected line=("+line.strip()+") in solution file="+self.soln_file+"; expecting header, but found data!"
    347360         
    348361        INPUT.close()
     
    384397
    385398pyutilib.services.register_executable(name="cbc")
    386 
Note: See TracChangeset for help on using the changeset viewer.