12from gams
import GamsWorkspace
14if __name__ ==
"__main__":
15 sys_dir = sys.argv[1]
if len(sys.argv) > 1
else None
16 work_dir = sys.argv[2]
if len(sys.argv) > 2
else None
17 ws = GamsWorkspace(system_directory=sys_dir, working_directory=work_dir)
18 ws.gamslib(
"trnsport")
20 print(
"Run with Default:")
21 job = ws.add_job_from_file(
"trnsport.gms")
23 for rec
in job.out_db[
"x"]:
25 f
"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"
28 print(
"Run with XPRESS:")
29 opt = ws.add_options()
30 opt.all_model_types =
"xpress"
32 for rec
in job.out_db[
"x"]:
34 f
"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"
37 print(
"Run with XPRESS and non default option:")
38 with open(os.path.join(ws.working_directory,
"xpress.opt"),
"w")
as file:
39 file.write(
"algorithm=barrier")
41 with open(os.path.join(ws.working_directory,
"transport1_xpress.log"),
"w")
as log:
42 job.run(opt, output=log)
43 for rec
in job.out_db[
"x"]:
45 f
"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"