Changeset 3284


Ignore:
Timestamp:
Dec 3, 2010 10:55:04 PM (10 years ago)
Author:
wehart
Message:

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

........

r3192 | jwatson | 2010-10-29 11:56:55 -0600 (Fri, 29 Oct 2010) | 3 lines


Changes to propagate the symbol map across the pyro solver manager interface.

........

r3204 | jwatson | 2010-10-29 14:46:39 -0600 (Fri, 29 Oct 2010) | 3 lines


Flushing out MIP warm-start capability for GUROBI plugin.

........

r3241 | wehart | 2010-11-13 01:28:14 -0700 (Sat, 13 Nov 2010) | 2 lines


Further updates to account for updates to coopr.os

........

r3243 | wehart | 2010-11-13 10:42:22 -0700 (Sat, 13 Nov 2010) | 2 lines


Fix for test when coopr.os is not imported.

........

r3249 | jwatson | 2010-11-17 14:34:25 -0700 (Wed, 17 Nov 2010) | 3 lines


Skipping ONE_VAR_CONSTANT variable from GUROBI plugin solution load.

........

r3255 | jwatson | 2010-11-19 13:32:01 -0700 (Fri, 19 Nov 2010) | 3 lines


Fixing bug in GUROBI plugin - was loading constraint duals into the "value" attribute of a ConstraintData? class (as opposed to the "dual" attribute).

........

r3256 | jwatson | 2010-11-19 13:36:54 -0700 (Fri, 19 Nov 2010) | 3 lines


Suppression of dual value reporting for constant constraint.

........

r3270 | wehart | 2010-12-01 15:29:41 -0700 (Wed, 01 Dec 2010) | 2 lines


Adding filter for the 'Message:' line.

........

r3273 | jwatson | 2010-12-02 14:56:00 -0700 (Thu, 02 Dec 2010) | 3 lines


Correcting condition under which constraint duals are extracted by the GUROBI plugin. We previously used binary and integer variable counts, which is insufficient if SOS constraints are in the model. Fortunately, you can avoid all of this mess by checking the Gurobi "IsMIP" attribute.

........

r3277 | jwatson | 2010-12-03 19:25:03 -0700 (Fri, 03 Dec 2010) | 3 lines


Fixing issue with CPLEX direct interface - logic for deregistration was not valid if the import of the cplex python module failed.

........

Location:
coopr.plugins/stable
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • coopr.plugins/stable

  • coopr.plugins/stable/coopr/plugins/mip/CPLEXDirect.py

    r3113 r3284  
    790790
    791791
    792 if cplex_import_available:
    793     OptSolverFactory().deactivate('cplexdirect')
    794     OptSolverFactory().deactivate('_mock_cplexdirect')
    795 
     792if cplex_import_available is False:
     793   SolverFactory().deactivate('cplexdirect')
     794   SolverFactory().deactivate('_mock_cplexdirect')
     795
  • coopr.plugins/stable/coopr/plugins/mip/GUROBI.py

    r3178 r3284  
    6868        self._capabilities.sos2 = True
    6969
     70    def warm_start_capable(self):
     71
     72       return True
     73
    7074    #
    71     # GUROBI warm-start capability is not implemented
     75    # write a warm-start file in the GUROBI MST format, which is *not* the same as the CPLEX MST format.
    7276    #
    73     def warm_start_capable(self):
    74 
    75        return False
     77    def warm_start(self, instance):
     78
     79       self.warm_start_file_name = pyutilib.services.TempfileManager.create_tempfile(suffix = '.gurobi.mst')
     80
     81       mst_file = open(self.warm_start_file_name,'w')
     82
     83       # for each variable, add a child to the variables element.
     84       # both continuous and discrete are accepted (and required,
     85       # depending on other options), according to the CPLEX manual.
     86       for variable in instance.active_components(Var).values():
     87
     88          for index in variable._varval.keys():
     89
     90             if (variable[index].status != VarStatus.unused) and (variable[index].value != None) and (variable[index].fixed == False):
     91
     92                name = variable[index].label
     93                name = name.replace('[','(')
     94                name = name.replace(']',')')
     95                print >>mst_file, name, variable[index].value
     96
     97       mst_file.close()
     98
     99    # over-ride presolve to extract the warm-start keyword, if specified.
     100    def _presolve(self, *args, **kwds):
     101
     102       # if the first argument is a string (representing a filename),
     103       # then we don't have an instance => the solver is being applied
     104       # to a file.
     105
     106       self.warm_start_solve = False               
     107       if "warmstart" in kwds:
     108          self.warm_start_solve = kwds["warmstart"]
     109          del kwds["warmstart"]
     110
     111       if (len(args) > 0) and (isinstance(args[0],basestring) is False):
     112
     113          # write the warm-start file - currently only supports MIPs.
     114          # we only know how to deal with a single problem instance.       
     115          if self.warm_start_solve is True:
     116
     117             if len(args) != 1:
     118                raise ValueError, "GUROBI _presolve method can only handle a single problem instance - "+str(len(args))+" were supplied"                 
     119
     120             if args[0].has_discrete_variables() is True:
     121                start_time = time.time()
     122                self.warm_start(args[0])
     123                end_time = time.time()
     124                if self._report_timing is True:
     125                   print "Warm start write time="+str(end_time-start_time)+" seconds"
     126         
     127       # let the base class handle any remaining keywords/actions.
     128       ILMLicensedSystemCallSolver._presolve(self, *args, **kwds)
    76129
    77130    def executable(self):
     
    108161        problem_filename = self._problem_files[0]
    109162        solution_filename = self.soln_file
     163        warmstart_filename = self.warm_start_file_name
    110164        if sys.platform == 'win32':
    111165           problem_filename  = problem_filename.replace('\\', r'\\')
    112166           solution_filename = solution_filename.replace('\\', r'\\')
     167           if self.warm_start is True:
     168              warmstart_filename = warmstart_filename.replace('\\', r'\\')
    113169
    114170        # translate the options into a normal python dictionary, from a
     
    127183        script += "sys.path.append('%s')\n" % os.path.dirname(__file__)
    128184        script += "from GUROBI_RUN import *\n"
    129         script += "gurobi_run%s\n" % str((problem_filename, solution_filename, self.mipgap, options_dict))
     185        script += "gurobi_run%s\n" % str((problem_filename, warmstart_filename, solution_filename, self.mipgap, options_dict))
    130186        script += "quit()\n"
    131187
     
    139195        if self.keepFiles:
    140196           print "Solver script file: '%s'" % self.gurobi_script_file_name
     197           if (self.warm_start_solve is True) and (self.warm_start_file_name is not None):
     198              print "Solver warm-start file: " + self.warm_start_file_name
    141199
    142200        #
     
    197255                        soln.objective['f'].vale=eval(tokens[1])
    198256                    elif (tokens[0] == 'constraint'):
    199                         soln_constraints[tokens[1]].value = eval(tokens[2])
     257                       if tokens[1] != "c_e_ONE_VAR_CONSTANT":
     258                           soln_constraints[tokens[1]].dual = eval(tokens[2])
    200259                    elif (tokens[0] == 'variable'):
    201                         soln_variables[tokens[1]].value = eval(tokens[2])
     260                       if tokens[1] != "ONE_VAR_CONSTANT":
     261                         soln_variables[tokens[1]].value = eval(tokens[2])
    202262                    else:
    203263                        setattr(soln, tokens[0], tokens[1])
  • coopr.plugins/stable/coopr/plugins/mip/GUROBI_RUN.py

    r3178 r3284  
    1212from gurobipy import *
    1313
    14 def gurobi_run(model_file, soln_file, mipgap, options):
     14def gurobi_run(model_file, warmstart_file, soln_file, mipgap, options):
    1515
    1616    # Load the lp model
    1717    model = read(model_file)
     18
     19    if warmstart_file is not None:
     20       model.read(warmstart_file)
    1821
    1922    # set the mipgap if specified.
     
    154157
    155158    is_discrete = False
    156     if (model.getAttr(GRB.Attr.NumBinVars) > 0) or (model.getAttr(GRB.Attr.NumIntVars) > 0):
     159    if (model.getAttr(GRB.Attr.IsMIP)):
    157160       is_discrete = True
    158161
     
    170173        if is_discrete is False:
    171174           for con in cons:
     175               # Pi attributes in Gurobi are the constraint duals
    172176               print >>solnfile, "constraint:",con.getAttr(GRB.Attr.ConstrName),":",con.getAttr(GRB.Attr.Pi)
    173177
  • coopr.plugins/stable/coopr/plugins/smanager/pyro.py

    r2593 r3284  
    9292                                 file=problem_file_string, filename=self._opt._problem_files[0], \
    9393                                 warmstart_file=warm_start_file_string, warmstart_filename=warm_start_file_name, \
    94                                  kwds=kwds, solver_options=solver_options, mipgap=self._opt.mipgap, suffixes=self._opt.suffixes)
     94                                 kwds=kwds, solver_options=solver_options, mipgap=self._opt.mipgap, suffixes=self._opt.suffixes, symbol_map=self._opt._symbol_map)
    9595        task = pyutilib.pyro.Task(data=data, id=ah.id)
    9696        self.client.add_task(task)
  • coopr.plugins/stable/coopr/plugins/tests/mip/test_asl.py

    r2429 r3284  
    3434    pico_convert_available=False
    3535
     36
     37def filter_cplex(line):
     38    return line.startswith("Message:")
    3639
    3740class mock_all(unittest.TestCase):
     
    98101            results = self.asl.solve(currdir+"test4.nl", logfile=currdir+"test_solve4.log")
    99102            results.write(filename=currdir+"test_solve4.txt",times=False)
    100             self.failUnlessFileEqualsBaseline(currdir+"test_solve4.txt", currdir+"test4_asl.txt")
     103            self.failUnlessFileEqualsBaseline(currdir+"test_solve4.txt", currdir+"test4_asl.txt", filter=filter_cplex)
    101104        else:
    102105            try:
  • coopr.plugins/stable/coopr/plugins/tests/mip/test_factory.py

    r2593 r3284  
    126126        ans = coopr.opt.ReaderFactory.services()
    127127        #self.failUnlessEqual(len(ans),4)
    128         self.failUnless(set(ans) >= set(["osrl","rtest3", "sol","yaml"]))
     128        self.failUnless(set(ans) >= set(["rtest3", "sol","yaml"]))
    129129
    130130    def test_reader_instance(self):
     
    134134        ans = coopr.opt.ReaderFactory("none")
    135135        self.failUnlessEqual(ans, None)
    136         ans = coopr.opt.ReaderFactory("osrl")
    137         self.failUnlessEqual(type(ans), coopr.opt.reader.OS.ResultsReader_osrl)
     136        ans = coopr.opt.ReaderFactory("sol")
     137        self.failUnlessEqual(type(ans), coopr.opt.reader.sol.ResultsReader_sol)
    138138        #ans = coopr.opt.ReaderFactory("osrl", "myreader")
    139139        #self.failUnlessEqual(type(ans), coopr.opt.reader.OS.ResultsReader_osrl)
  • coopr.plugins/stable/setup.py

    r3180 r3284  
    8080            'solver.asl = coopr.plugins.mip.ASL',
    8181            'solver.gurobi = coopr.plugins.mip.GUROBI',
    82             'testdriver.coopr.mip = coopr.plugins.testdriver.mip.CooprMIPTestDriver',
     82            'testdriver.coopr.mip = coopr.plugins.testdriver.mip',
    8383        ],
    8484        'coopr.pyomo': [
    85             'testdriver.coopr.pyomo = coopr.plugins.testdriver.pyomo.PyomoTestDriver',
     85            'testdriver.coopr.pyomo = coopr.plugins.testdriver.pyomo',
    8686        ]
    8787      }
Note: See TracChangeset for help on using the changeset viewer.