Loading...
Searching...
No Matches
transport1.py
Go to the documentation of this file.
1
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 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")
19
20 print("Run with Default:")
21 job = ws.add_job_from_file("trnsport.gms")
22 job.run()
23 for rec in job.out_db["x"]:
24 print(
25 f"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"
26 )
27
28 print("Run with XPRESS:")
29 opt = ws.add_options()
30 opt.all_model_types = "xpress"
31 job.run(opt)
32 for rec in job.out_db["x"]:
33 print(
34 f"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"
35 )
36
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")
40 opt.optfile = 1
41 with open(os.path.join(ws.working_directory, "transport1_xpress.log"), "w") as log:
42 job.run(opt, output=log) # job.run(opt, output=sys.stdout)
43 for rec in job.out_db["x"]:
44 print(
45 f"x({rec.key(0)},{rec.key(1)}): level={rec.level} marginal={rec.marginal}"
46 )