Changeset 3079


Ignore:
Timestamp:
Oct 11, 2010 11:54:31 AM (11 years ago)
Author:
jwatson
Message:

Improvements to GUROBI plug-in to allow execution on windows and linux, and eliminated Coopr module import dependencies on claird home diretory existence and accessibility :)

File:
1 edited

Legend:

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

    r2664 r3079  
    1010
    1111import os
     12import sys
    1213import re
    1314from coopr.opt.base import *
     
    2728import time
    2829
    29 # TODO: CHECK IF IT IS ILMLicensedSystemCallSolver
    3030class GUROBI(ILMLicensedSystemCallSolver):
    3131    """The GUROBI LP/MIP solver
     
    6363        self._capabilities = pyutilib.misc.Options()
    6464        self._capabilities.linear = True
     65        self._capabilities.quadratic = True       
    6566        self._capabilities.integer = True
     67        self._capabilities.sos1 = True
     68        self._capabilities.sos2 = True       
    6669
    6770    #
     
    6972    #
    7073    def warm_start_capable(self):
     74
    7175       return False
    7276
    7377    def executable(self):
    74         executable = pyutilib.services.registered_executable("gurobi.sh")
     78       
     79        if sys.platform == "win32":
     80           executable = pyutilib.services.registered_executable("gurobi.bat")
     81        else:
     82           executable = pyutilib.services.registered_executable("gurobi.sh")           
    7583        if executable is None:
    7684            pyutilib.component.core.PluginGlobals.env().log.error("Could not locate the 'gurobi' executable, which is required for solver %s" % self.name)
     
    8088
    8189    def create_command_line(self,executable,problem_files):
     90
    8291        #
    8392        # Define log file
     
    96105        # Write the GUROBI execution script
    97106        #
     107
     108        # NOTE: the gurobi shell is independent of Coopr python virtualized environment, so any
     109        #       imports - specifically that required to get GUROBI_RUN - must be handled explicitly.
    98110        self.gurobi_script_file_name = pyutilib.services.TempfileManager.create_tempfile(suffix = '.gurobi.script')
    99111        gurobi_script_file = open(self.gurobi_script_file_name,'w')
    100112        gurobi_script_file.write("import sys\n")
    101113        gurobi_script_file.write("from gurobipy import *\n")
    102         gurobi_script_file.write("sys.path.append(\'/home/claird/Research/CooprWork/coopr/src/coopr.plugins/coopr/plugins/mip\')\n")
     114        # NOTE: The gurobi plugin and GUROBI_RUN.py live in the same directory.
     115        gurobi_script_file.write("sys.path.append("+"\""+os.path.dirname(__file__)+"\""+")\n")
    103116        gurobi_script_file.write("from GUROBI_RUN import *\n")
    104117        gurobi_script_file.write("gurobi_run(\""+self._problem_files[0]+"\",\""+self.soln_file+"\")\n")
     
    109122        # user if we're keeping files around.
    110123        if self.keepFiles:
    111            print "Solver script file=" + self.gurobi_script_file_name
     124           print "Solver script file: '%s'" % self.gurobi_script_file_name
    112125
    113126        #
     
    118131
    119132    def process_logfile(self):
     133       
    120134        return ILMLicensedSystemCallSolver.process_logfile(self)
    121135
    122136    def process_soln_file(self,results):
     137       
    123138        # check for existence of the solution file
    124139        # not sure why we just return - would think that we
     
    173188        results.solution.insert(soln)
    174189
    175         # todo:
    176         # is this necessary????
    177 #        return ILMLicensedSystemCallSolver.process_soln_file(self,results)
    178  
    179 pyutilib.services.register_executable(name="gurobi.sh")
     190if sys.platform == "win32":
     191   pyutilib.services.register_executable(name="gurobi.bat")
     192else:
     193   pyutilib.services.register_executable(name="gurobi.sh")
Note: See TracChangeset for help on using the changeset viewer.