def __init__(self, **kwds): # # Call base class constructor # kwds['type'] = 'xpress' ILMLicensedSystemCallSolver.__init__(self, **kwds) self.is_mip = kwds.pop('is_mip', False) # # Define valid problem formats and associated results formats # self._valid_problem_formats = [ProblemFormat.cpxlp, ProblemFormat.mps] self._valid_result_formats = {} self._valid_result_formats[ProblemFormat.cpxlp] = [ResultsFormat.soln] self._valid_result_formats[ProblemFormat.mps] = [ResultsFormat.soln] self.set_problem_format(ProblemFormat.cpxlp) # # Cache the problem type - LP or MIP. Xpress needs to know this # on the command-line, and it matters when reading the solution file. # # Note: Undefined capabilities default to 'None' self._capabilities = Options() self._capabilities.linear = True self._capabilities.quadratic_objective = True self._capabilities.quadratic_constraint = True self._capabilities.integer = True self._capabilities.sos1 = True self._capabilities.sos2 = True
def __init__(self, **kwds): # # Call base class constructor # kwds['type'] = 'cplex' ILMLicensedSystemCallSolver.__init__(self, **kwds) # NOTE: eventually both of the following attributes should be migrated to a common base class. # is the current solve warm-started? a transient data member to communicate state information # across the _presolve, _apply_solver, and _postsolve methods. self._warm_start_solve = False # related to the above, the temporary name of the MST warm-start file (if any). self._warm_start_file_name = None # # Define valid problem formats and associated results formats # self._valid_problem_formats = [ProblemFormat.cpxlp, ProblemFormat.mps] self._valid_result_formats = {} self._valid_result_formats[ProblemFormat.cpxlp] = [ResultsFormat.soln] self._valid_result_formats[ProblemFormat.mps] = [ResultsFormat.soln] self.set_problem_format(ProblemFormat.cpxlp) # Note: Undefined capabilities default to 'None' self._capabilities = Options() self._capabilities.linear = True self._capabilities.quadratic_objective = True self._capabilities.quadratic_constraint = True self._capabilities.integer = True self._capabilities.sos1 = True self._capabilities.sos2 = True
def _presolve(self, *args, **kwds): # create a context in the temporary file manager for # this plugin - is "pop"ed in the _postsolve method. TempfileManager.push() # if the first argument is a string (representing a filename), # then we don't have an instance => the solver is being applied # to a file. self._warm_start_solve = kwds.pop('warmstart', False) self._warm_start_file_name = kwds.pop('warmstart_file', None) user_warmstart = False if self._warm_start_file_name is not None: user_warmstart = True # the input argument can currently be one of two things: an # instance or a filename. if a filename is provided and a # warm-start is indicated, we go ahead and create the temporary # file - assuming that the user has already, via some external # mechanism, invoked warm_start() with a instance to create the # warm start file. if self._warm_start_solve and \ isinstance(args[0], str): # we assume the user knows what they are doing... pass elif self._warm_start_solve and \ (not isinstance(args[0], str)): # assign the name of the warm start file *before* calling # the base class presolve - the base class method ends up # creating the command line, and the warm start file-name is # (obviously) needed there. if self._warm_start_file_name is None: assert not user_warmstart self._warm_start_file_name = TempfileManager.create_tempfile( suffix='.gurobi.mst') # let the base class handle any remaining keywords/actions. ILMLicensedSystemCallSolver._presolve(self, *args, **kwds) # NB: we must let the base class presolve run first so that the # symbol_map is actually constructed! if (len(args) > 0) and (not isinstance(args[0], str)): if len(args) != 1: raise ValueError( "GUROBI _presolve method can only handle a single " "problem instance - %s were supplied" % (len(args), )) # write the warm-start file - currently only supports MIPs. # we only know how to deal with a single problem instance. if self._warm_start_solve and (not user_warmstart): start_time = time.time() self._warm_start(args[0]) end_time = time.time() if self._report_timing is True: print("Warm start write time=%.2f seconds" % (end_time - start_time))
def _postsolve(self): # take care of the annoying (and empty) CPLEX temporary files in the current directory. # this approach doesn't seem overly efficient, but python os module functions don't # accept regular expression directly. filename_list = os.listdir(".") for filename in filename_list: # CPLEX temporary files come in two flavors - cplex.log and clone*.log. # the latter is the case for multi-processor environments. # IMPT: trap the possible exception raised by the file not existing. # this can occur in pyro environments where > 1 workers are # running CPLEX, and were started from the same directory. # these logs don't matter anyway (we redirect everything), # and are largely an annoyance. try: if re.match('cplex\.log', filename) != None: os.remove(filename) elif re.match('clone\d+\.log', filename) != None: os.remove(filename) except OSError: pass # let the base class deal with returning results. results = ILMLicensedSystemCallSolver._postsolve(self) # finally, clean any temporary files registered with the temp file # manager, created populated *directly* by this plugin. does not # include, for example, the execution script. but does include # the warm-start file. TempfileManager.pop(remove=not self._keepfiles) return results
def _postsolve(self): # take care of the annoying GUROBI log file in the current # directory. this approach doesn't seem overly efficient, but # python os module functions doesn't accept regular expression # directly. filename_list = os.listdir(".") for filename in filename_list: # IMPT: trap the possible exception raised by the file not # existing. this can occur in pyro environments where # > 1 workers are running GUROBI, and were started # from the same directory. these logs don't matter # anyway (we redirect everything), and are largely an # annoyance. try: if re.match('gurobi\.log', filename) != None: os.remove(filename) except OSError: pass # let the base class deal with returning results. results = ILMLicensedSystemCallSolver._postsolve(self) # finally, clean any temporary files registered with the temp file # manager, created populated *directly* by this plugin. does not # include, for example, the execution script. but does include # the warm-start file. TempfileManager.pop(remove=not self._keepfiles) return results
def __init__(self, **kwds): logger.warning( "The shell interface for Xpress is broken for recent versions "\ "of Xpress. Please use xpress_direct or xpress_persistent, "\ "which require the Xpress Python API. Python bindings "\ "for recent versions of Xpress can be installed via `pip`: "\ "<https://pypi.org/project/xpress/>.") # # Call base class constructor # kwds['type'] = 'xpress' ILMLicensedSystemCallSolver.__init__(self, **kwds) self.is_mip = kwds.pop('is_mip', False) # # Define valid problem formats and associated results formats # self._valid_problem_formats = [ProblemFormat.cpxlp, ProblemFormat.mps] self._valid_result_formats = {} self._valid_result_formats[ProblemFormat.cpxlp] = [ResultsFormat.soln] self._valid_result_formats[ProblemFormat.mps] = [ResultsFormat.soln] self.set_problem_format(ProblemFormat.cpxlp) # # Cache the problem type - LP or MIP. Xpress needs to know this # on the command-line, and it matters when reading the solution file. # # Note: Undefined capabilities default to 'None' self._capabilities = Bunch() self._capabilities.linear = True self._capabilities.quadratic_objective = True self._capabilities.quadratic_constraint = True self._capabilities.integer = True self._capabilities.sos1 = True self._capabilities.sos2 = True
def process_logfile(self): return ILMLicensedSystemCallSolver.process_logfile(self)
def available(self, exception_flag=False): val = ILMLicensedSystemCallSolver.available(self, exception_flag) if not val: return False return True