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 work_dir = sys.argv[2]
if len(sys.argv) > 2
else None
26 ws = GamsWorkspace(system_directory=sys_dir, working_directory=work_dir)
30 job = ws.add_job_from_file(
"clad")
33 with open(os.path.join(ws.working_directory,
"cplex.opt"),
"w")
as f:
35 f.write(
"interactive 1\n")
36 f.write(
"iafile cplex.op2\n")
38 opt = ws.add_options()
41 opt.solvelink = SolveLink.LoadLibrary
46 thread = Thread(target=job.run, args=(opt,), kwargs={
"output": sw})
50 steps = [(5.0,
"epgap 0.1"), (10.0,
"epgap 0.2"), (20.0,
"epagap 1e9")]
55 thread.join(s[0] - total_time)
56 if not thread.is_alive():
60 with open(os.path.join(ws.working_directory,
"cplex.op2"),
"w")
as f:
64 print(
"Interrupted Cplex to continue with new option: " + s[1])
71 if not "Interrupted..." in log:
72 raise Exception(
"Expected the solver to be interrupted at least once.")