Transport1.cs
1using System;
2using System.IO;
3using System.Collections.Generic;
4using System.Text;
5using GAMS;
6
7namespace TransportSeq
8{
24 {
25 static void Main(string[] args)
26 {
28 if (Environment.GetCommandLineArgs().Length > 1)
29 ws = new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
30 else
31 ws = new GAMSWorkspace();
32 ws.GamsLib("trnsport");
33
34 // create a GAMSJob from file and run it with default settings
35 GAMSJob t1 = ws.AddJobFromFile("trnsport.gms");
36
37 t1.Run();
38 Console.WriteLine("Ran with Default:");
39 foreach (GAMSVariableRecord rec in t1.OutDB.GetVariable("x"))
40 Console.WriteLine("x(" + rec.Key(0) + "," + rec.Key(1) + "): level=" + rec.Level + " marginal=" + rec.Marginal);
41
42 // run the job again with another solver
43 using (GAMSOptions opt = ws.AddOptions())
44 {
45 opt.AllModelTypes = "xpress";
46 t1.Run(opt);
47 }
48 Console.WriteLine("Ran with XPRESS:");
49 foreach (GAMSVariableRecord rec in t1.OutDB.GetVariable("x"))
50 Console.WriteLine("x(" + rec.Key(0) + "," + rec.Key(1) + "): level=" + rec.Level + " marginal=" + rec.Marginal);
51
52 // run the job with a solver option file
53 using (StreamWriter optFile = new StreamWriter(Path.Combine(ws.WorkingDirectory, "xpress.opt")))
54 using (GAMSOptions opt = ws.AddOptions())
55 {
56 optFile.WriteLine("algorithm=barrier");
57 optFile.Close();
58 opt.AllModelTypes = "xpress";
59 opt.OptFile = 1;
60 t1.Run(opt);
61 }
62 Console.WriteLine("Ran with XPRESS with non-default option:");
63 foreach (GAMSVariableRecord rec in t1.OutDB.GetVariable("x"))
64 Console.WriteLine("x(" + rec.Key(0) + "," + rec.Key(1) + "): level=" + rec.Level + " marginal=" + rec.Marginal);
65 }
66 }
67}
string Key(int index)
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
void GamsLib(string model)
This is the 1st model in a series of tutorial examples. Here we show: How to run a GAMSJob from file ...
Definition: Transport1.cs:23
GAMSJob AddJobFromFile(string fileName, GAMSCheckpoint checkpoint=null, string jobName=null)