Changeset 2071 for coopr.plugins


Ignore:
Timestamp:
Dec 30, 2009 12:46:20 AM (10 years ago)
Author:
wehart
Message:

Merged revisions 1971-2070 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.plugins/trunk

........

r1974 | wehart | 2009-12-06 17:20:56 -0700 (Sun, 06 Dec 2009) | 2 lines


Updating PyPI categories

........

r1980 | jwatson | 2009-12-11 22:51:19 -0700 (Fri, 11 Dec 2009) | 5 lines


Added extraction of reduced-costs for variables in CBC plugin solution reader. Additionally, all values need to be pushed into the solution, whether non-zero or not. If this isn't done, then when the instance is loaded, only a subset of the variable values (and reduced-costs) are over-ridden. Supression of 0 values does happen in the solution output routine.


NOTE: This does kill the CBC tests due to the presence of reduced-costs in the solution print. Correcting these will require some help from Bill.

........

r1981 | jwatson | 2009-12-11 23:04:10 -0700 (Fri, 11 Dec 2009) | 5 lines


Major re-work to GLPK interface, which was failing to read pretty much all solutions correctly. In particular, if identifiers are longer than the "usual" GLPK field width, the index/name and various values/status elements are split across multiple lines. This wrecks unit tests, but those will have to be revisited anyway - we still don't handle MIPs correctly, as the formats between MIP and LP are radically different.


Plan is to commit the MIP fix first, and then we can revisit the unit tests.

........

r1982 | jwatson | 2009-12-11 23:37:41 -0700 (Fri, 11 Dec 2009) | 3 lines


Added MIP solution read capability to GLPK plugin. Now able to read MIP solutions in via Pyomo and display attributes!

........

r1984 | jwatson | 2009-12-12 10:43:14 -0700 (Sat, 12 Dec 2009) | 3 lines


CPLEX has warm-start capabilities - over-riding base OptSolver? query method to indicate so.

........

r1988 | jwatson | 2009-12-12 11:43:54 -0700 (Sat, 12 Dec 2009) | 3 lines


More updates to the GLPK plug-in.

........

r1989 | jwatson | 2009-12-12 13:05:28 -0700 (Sat, 12 Dec 2009) | 3 lines


Fix to GLPK plug-in when parsing solution files that are time-limited.

........

r1991 | wehart | 2009-12-12 23:28:15 -0700 (Sat, 12 Dec 2009) | 2 lines


Update to test baselines.

........

r1997 | jwatson | 2009-12-13 15:17:34 -0700 (Sun, 13 Dec 2009) | 3 lines


Changing _component reference to active_component.

........

r2006 | jwatson | 2009-12-17 08:06:30 -0700 (Thu, 17 Dec 2009) | 3 lines


Missed CPLEX.py in the transition from model _component[] to components() access.

........

r2013 | jwatson | 2009-12-17 16:32:26 -0700 (Thu, 17 Dec 2009) | 3 lines


Added fully-tested (whatever that means!) urc and lrc reduced-cost solution loading to the CPLEX plugin.

........

r2014 | wehart | 2009-12-17 18:24:27 -0700 (Thu, 17 Dec 2009) | 2 lines


Update to CPLEX baselines

........

r2034 | jwatson | 2009-12-22 21:08:24 -0700 (Tue, 22 Dec 2009) | 3 lines


Added ability to write the mipgap attribute (if not None) to the solver script file for CPLEX and GLPK. I haven't incorporated the ability for CBC or PICO, but that is simply because I'm being lazy and haven't figured out the corresponding solver option (assuming it exists). For these latter plugins, I raise an exception, warning that the mipgap write capability is not currently implemented.

........

r2040 | jwatson | 2009-12-23 16:57:51 -0700 (Wed, 23 Dec 2009) | 3 lines


Adding transmission of solver mipgap across the Pyro distributed solver interface.

........

r2042 | jwatson | 2009-12-23 21:00:15 -0700 (Wed, 23 Dec 2009) | 3 lines


Update of Pyro solver manager to propagate warm-start files to pyro_mip_servers. This currently only works for CPLEX, because CPLEX is currently the only solver plug-in that supports warm-starts.

........

r2048 | wehart | 2009-12-26 17:06:03 -0700 (Sat, 26 Dec 2009) | 4 lines


Reworking MIP plugins to more selectively print
branch-and-bound information. Don't print
this info unless solving a MIP.

........

r2065 | jwatson | 2009-12-29 18:39:54 -0700 (Tue, 29 Dec 2009) | 3 lines


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

........

Location:
coopr.plugins/stable/2.1
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • coopr.plugins/stable/2.1

  • coopr.plugins/stable/2.1/coopr/plugins/mip/CBC.py

    r1950 r2071  
    112112        # Define command line
    113113        #
     114        if (self.mipgap is not None):
     115           raise ValueError, "The mipgap parameter is currently not being processed by CBC solver plugin"
     116       
    114117        if self._problem_format == ProblemFormat.nl:
    115118            if self._timelimit is not None and self._timelimit > 0.0:
     
    153156        # Initial values
    154157        #
    155         results.solver.statistics.branch_and_bound.number_of_created_subproblems=0
    156         results.solver.statistics.branch_and_bound.number_of_bounded_subproblems=0
     158        #results.solver.statistics.branch_and_bound.number_of_created_subproblems=0
     159        #results.solver.statistics.branch_and_bound.number_of_bounded_subproblems=0
    157160        soln = results.solution.add()
    158161        soln.objective['f'].value=float('inf')
     
    288291             constraint_dual = eval(tokens[3])
    289292
    290              # assume that CBC has taken care of rounding - we report any
    291              # dual value not precisely equal to 0.0.
    292              if constraint_dual != 0:
    293                 solution.constraint[constraint].dual = constraint_dual
     293             solution.constraint[constraint].dual = constraint_dual
    294294
    295295          elif processing_constraints is False:
    296              variable = tokens[1]
     296             variable_name = tokens[1]
    297297             variable_value = eval(tokens[2])
    298298             variable_reduced_cost = eval(tokens[3]) # currently ignored.
    299299
    300              # assume that CBC has taken care of rounding - we report any
    301              # variable value not precisely equal to 0.0.
    302              if variable_value != 0:
    303                 solution.variable[variable].value = variable_value
     300             solution.variable[variable_name].value = variable_value
     301             solution.variable[variable_name].rc = variable_reduced_cost
    304302          else:
    305303             raise RuntimeError, "CBC encountered unexpected line=("+line.strip()+") in solution file="+self.soln_file+"; expecting header, but found data!"
  • coopr.plugins/stable/2.1/coopr/plugins/mip/CPLEX.py

    r1971 r2071  
    1515from coopr.opt.results import *
    1616from coopr.opt.solver import *
     17from coopr.pyomo.base.var import *
    1718import mockmip
    1819import pyutilib.services
     
    4243        self.cplex_script_file_name = None
    4344
     45        # NOTE: eventually both of the following attributes should be migrated to a common base class.
    4446        # is the current solve warm-started? a transient data member to communicate state information
    4547        # across the _presolve, _apply_solver, and _postsolve methods.
    4648        self.warm_start_solve = False
    4749        # related to the above, the temporary name of the MST warm-start file (if any).
    48         self.mst_file_name = None
     50        self.warm_start_file_name = None
    4951
    5052        #
     
    6567       from coopr.pyomo.base.set_types import IntegerSet, BooleanSet
    6668
    67        for variable in instance._component[coopr.pyomo.base.var._VarBase].values():
     69       for variable in instance.active_components(Var).values():
    6870
    6971           if (isinstance(variable.domain, IntegerSet) is True) or (isinstance(variable.domain, BooleanSet) is True):
     
    7476
    7577    #
     78    # CPLEX has a simple, easy-to-use warm-start capability.
     79    #
     80    def warm_start_capable(self):
     81       return True
     82
     83    #
    7684    # write a warm-start file in the CPLEX MST format.
    7785    #
     
    8088       import coopr.pyomo.base.var
    8189
    82        self.mst_file_name = pyutilib.services.TempfileManager.create_tempfile(suffix = '.cplex.mst')
     90       self.warm_start_file_name = pyutilib.services.TempfileManager.create_tempfile(suffix = '.cplex.mst')
    8391
    8492       doc = xml.dom.minidom.Document()
     
    102110       # depending on other options), according to the CPLEX manual.
    103111       output_index = 0
    104        for variable in instance._component[coopr.pyomo.base.var._VarBase].values():
     112       for variable in instance.active_components(Var).values():
    105113
    106114           for index in variable._varval.keys():
     
    120128                   output_index = output_index + 1
    121129
    122        mst_file = open(self.mst_file_name,'w')
     130       mst_file = open(self.warm_start_file_name,'w')
    123131       doc.writexml(mst_file, indent="    ", newl="\n")
    124132       mst_file.close()
     
    188196        if self._timelimit is not None and self._timelimit > 0.0:
    189197            cplex_script_file.write("set timelimit "+`self._timelimit`+"\n")
     198        if (self.mipgap is not None) and (self.mipgap > 0.0):
     199            cplex_script_file.write("set mip tolerances mipgap "+`self.mipgap`+"\n")           
    190200        for key in self.options:
    191201                if key in ['relax_integrality']:
     
    199209
    200210        # if we're dealing with an LP, the MST file will be empty.
    201         if (self.warm_start_solve is True) and (self.mst_file_name is not None):
    202             cplex_script_file.write("read "+self.mst_file_name+"\n")
     211        if (self.warm_start_solve is True) and (self.warm_start_file_name is not None):
     212            cplex_script_file.write("read "+self.warm_start_file_name+"\n")
    203213
    204214        if 'relax_integrality' in self.options:
     
    215225        if self.keepFiles:
    216226           print "Solver script file=" + self.cplex_script_file_name
    217            if (self.warm_start_solve is True) and (self.mst_file_name is not None):
    218               print "Solver warm-start file=" + self.mst_file_name
     227           if (self.warm_start_solve is True) and (self.warm_start_file_name is not None):
     228              print "Solver warm-start file=" + self.warm_start_file_name
    219229
    220230        #
     
    282292           return
    283293
    284         results.solver.statistics.branch_and_bound.number_of_created_subproblems=0
    285         results.solver.statistics.branch_and_bound.number_of_bounded_subproblems=0
    286 
    287294        soln = Solution()
    288295        soln.objective['f'].value=None
    289296        INPUT = open(self.soln_file,"r")
    290297        results.problem.number_of_objectives=1
     298        mip_problem=False
    291299        for line in INPUT:
    292300            line = line.strip()
     
    300308                variable_value = None
    301309                variable_reduced_cost = None
     310                variable_status = None
    302311                for i in range(1,len(tokens)):
    303312                   field_name =  string.strip(tokens[i].split('=')[0])
     
    309318                   elif field_name == "reducedCost":
    310319                      variable_reduced_cost = field_value
     320                   elif field_name == "status":
     321                      variable_status = field_value
    311322
    312323                # skip the "constant-one" variable, used to capture/retain objective offsets in the CPLEX LP format.
    313324                if variable_name != "ONE_VAR_CONSTANT":
     325                   variable = None # cache the solution variable reference, as the getattr is expensive.
    314326                   try:
    315                        soln.variable[variable_name].value = eval(variable_value)
    316                        #print soln.variable[variable_name].value, type(soln.variable[variable_name].value)
     327                       variable = soln.variable[variable_name]
     328                       variable.value = eval(variable_value)
    317329                   except:
    318                        soln.variable[variable_name].value = variable_value
     330                       variable.value = variable_value
    319331                   if not variable_reduced_cost is None:
    320332                        try:
    321                             soln.variable[variable_name].rc = eval(variable_reduced_cost)
     333                            variable.rc = eval(variable_reduced_cost)
     334                            if variable_status is not None:
     335                               if variable_status == "LL":
     336                                  variable.lrc = eval(variable_reduced_cost)
     337                               else:
     338                                  variable.lrc = 0.0
     339                               if variable_status == "UL":
     340                                  variable.urc = eval(variable_reduced_cost)
     341                               else:
     342                                  variable.urc = 0.0
    322343                        except:
    323                             soln.variable[variable_name].rc = variable_reduced_cost
     344                            raise ValueError, "Unexpected reduced-cost value="+str(variable_reduced_cost)+" encountered for variable="+variable_name
    324345            elif tokens[0] == "constraint":
    325346                constraint_name = None
    326347                constraint_dual = None
     348                constaint = None # cache the solution constraint reference, as the getattr is expensive.
    327349                for i in range(1,len(tokens)):
    328350                   field_name =  string.strip(tokens[i].split('=')[0])
     
    330352                   if field_name == "name":
    331353                      constraint_name = field_value
     354                      constraint = soln.constraint[constraint_name]
    332355                   elif field_name == "dual": # for LPs
    333356                      # assumes the name field is first.
    334357                      if eval(field_value) != 0.0:
    335                         soln.constraint[constraint_name].dual = eval(field_value)
     358                        constraint.dual = eval(field_value)
    336359                   elif field_name == "slack": # for MIPs
    337360                      # assumes the name field is first.
    338361                      if eval(field_value) != 0.0:
    339                         soln.constraint[constraint_name].slack = eval(field_value)
     362                        constraint.slack = eval(field_value)
    340363            elif tokens[0].startswith("problemName"):
    341364                filename = (string.strip(tokens[0].split('=')[1])).lstrip("\"").rstrip("\"")
     
    379402                        if "lower_bound" in dir(results.problem):
    380403                            del results.problem.lower_bound
     404                    mip_problem=True
     405            elif tokens[0].startswith("MIPNodes"):
     406                if mip_problem:
     407                    n = eval(string.strip(" ".join(tokens).split('=')[1])).lstrip("\"").rstrip("\"")
     408                    results.solver.statistics.branch_and_bound.number_of_created_subproblems=n
     409                    results.solver.statistics.branch_and_bound.number_of_bounded_subproblems=n
     410
    381411               
    382412        if not results.solver.status is SolverStatus.error:
  • coopr.plugins/stable/2.1/coopr/plugins/mip/GLPK.py

    r1950 r2071  
    7575        else:
    7676           timing = ""
     77        if (self.mipgap is not None) and (self.mipgap > 0.0):
     78           mipgap = " --mipgap "+str(self.mipgap)+" "
     79        else:
     80           mipgap = ""           
    7781        if self._problem_format == ProblemFormat.cpxlp:
    7882            problem=" --cpxlp " + problem_files[0]
     
    8993            else:
    9094                opt += " --"+key+" "+str(self.options[key])
    91         proc = self._timer + " " + executable + opt + " " + timing + " --output " + self.soln_file + problem
     95        proc = self._timer + " " + executable + opt + " " + timing + mipgap + " --output " + self.soln_file + problem
    9296        return pyutilib.misc.Bunch(cmd=proc, log_file=self.log_file, env=None)
    9397
     
    100104        # Initial values
    101105        #
    102         results.solver.statistics.branch_and_bound.number_of_created_subproblems=0
    103         results.solver.statistics.branch_and_bound.number_of_bounded_subproblems=0
     106        #results.solver.statistics.branch_and_bound.number_of_created_subproblems=0
     107        #results.solver.statistics.branch_and_bound.number_of_bounded_subproblems=0
    104108        soln = results.solution.add()
    105109        soln.objective['f']=float('inf')
     
    115119        for line in output.split("\n"):
    116120          tokens = re.split('[ \t]+',line.strip())
    117           #print "LINE:", tokens
    118121          if len(tokens) > 4 and tokens[1] == "objval":
    119122             soln.objective['f'] = tokens[3]
     
    209212
    210213    def process_soln_file(self,results):
    211         lp_solution=False
     214
     215        lp_solution = True # if false, we're dealing with a MIP!
    212216        if not os.path.exists(self.soln_file):
    213217           return
    214218        soln = results.solution(0)
    215219        INPUT = open(self.soln_file,"r")
    216         state=0
    217         results.problem.number_of_objectives=1
     220       
     221        state = 0 # 0=initial header, 1=constraints, 2=variables, -1=done
     222       
     223        results.problem.number_of_objectives = 1
     224       
     225        number_of_constraints_read = 0 # for validation of the total count read and the order
     226        number_of_variables_read = 0
     227        active_constraint_name = "" # constraint names and their value/bounds can be split across multiple lines
     228        active_variable_name = "" # variable names and their value/bounds can be split across multiple lines
     229       
    218230        for line in INPUT:
    219231          tokens = re.split('[ \t]+',line.strip())
    220           ##print "LINE",line,len(tokens)
    221           ##print "TOKENS",tokens
    222           if state==0:
     232
     233          if (len(tokens) == 1) and (len(tokens[0]) == 0):
     234             pass
     235          elif state == 0:
    223236             #
    224237             # Processing initial header
    225238             #
    226239             if len(tokens) == 2 and tokens[0] == "Problem:":
     240                # the problem name may be absent, in which case the "Problem:" line will be skipped.
    227241                results.problem.name = tokens[1]
    228242             elif len(tokens) == 2 and tokens[0] == "Rows:":
    229                 results.problem.number_of_constraints = tokens[1]
    230              elif len(tokens) >= 2 and tokens[0] == "Columns:":
    231                 results.problem.number_of_variables = tokens[1]
     243                results.problem.number_of_constraints = eval(tokens[1])
     244             elif len(tokens) == 2 and tokens[0] == "Columns:":
     245                lp_solution = True
     246                results.problem.number_of_variables = eval(tokens[1])
     247             elif len(tokens) > 2 and tokens[0] == "Columns:":
     248                lp_solution = False
     249                results.problem.number_of_variables = eval(tokens[1])               
    232250             elif len(tokens) == 2 and tokens[0] == "Non-zeros:":
    233                 results.problem.number_of_nonzeros = tokens[1]
     251                results.problem.number_of_nonzeros = eval(tokens[1])
    234252             elif len(tokens) >= 2 and tokens[0] == "Status:":
    235253                if tokens[1] == "OPTIMAL":
     
    240258                   soln.status = SolutionStatus.optimal
    241259                elif len(tokens) == 3 and tokens[1] == "INTEGER" and tokens[2] == "UNDEFINED":
    242                    soln.status = SolutionStatus.unbounded                   
     260                   soln.status = SolutionStatus.stoppedByLimit
    243261                else:
    244262                   print "GLPK WARNING: unknown status: "+" ".join(tokens[1:])
     
    258276                        if "lower_bound" in dir(results.problem):
    259277                            del results.problem.lower_bound
    260              elif len(tokens) > 1 and tokens[0] == "No.":
    261                 if tokens[1] == "Row":
    262                    state=1
    263                 else:
    264                    state=2
    265           elif state==1:
     278                # the objective is the last entry in the problem section - move on to constraints.
     279                state = 1
     280
     281          elif state == 1:
    266282             #
    267283             # Process Constraint Info
    268284             #
    269              if len(tokens) == 0:
    270                 continue
    271              if len(tokens) > 1 and tokens[0] == "No.":
    272                 state=2
    273                 if line[65:78].strip() == "Marginal":
    274                    lp_solution=True
     285             
     286             if (len(tokens) == 2) and (len(active_constraint_name) == 0):
     287
     288                number_of_constraints_read = number_of_constraints_read + 1
     289                active_constraint_name = tokens[1].strip()
     290                index = eval(tokens[0].strip())
     291
     292                # sanity check - the indices should be in sequence.
     293                if index != number_of_constraints_read:
     294                   raise ValueError,"***ERROR: Unexpected constraint index encountered on line="+line+"; expected value="+str(number_of_constraints_read)+"; actual value="+str(index)
     295
    275296             else:
    276                 tmp=line[0:6]
    277                 tmp = tmp.strip()
    278                 if tmp == "------":
     297
     298                index = None
     299                activity = None
     300                lower_bound = None
     301                upper_bound = None
     302                marginal = None
     303
     304                # extract the field names and process accordingly. there
     305                # is some wasted processing w.r.t. single versus double-line
     306                # entries, but it's not significant enough to worry about.               
     307                 
     308                index_string = line[0:6].strip()
     309                name_string = line[7:19].strip()
     310                activity_string = line[23:36].strip()
     311                lower_bound_string = line[37:50].strip()
     312                upper_bound_string = line[51:64].strip()
     313
     314                state_string = None               
     315                marginal_string = None
     316
     317                # skip any headers
     318                if (index_string == "------") or (index_string == "No."):
    279319                   continue
    280                 if tmp != "":
    281                    tmpname = tokens[1]
    282                    if len(tokens) == 2:
    283                       continue
    284                 tmp=line[65:78]
    285                 tmp=tmp.strip()
    286                 ##print "HERE",tmp
    287                 if tmp=="":
    288                    if lp_solution:
    289                       soln.dual.add( tmpname,0.0 )
    290                 else:
    291                    if tmp.strip() == "< eps":
    292                       soln.constraint[tmpname].dual = 0.0
    293                    else:
    294                       soln.constraint[tmpname].dual = eval(tmp)
    295           elif state==2:
     320
     321                if len(index_string) > 0:
     322                   index = eval(index_string)               
     323
     324                if lp_solution is True:
     325                   state_string = line[20:22].strip()
     326                   marginal_string = line[65:78].strip()
     327                   if (activity_string != "< eps") and (len(activity_string) > 0):
     328                      activity = eval(activity_string)
     329                   else:
     330                      activity = 0.0
     331                   if (lower_bound_string != "< eps") and (len(lower_bound_string) > 0):
     332                      lower_bound = eval(lower_bound_string)
     333                   else:
     334                      lower_bound = 0.0
     335                   if state_string != "NS":                   
     336                      if (upper_bound_string != "< eps") and (len(upper_bound_string) > 0):
     337                         upper_bound = eval(upper_bound_string)
     338                      else:
     339                         upper_bound = 0.0
     340                   if (marginal_string != "< eps") and (len(marginal_string) > 0):
     341                      marginal = eval(marginal_string)
     342                   else:
     343                      marginal = 0.0
     344
     345                else:
     346                    # no constraint-related attributes/values are extracted currently for MIPs.
     347                    pass
     348               
     349                constraint_name = None
     350                if len(active_constraint_name) > 0:
     351                   # if there is an active constraint name, the identifier was
     352                   # too long for everything to be on a single line; the second
     353                   # line contains all of the value information.                   
     354                   constraint_name = active_constraint_name
     355                   active_constraint_name = ""
     356                else:
     357                   # everything is on a single line.
     358                   constraint_name = name_string
     359                   number_of_constraints_read = number_of_constraints_read + 1
     360                   # sanity check - the indices should be in sequence.
     361                   if index != number_of_constraints_read:
     362                      raise ValueError,"***ERROR: Unexpected constraint index encountered on line="+line+"; expected value="+str(number_of_constraints_read)+"; actual value="+str(index)
     363
     364                if lp_solution is True:
     365                   # GLPK doesn't report slacks directly.
     366                   constraint_dual = activity
     367                   if state_string == "B":
     368                      constraint_dual = 0.0
     369                   elif (state_string == "NS") or (state_string == "NL") or (state_string == "NU"):
     370                      constraint_dual = marginal
     371                   else:
     372                      raise ValueError, "Unknown status="+tokens[0]+" encountered for constraint="+active_constraint_name+" in line="+line+" of solution file="+self.soln_file
     373
     374                   soln.constraint[constraint_name].dual = constraint_dual
     375                 
     376                else:
     377                   # there isn't anything interesting to do with constraints in the MIP case.
     378                   pass
     379
     380                # if all of the constraints have been read, exit.
     381                if number_of_constraints_read == results.problem.number_of_constraints:
     382                   state = 2
     383                     
     384          elif state == 2:
    296385             #
    297386             # Process Variable Info
    298387             #
    299              if len(tokens) == 1:
    300                 state=-1
    301                 continue
    302              if True:
    303                 tmp=line[0:6]
    304                 tmp = tmp.strip()
    305                 if tmp == "------":
     388
     389             if (len(tokens) == 2) and (len(active_variable_name) == 0):
     390                 
     391                # in the case of name over-flow, there are only two tokens
     392                # on the first of two lines for the variable entry.
     393                number_of_variables_read = number_of_variables_read + 1
     394                active_variable_name = tokens[1].strip()
     395                index = eval(tokens[0].strip())
     396
     397                # sanity check - the indices should be in sequence.
     398                if index != number_of_variables_read:
     399                   raise ValueError,"***ERROR: Unexpected variable index encountered on line="+line+"; expected value="+str(number_of_variables_read)+"; actual value="+str(index)                   
     400               
     401             else:
     402                 
     403                index = None
     404                activity = None
     405                lower_bound = None
     406                upper_bound = None
     407                marginal = None
     408
     409                # extract the field names and process accordingly. there
     410                # is some wasted processing w.r.t. single versus double-line
     411                # entries, but it's not significant enough to worry about.
     412
     413                index_string = line[0:6].strip()
     414                name_string = line[7:19].strip()
     415                activity_string = line[23:36].strip()
     416                lower_bound_string = line[37:50].strip()
     417                upper_bound_string = line[51:64].strip()
     418
     419                state_string = None
     420                marginal_string = None
     421
     422                # skip any headers
     423                if (index_string == "------") or (index_string == "No."):
    306424                   continue
    307                 if tmp != "":
    308                    tmpname = tokens[1]
    309                    if len(tokens) == 2:
    310                       continue
    311                 tmp=line[23:36]
    312                 tmp=tmp.strip()
    313                 if tmp=="":
    314                    soln.variable[tmpname].value = 0.0
    315                 else:
    316                    soln.variable[tmpname].value = eval(tmp)
     425
     426                if len(index_string) > 0:
     427                   index = eval(index_string)
     428
     429                if lp_solution is True:
     430                   state_string = line[20:22].strip()
     431                   marginal_string = line[65:78].strip()                               
     432
     433                   if (activity_string != "< eps") and (len(activity_string) > 0):
     434                      activity = eval(activity_string)
     435                   else:
     436                      activity = 0.0
     437                   if (lower_bound_string != "< eps") and (len(lower_bound_string) > 0):
     438                      lower_bound = eval(lower_bound_string)
     439                   else:
     440                      lower_bound = 0.0
     441                   if state_string != "NS":                   
     442                      if (upper_bound_string != "< eps") and (len(upper_bound_string) > 0):
     443                         upper_bound = eval(upper_bound_string)
     444                      else:
     445                         upper_bound = 0.0
     446                   if (marginal_string != "< eps") and (len(marginal_string) > 0):
     447                      marginal = eval(marginal_string)
     448                   else:
     449                      marginal = 0.0
     450
     451                else:
     452
     453                   if (activity_string != "< eps") and (len(activity_string) > 0):
     454                      activity = eval(activity_string)
     455                   else:
     456                      activity = 0.0                   
     457
     458                variable_name = None
     459                if len(active_variable_name) > 0:
     460                   # if there is an active variable name, the identifier was
     461                   # too long for everything to be on a single line; the second
     462                   # line contains all of the value information.
     463                   variable_name = active_variable_name
     464                   active_variable_name = ""
     465                else:
     466                   # everything is on a single line.
     467                   variable_name = name_string
     468                   number_of_variables_read = number_of_variables_read + 1
     469                   # sanity check - the indices should be in sequence.
     470                   if index != number_of_variables_read:
     471                      raise ValueError,"***ERROR: Unexpected variable index encountered on line="+line+"; expected value="+str(number_of_variables_read)+"; actual value="+str(index)
     472
     473                if lp_solution is True:
     474                   # the "activity" column always specifies the variable value.
     475                   # embedding the if-then-else to validate the basis status.
     476                   # we are currently ignoring all bound-related information.
     477                   variable_value = None
     478                   if state_string == "B":
     479                      variable_value = activity
     480                   elif (state_string == "NL") or (state_string == "NS") or (state_string == "NU"):
     481                      variable_value = activity
     482                   else:
     483                      raise ValueError, "Unknown status="+state_string+" encountered for variable="+active_variable_name+" in line="+line+" of solution file="+self.soln_file
     484               
     485                   soln.variable[variable_name].value = variable_value
     486                else:
     487                   soln.variable[variable_name].value = activity
     488               
     489             # if all of the variables have been read, exit.
     490             if number_of_variables_read == results.problem.number_of_variables:
     491                state = -1
     492             
    317493          if state==-1:
    318494             break
     495         
    319496        INPUT.close()
    320 
    321 
    322497
    323498class MockGLPK(GLPK,mockmip.MockMIP):
  • coopr.plugins/stable/2.1/coopr/plugins/mip/PICO.py

    r1950 r2071  
    8181        # Define command line
    8282        #
     83        if (self.mipgap is not None):
     84           raise ValueError, "The mipgap parameter is currently not being processed by PICO solver plugin"       
    8385        env=copy.copy(os.environ)
    8486        if self._problem_format is None or self._problem_format == ProblemFormat.nl:
     
    115117        # Initial values
    116118        #
    117         results.solver.statistics.branch_and_bound.number_of_created_subproblems=0
    118         results.solver.statistics.branch_and_bound.number_of_bounded_subproblems=0
     119        #results.solver.statistics.branch_and_bound.number_of_created_subproblems=0
     120        #results.solver.statistics.branch_and_bound.number_of_bounded_subproblems=0
    119121        soln = results.solution.add()
    120122        soln.objective['f'].value = None
  • coopr.plugins/stable/2.1/coopr/plugins/smanager/pyro.py

    r1950 r2071  
    5656        kwds['available'] = True
    5757        self._opt._presolve(*args, **kwds)
    58         filestr = open(self._opt._problem_files[0],'r').read()
     58        problem_file_string = open(self._opt._problem_files[0],'r').read()
    5959
    6060        #
     
    7272           solver_options[key]=self._opt.options[key]
    7373
     74        # pick up the warm-start file, if available.
     75        warm_start_file_string = None
     76        warm_start_file_name = None
     77        if hasattr(self._opt,  "warm_start_solve"):
     78           if (self._opt.warm_start_solve is True) and (self._opt.warm_start_file_name is not None):
     79              warm_start_file_name = self._opt.warm_start_file_name
     80              warm_start_file_string = open(warm_start_file_name, 'r').read()
     81
    7482        #
    7583        # Pickl everything into one big data object via the "Bunch" command
    7684        # and post the task!
    7785        #
    78         data=pyutilib.misc.Bunch(opt=self._opt.type, file=filestr, filename=self._opt._problem_files[0], kwds=kwds, solver_options=solver_options)
     86        data=pyutilib.misc.Bunch(opt=self._opt.type, \
     87                                 file=problem_file_string, filename=self._opt._problem_files[0], \
     88                                 warmstart_file=warm_start_file_string, warmstart_filename=warm_start_file_name, \
     89                                 kwds=kwds, solver_options=solver_options, mipgap=self._opt.mipgap)
    7990        task = pyutilib.pyro.Task(data=data, id=ah.id)
    8091        self.client.add_task(task)
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/diet_glpk.txt

    r1950 r2071  
    2222- Status: ok
    2323  Termination condition: unsure
    24   Statistics:
    25     Branch and bound:
    26       Number of bounded subproblems: 0
    27       Number of created subproblems: 0
    2824  Error rc: 0
    2925
     
    4642  Constraint:
    4743    Diet[B2]:
    48       Id: 0
     44      Id: 3
    4945      Dual: 0.126
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test1_cbc.txt

    r1950 r2071  
    2222- Status: ok
    2323  Termination condition: unsure
    24   Statistics:
    25     Branch and bound:
    26       Number of bounded subproblems: 0
    27       Number of created subproblems: 0
    2824  Error rc: 0
    2925
     
    4440      Id: 0
    4541      Value: 1
     42    X12:
     43      Id: 1
     44      Rc: 1
     45    X13:
     46      Id: 2
     47      Rc: 2
     48    X21:
     49      Id: 3
     50      Rc: 1
     51    X22:
     52      Id: 4
     53      Rc: 2
    4654    X23:
    47       Id: 1
     55      Id: 5
    4856      Value: 1
     57    X31:
     58      Id: 6
     59      Rc: 2
    4960    X32:
    50       Id: 2
     61      Id: 7
    5162      Value: 1
     63    X33:
     64      Id: 8
     65      Rc: 1
    5266  Constraint:
    5367    NODEA1:
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test1_cplex.txt

    r1971 r2071  
    2222- Status: ok
    2323  Termination condition: unsure
    24   Statistics:
    25     Branch and bound:
    26       Number of bounded subproblems: 0
    27       Number of created subproblems: 0
    2824  Error rc: 0
    2925
     
    4743      Id: 1
    4844      Rc: 1
     45      Lrc: 1
    4946    X13:
    5047      Id: 2
    5148      Rc: 2
     49      Lrc: 2
    5250    X21:
    5351      Id: 3
    5452      Rc: 1
     53      Lrc: 1
    5554    X22:
    5655      Id: 4
    5756      Rc: 2
     57      Lrc: 2
    5858    X23:
    5959      Id: 5
     
    6262      Id: 6
    6363      Rc: 2
     64      Lrc: 2
    6465    X32:
    6566      Id: 7
     
    6869      Id: 8
    6970      Rc: 1
     71      Lrc: 1
    7072  Constraint:
    7173    NODEA1:
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test1_glpk.txt

    r1950 r2071  
    2222- Status: ok
    2323  Termination condition: unsure
    24   Statistics:
    25     Branch and bound:
    26       Number of bounded subproblems: 0
    27       Number of created subproblems: 0
    2824  Error rc: 0
    2925
     
    5248  Constraint:
    5349    NODEA1:
    54       Id: 0
     50      Id: 1
    5551      Dual: 1
    5652    NODEA2:
    57       Id: 1
     53      Id: 2
    5854      Dual: 1
    5955    NODEA3:
    60       Id: 2
     56      Id: 3
    6157      Dual: 2
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test1_pico.txt

    r1950 r2071  
    2323- Status: ok
    2424  Termination condition: unsure
    25   Statistics:
    26     Branch and bound:
    27       Number of bounded subproblems: 0
    28       Number of created subproblems: 0
    2925  Error rc: 0
    3026
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test2_cbc.txt

    r1950 r2071  
    4141      Value: 2
    4242  Variable:
     43    x1:
     44      Id: 0
     45      Rc: 1
    4346    x2:
    44       Id: 0
     47      Id: 1
    4548      Value: 1
     49      Rc: -2
     50  Constraint: No nonzero values
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test4_cbc.txt

    r1950 r2071  
    2323  Message: Cbc 1.04 optimal, objective 9e+01; 1 iterations
    2424  Termination condition: unsure
    25   Statistics:
    26     Branch and bound:
    27       Number of bounded subproblems: 0
    28       Number of created subproblems: 0
    2925  Id: 0
    3026  Error rc: 0
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test4_cplex.txt

    r1971 r2071  
    2222- Status: ok
    2323  Termination condition: unsure
    24   Statistics:
    25     Branch and bound:
    26       Number of bounded subproblems: 0
    27       Number of created subproblems: 0
    2824  Error rc: 0
    2925
     
    4440      Id: 0
    4541      Rc: 1.3
     42      Lrc: 1.3
    4643    x1:
    4744      Id: 1
    4845      Rc: 0.07
     46      Lrc: 0.07
    4947    x2:
    5048      Id: 2
    5149      Rc: 1.03
     50      Lrc: 1.03
    5251    x3:
    5352      Id: 3
    5453      Rc: 1.63
     54      Lrc: 1.63
    5555    x4:
    5656      Id: 4
     
    5959      Id: 5
    6060      Rc: 0.1
     61      Lrc: 0.1
    6162    x6:
    6263      Id: 6
    6364      Rc: 0.1
     65      Lrc: 0.1
    6466    x7:
    6567      Id: 7
    6668      Rc: 1.23
     69      Lrc: 1.23
    6770  Constraint:
    6871    cons0:
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test4_glpk.txt

    r1950 r2071  
    2121- Status: ok
    2222  Termination condition: unsure
    23   Statistics:
    24     Branch and bound:
    25       Number of bounded subproblems: 0
    26       Number of created subproblems: 0
    2723  Error rc: 0
    2824
     
    4541  Constraint:
    4642    cons2:
    47       Id: 0
     43      Id: 2
    4844      Dual: 0.126
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test4_pico.txt

    r1950 r2071  
    2323  Message: PICO Solver\x3a final f = 88.578000
    2424  Termination condition: unsure
    25   Statistics:
    26     Branch and bound:
    27       Number of bounded subproblems: 0
    28       Number of created subproblems: 0
    2925  Id: 0
    3026  Error rc: 0
  • coopr.plugins/stable/2.1/coopr/plugins/tests/mip/test_cplex.py

    r1950 r2071  
    8585    def test_solve3(self):
    8686        """ Test CPLEX - test2.lp """
    87         results = self.cplex.solve(currdir+"test2.lp", logfile=currdir+"test_solve3.log")
     87        results = self.cplex.solve(currdir+"test2.lp", logfile=currdir+"test_solve3.log", keepFiles=True)
    8888        results.write(filename=currdir+"test_solve3.txt",times=False)
    8989        self.failUnlessFileEqualsBaseline(currdir+"test_solve3.txt", currdir+"test2_cplex.txt")
  • coopr.plugins/stable/2.1/setup.py

    r1950 r2071  
    6161            'Programming Language :: Unix Shell',
    6262            'Topic :: Scientific/Engineering :: Mathematics',
    63             'Topic :: Software Development :: Libraries :: Python Modules'
     63            'Topic :: Software Development :: Libraries :: Python Modules',
     64            'Topic :: Scientific/Engineering'
    6465        ],
    6566      packages=packages,
Note: See TracChangeset for help on using the changeset viewer.