Esempio n. 1
0
 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
Esempio n. 2
0
 def __setstate__(self, repr_dict):
     tmp_file = tempfile.mktemp(suffix=".glpk")
     open(tmp_file, 'w').write(repr_dict['glpk_repr'])
     problem = glp_create_prob()
     glp_read_prob(problem, 0, tmp_file)
     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
Esempio n. 3
0
 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
Esempio n. 4
0
 def __setstate__(self, repr_dict):
     with tempfile.NamedTemporaryFile(suffix=".glpk",
                                      delete=True) as tmp_file:
         tmp_file_name = tmp_file.name
         with open(tmp_file_name, 'w') as tmp_file:
             tmp_file.write(repr_dict['glpk_repr'])
             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
Esempio n. 5
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
Esempio n. 6
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