17from io
import StringIO
20from threading
import Thread
21from gams
import GamsWorkspace, SolveLink
23if __name__ ==
"__main__":
24 sys_dir = sys.argv[1]
if len(sys.argv) > 1
else None
25 ws = GamsWorkspace(system_directory=sys_dir)
29 job = ws.add_job_from_file(
"clad")
32 with open(os.path.join(ws.working_directory,
"cplex.opt"),
"w")
as f:
34 f.write(
"interactive 1\n")
35 f.write(
"iafile cplex.op2\n")
37 opt = ws.add_options()
40 opt.solvelink = SolveLink.LoadLibrary
45 thread = Thread(target=job.run, args=(opt,), kwargs={
"output": sw})
49 steps = [(5.0,
"epgap 0.1"), (10.0,
"epgap 0.2"), (20.0,
"epagap 1e9")]
54 thread.join(s[0] - total_time)
55 if not thread.is_alive():
59 with open(os.path.join(ws.working_directory,
"cplex.op2"),
"w")
as f:
63 print(
"Interrupted Cplex to continue with new option: " + s[1])
70 if not "Interrupted..." in log:
71 raise Exception(
"Expected the solver to be interrupted at least once.")