Changeset 3091


Ignore:
Timestamp:
Oct 13, 2010 2:02:57 PM (11 years ago)
Author:
khunter
Message:

Refactor to be clearer about what's being written, and write but once.

File:
1 edited

Legend:

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

    r3090 r3091  
    106106        #
    107107
    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.
    110         self.gurobi_script_file_name = pyutilib.services.TempfileManager.create_tempfile(suffix = '.gurobi.script')
    111         gurobi_script_file = open(self.gurobi_script_file_name,'w')
    112         gurobi_script_file.write("import sys\n")
    113         gurobi_script_file.write("from gurobipy import *\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")
    116         gurobi_script_file.write("from GUROBI_RUN import *\n")
    117108        problem_filename = self._problem_files[0]
    118109        solution_filename = self.soln_file
     
    121112           solution_filename = solution_filename.replace('\\', r'\\')
    122113
    123         gurobi_script_file.write("gurobi_run%s\n" % str((problem_filename, solution_filename)))
    124         gurobi_script_file.write("quit()\n")
     114        # NOTE: the gurobi shell is independent of Coopr python virtualized environment, so any
     115        #       imports - specifically that required to get GUROBI_RUN - must be handled explicitly.
     116        # NOTE: The gurobi plugin and GUROBI_RUN.py live in the same directory.
     117        script  = "import sys\n"
     118        script += "from gurobipy import *\n"
     119        script += "sys.path.append('%s')\n" % os.path.dirname(__file__)
     120        script += "from GUROBI_RUN import *\n"
     121        script += "gurobi_run%s\n" % str((problem_filename, solution_filename))
     122        script += "quit()\n"
     123
     124        self.gurobi_script_file_name = pyutilib.services.TempfileManager.create_tempfile(suffix = '.gurobi.script')
     125        gurobi_script_file = open(self.gurobi_script_file_name, 'w')
     126        gurobi_script_file.write( script )
    125127        gurobi_script_file.close()
    126128
Note: See TracChangeset for help on using the changeset viewer.