transport1.py
Go to the documentation of this file.
9 
10 from gams import *
11 import os
12 import sys
13 
14 
15 if __name__ == "__main__":
16  if len(sys.argv) > 1:
17  ws = GamsWorkspace(system_directory = sys.argv[1])
18  else:
19  ws = GamsWorkspace()
20 
21  ws.gamslib("trnsport")
22 
23  t1 = ws.add_job_from_file("trnsport.gms")
24  t1.run()
25  print("Ran with Default:")
26 
27  for rec in t1.out_db["x"]:
28  print("x(" + rec.key(0) + "," + rec.key(1) + "): level=" + str(rec.level) + " marginal=" + str(rec.marginal))
29 
30  opt = ws.add_options()
31  opt.all_model_types = "xpress"
32  t1.run(opt)
33 
34  print("Ran with XPRESS:")
35  for rec in t1.out_db["x"]:
36  print("x(" + rec.key(0) + "," + rec.key(1) + "): level=" + str(rec.level) + " marginal=" + str(rec.marginal))
37 
38  file = open(os.path.join(ws.working_directory, "xpress.opt"), "w")
39  file.write("algorithm=barrier")
40  file.close()
41 
42  opt.optfile = 1
43  with open("transport1_xpress.log", "w", newline="") as log:
44  t1.run(opt, output=log)
45  # instead of writing the log into a file it is also possible to redirect it to stdout
46  #t1.run(opt, output=sys.stdout)
47 
48  print("Ran with XPRESS with non-default option:")
49  for rec in t1.out_db["x"]:
50  print("x(" + rec.key(0) + "," + rec.key(1) + "): level=" + str(rec.level) + " marginal=" + str(rec.marginal))