gt_example2.py
Go to the documentation of this file.
11 
12 from gamstransfer import *
13 from gams import GamsWorkspace, GamsJob
14 import os
15 import sys
16 
17 if __name__ == "__main__":
18  if len(sys.argv) > 1:
19  ws = GamsWorkspace(system_directory=sys.argv[1])
20  else:
21  ws = GamsWorkspace()
22 
23  ws.gamslib("trnsport")
24  job = ws.add_job_from_file("trnsport.gms")
25  job.run()
26 
27  # create instance of gams gdx data
28  # this readies the file for reading
29  # this convenience notation also reads in all symbols (records & meta data)
30  m = Container(os.path.join(ws.working_directory, job.out_db.name + ".gdx"))
31 
32  # some gdx attributes are available right away, but the data need to be loaded
33  m.listSymbols # get all symbols in GDX
34  m.listSets # get all sets in GDX file
35  m.listParameters # get all parameters in GDX file
36  m.listVariables # get all variables in GDX file
37  m.listEquations # get all equations in GDX file
38 
39  # get access to the data structures
40  m.data["i"].summary
41  m.data["i"].records
42 
43  # add new data
44  t = Parameter(
45  m,
46  "t",
47  ["*"],
48  records=[("t" + str(i), i) for i in range(10)],
49  description="new data",
50  )
51 
52  # write the gdx
53  m.write("transport_out.gdx")