def register_cbc_executable( path=r'C:\Users\Benjamin\PycharmProjects\DispatchModels\dispatch\solver' ): """ :param path: :return: """ # todo: add cbc executable path to Django settings path_cbc = path os.environ['PATH'] += os.pathsep + path_cbc register_executable(name='cbc') return None
def __init__(self, **kwds): try: GLPKSHELL_old.__init__(self, **kwds) except ApplicationError: #pragma:nocover pass #pragma:nocover MockMIP.__init__(self, "glpk") def available(self, exception_flag=True): return GLPKSHELL_old.available(self, exception_flag) def create_command_line(self, executable, problem_files): command = GLPKSHELL_old.create_command_line(self, executable, problem_files) MockMIP.create_command_line(self, executable, problem_files) return command def executable(self): return MockMIP.executable(self) def _execute_command(self, cmd): return MockMIP._execute_command(self, cmd) def _convert_problem(self, args, pformat, valid_pformats): if pformat in [ProblemFormat.mps, ProblemFormat.cpxlp]: return (args, pformat, None) else: return (args, ProblemFormat.cpxlp, None) register_executable(name='glpsol')
def __init__(self, **kwds): try: GLPKSHELL_old.__init__(self, **kwds) except ApplicationError: #pragma:nocover pass #pragma:nocover MockMIP.__init__(self,"glpk") def available(self, exception_flag=True): return GLPKSHELL_old.available(self,exception_flag) def create_command_line(self,executable,problem_files): command = GLPKSHELL_old.create_command_line(self,executable,problem_files) MockMIP.create_command_line(self,executable,problem_files) return command def executable(self): return MockMIP.executable(self) def _execute_command(self,cmd): return MockMIP._execute_command(self,cmd) def _convert_problem(self,args,pformat,valid_pformats): if pformat in [ProblemFormat.mps,ProblemFormat.cpxlp]: return (args,pformat,None) else: return (args,ProblemFormat.cpxlp,None) register_executable( name='glpsol')
return obj ## Display of the output ## # Display x.l, x.m ; def pyomo_postprocess(options=None, instance=None, results=None): model.x.display() import os from pyutilib.services import register_executable print(type(os.environ['PATH'])) path_cbc = r'C:\Users\Benjamin\PycharmProjects\DispatchModels\dispatch\solver' os.environ['PATH'] += os.pathsep + path_cbc register_executable(name='cbc') # This is an optional code path that allows the script to be run outside of # pyomo command-line. For example: python transport.py if __name__ == '__main__': # This emulates what the pyomo command-line tools does from pyomo.opt import SolverFactory import pyomo.environ opt = SolverFactory("cbc") results = opt.solve(model) #sends results to stdout results.write() print("\nDisplaying Solution\n" + '-' * 60) pyomo_postprocess(None, model, results)