Loading...
Searching...
No Matches
transport1.py
Go to the documentation of this file.
9
10import os
11import sys
12from gams import GamsWorkspace
13
14if __name__ == "__main__":
15 sys_dir = sys.argv[1] if len(sys.argv) > 1 else None
16 ws = GamsWorkspace(system_directory=sys_dir)
17 ws.gamslib("trnsport")
18
19 print("Run with Default:")
20 job = ws.add_job_from_file("trnsport.gms")
21 job.run()
22 for rec in job.out_db["x"]:
23 print(
24 f"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"
25 )
26
27 print("Run with XPRESS:")
28 opt = ws.add_options()
29 opt.all_model_types = "xpress"
30 job.run(opt)
31 for rec in job.out_db["x"]:
32 print(
33 f"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"
34 )
35
36 print("Run with XPRESS and non default option:")
37 with open(os.path.join(ws.working_directory, "xpress.opt"), "w") as file:
38 file.write("algorithm=barrier")
39 opt.optfile = 1
40 with open("transport1_xpress.log", "w") as log:
41 job.run(opt, output=log) # job.run(opt, output=sys.stdout)
42 for rec in job.out_db["x"]:
43 print(
44 f"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"
45 )