Loading...
Searching...
No Matches
gt_example2.py
Go to the documentation of this file.
7
8import os
9import sys
10from gams import GamsWorkspace
11import gams.transfer as gt
12
13if __name__ == "__main__":
14 sys_dir = sys.argv[1] if len(sys.argv) > 1 else None
15 ws = GamsWorkspace(system_directory=sys_dir)
16
17 ws.gamslib("trnsport")
18 job = ws.add_job_from_file("trnsport.gms")
19 job.run()
20
21 m = gt.Container(
22 os.path.join(ws.working_directory, job.out_db.name + ".gdx"), sys_dir
23 )
24
25 # some GDX attributes are available right away, but the data needs to be loaded
26 print(f"m.listSymbols(): {m.listSymbols()}") # get all symbols in GDX
27 print(f"m.listSets(): {m.listSets()}") # get all sets in GDX file
28 print(f"m.listParameters(): {m.listParameters()}") # get all parameters in GDX file
29 print(f"m.listVariables(): {m.listVariables()}") # get all variables in GDX file
30 print(f"m.listEquations(): {m.listEquations()}") # get all equations in GDX file
31
32 # get access to the data structures
33 print(f"m.data['i'].summary: {m.data['i'].summary}")
34 print(f"m.data['i'].records:\n{m.data['i'].records}")
35
36 # add new data
37 t = gt.Parameter(
38 m,
39 "t",
40 ["*"],
41 records=[("t" + str(i), i) for i in range(10)],
42 description="new data",
43 )
44
45 # write the GDX file
46 m.write("transport_out.gdx")