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