def solve(self, solver, io, io_options, solver_options, symbolic_labels, load_solutions): """ Optimize the model """ assert self.model is not None opt = SolverFactory(solver, solver_io=io) opt.options.update(solver_options) if io == 'nl': assert opt.problem_format() == ProblemFormat.nl elif io == 'lp': assert opt.problem_format() == ProblemFormat.cpxlp elif io == 'mps': assert opt.problem_format() == ProblemFormat.mps #elif io == 'python': # print opt.problem_format() # assert opt.problem_format() is None try: if isinstance(opt, PersistentSolver): opt.set_instance(self.model, symbolic_solver_labels=symbolic_labels) if opt.warm_start_capable(): results = opt.solve(symbolic_solver_labels=symbolic_labels, warmstart=True, load_solutions=load_solutions, **io_options) else: results = opt.solve(symbolic_solver_labels=symbolic_labels, load_solutions=load_solutions, **io_options) else: if opt.warm_start_capable(): results = opt.solve(self.model, symbolic_solver_labels=symbolic_labels, warmstart=True, load_solutions=load_solutions, **io_options) else: results = opt.solve(self.model, symbolic_solver_labels=symbolic_labels, load_solutions=load_solutions, **io_options) return opt, results finally: opt.deactivate() del opt return None, None
def solve(self, solver, io, io_options, solver_options, symbolic_labels, load_solutions): """ Optimize the model """ assert self.model is not None opt = SolverFactory(solver, solver_io=io) opt.options.update(solver_options) if io == 'nl': assert opt.problem_format() == ProblemFormat.nl elif io == 'lp': assert opt.problem_format() == ProblemFormat.cpxlp elif io == 'mps': assert opt.problem_format() == ProblemFormat.mps #elif io == 'python': # print opt.problem_format() # assert opt.problem_format() is None try: if isinstance(opt, PersistentSolver): opt.compile_instance(self.model, symbolic_solver_labels=symbolic_labels) if opt.warm_start_capable(): results = opt.solve( self.model, symbolic_solver_labels=symbolic_labels, warmstart=True, load_solutions=load_solutions, **io_options) else: results = opt.solve( self.model, symbolic_solver_labels=symbolic_labels, load_solutions=load_solutions, **io_options) return opt, results finally: opt.deactivate() del opt return None, None