def to_lp(self):
     self.update()
     with TemporaryFilename(suffix=".lp") as tmp_file_name:
         glp_write_lp(self.problem, None, tmp_file_name)
         with open(tmp_file_name) as tmp_file:
             lp_form = tmp_file.read()
     return lp_form
 def _glpk_representation(self):
     self.update()
     with TemporaryFilename(suffix=".glpk") as tmp_file_name:
         glp_write_prob(self.problem, 0, tmp_file_name)
         with open(tmp_file_name) as tmp_file:
             glpk_form = tmp_file.read()
     return glpk_form
Beispiel #3
0
 def __getstate__(self):
     self.update()
     with TemporaryFilename(suffix=".lp") as tmp_file_name:
         self.problem.write(tmp_file_name)
         with open(tmp_file_name) as tmp_file:
             lp_form = tmp_file.read()
     repr_dict = {'lp': lp_form, 'status': self.status, 'config': self.configuration}
     return repr_dict
Beispiel #4
0
 def __getstate__(self):
     self.update()
     with TemporaryFilename(suffix=".sav") as tmp_file_name:
         self.problem.write(tmp_file_name)
         with open(tmp_file_name, "rb") as tmp_file:
             cplex_binary = tmp_file.read()
     repr_dict = {'cplex_binary': cplex_binary, 'status': self.status, 'config': self.configuration}
     return repr_dict
Beispiel #5
0
 def _glpk_representation(self):
     self.update()
     with TemporaryFilename(suffix=".glpk") as tmp_file_name:
         code = glp_write_prob(self.problem, 0, tmp_file_name)
         if code != 0:
             raise Exception("GLPK could not successfully create the GLPK file.")
         with open(tmp_file_name, "r") as tmp_file:
             glpk_form = tmp_file.read()
     return glpk_form
Beispiel #6
0
 def to_lp(self):
     self.update()
     with TemporaryFilename(suffix=".lp") as tmp_file_name:
         code = glp_write_lp(self.problem, None, tmp_file_name)
         if code != 0:
             raise Exception("GLPK could not successfully create the LP.")
         with open(tmp_file_name) as tmp_file:
             lp_form = tmp_file.read()
     return lp_form
Beispiel #7
0
 def __setstate__(self, repr_dict):
     with TemporaryFilename(suffix=".glpk", content=repr_dict["glpk_repr"]) as tmp_file_name:
         problem = glp_create_prob()
         code = glp_read_prob(problem, 0, tmp_file_name)
         if code != 0:
             with open(tmp_file_name) as tmp_file:
                 invalid_problem = tmp_file.read()
             raise Exception("The GLPK file " + tmp_file_name + " does not seem to contain a valid GLPK problem:\n\n" + invalid_problem)
     self.__init__(problem=problem)
     self.configuration = Configuration.clone(repr_dict['config'], problem=self)
     if repr_dict['glpk_status'] == 'optimal':
         self.optimize()  # since the start is an optimal solution, nothing will happen here
 def __setstate__(self, repr_dict):
     with TemporaryFilename(
             suffix=".glpk",
             content=repr_dict["glpk_repr"]) as tmp_file_name:
         problem = glp_create_prob()
         glp_read_prob(problem, 0, tmp_file_name)
     self.__init__(problem=problem)
     self.configuration = Configuration.clone(repr_dict['config'],
                                              problem=self)
     if repr_dict['glpk_status'] == 'optimal':
         self.optimize(
         )  # since the start is an optimal solution, nothing will happen here
Beispiel #9
0
 def __setstate__(self, repr_dict):
     with TemporaryFilename(suffix=".lp", content=repr_dict["lp"]) as tmp_file_name:
         problem = gurobipy.read(tmp_file_name)
     # if repr_dict['status'] == 'optimal':  # TODO: uncomment this
     #     # turn off logging completely, get's configured later
     #     problem.set_error_stream(None)
     #     problem.set_warning_stream(None)
     #     problem.set_log_stream(None)
     #     problem.set_results_stream(None)
     #     problem.solve()  # since the start is an optimal solution, nothing will happen here
     self.__init__(problem=problem)
     self.configuration = Configuration.clone(repr_dict['config'], problem=self)  # TODO: make configuration work
Beispiel #10
0
 def __setstate__(self, repr_dict):
     with TemporaryFilename(suffix=".sav") as tmp_file_name:
         with open(tmp_file_name, "wb") as tmp_file:
             tmp_file.write(repr_dict["cplex_binary"])
         problem = cplex.Cplex()
         # turn off logging completely, get's configured later
         problem.set_error_stream(None)
         problem.set_warning_stream(None)
         problem.set_log_stream(None)
         problem.set_results_stream(None)
         problem.read(tmp_file_name)
     if repr_dict['status'] == 'optimal':
         problem.solve()  # since the start is an optimal solution, nothing will happen here
     self.__init__(problem=problem)
     self.configuration = Configuration.clone(repr_dict['config'], problem=self)
Beispiel #11
0
 def from_lp(cls, lp_form):
     problem = glp_create_prob()
     with TemporaryFilename(suffix=".lp", content=lp_form) as tmp_file_name:
         glp_read_lp(problem, None, tmp_file_name)
     model = cls(problem=problem)
     return model
Beispiel #12
0
 def from_lp(cls, lp_form):
     with TemporaryFilename(suffix=".lp", content=lp_form) as tmp_file_name:
         problem = gurobipy.read(tmp_file_name)
     model = cls(problem=problem)
     return model
Beispiel #13
0
 def from_lp(cls, lp_form):
     problem = mip.Model(solver_name=mip.CBC)
     with TemporaryFilename(suffix=".lp", content=lp_form) as tmp_file_name:
         problem.read(tmp_file_name)
     model = cls(problem=problem)
     return model