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 if (Environment.GetCommandLineArgs().Length > 1)
32 ws = new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
33 else
34 ws = new GAMSWorkspace();
35 ws.GamsLib("trnsport");
36
37 // create a GAMSJob from file and run it with default settings
38 GAMSJob t1 = ws.AddJobFromFile("trnsport.gms");
39
40 t1.Run();
41 Console.WriteLine("Ran with Default:");
42 foreach (GAMSVariableRecord rec in t1.OutDB.GetVariable("x"))
43 Console.WriteLine("x(" + rec.Key(0) + "," + rec.Key(1) + "): level=" + rec.Level + " marginal=" + rec.Marginal);
44
45 // run the job again with another solver
46 using (GAMSOptions opt = ws.AddOptions())
47 {
48 opt.AllModelTypes = "xpress";
49 t1.Run(opt);
50 }
51 Console.WriteLine("Ran with XPRESS:");
52 foreach (GAMSVariableRecord rec in t1.OutDB.GetVariable("x"))
53 Console.WriteLine("x(" + rec.Key(0) + "," + rec.Key(1) + "): level=" + rec.Level + " marginal=" + rec.Marginal);
54
55 // run the job with a solver option file
56 using (StreamWriter optFile = new StreamWriter(Path.Combine(ws.WorkingDirectory, "xpress.opt")))
57 using (TextWriter logFile = new StreamWriter(Path.Combine(ws.WorkingDirectory, "transport1_xpress.log")))
58 using (GAMSOptions opt = ws.AddOptions())
59 {
60 optFile.WriteLine("algorithm=barrier");
61 optFile.Close();
62 opt.AllModelTypes = "xpress";
63 opt.OptFile = 1;
64 t1.Run(opt, output: logFile);
65 //Instead of writing the log into a file. it is also possible to redirect it to Console.Out
66 //t1.Run(opt, output: Console.Out);
67 }
68 Console.WriteLine("Ran with XPRESS with non-default option:");
69 foreach (GAMSVariableRecord rec in t1.OutDB.GetVariable("x"))
70 Console.WriteLine("x(" + rec.Key(0) + "," + rec.Key(1) + "): level=" + rec.Level + " marginal=" + rec.Marginal);
71 }
72 }
73}
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
string Key(int index)
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