Loading...
Searching...
No Matches
Transport13.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using GAMS;
6
7namespace TransportSeq
8{
18 {
19 static void Main(string[] args)
20 {
21 #region Static data section
22 List<string> plants = new List<string>()
23 {
24 "Seattle", "San-Diego"
25 };
26 List<string> markets = new List<string>()
27 {
28 "New-York", "Chicago", "Topeka"
29 };
30 Dictionary<string, double> capacity = new Dictionary<string, double>()
31 {
32 { "Seattle", 350.0 }, { "San-Diego", 600.0 }
33 };
34 Dictionary<string, double> demand = new Dictionary<string, double>()
35 {
36 { "New-York", 325.0 }, { "Chicago", 300.0 }, { "Topeka", 275.0 }
37 };
38 Dictionary<Tuple<string, string>, double> distance = new Dictionary<Tuple<string, string>, double>()
39 {
40 { new Tuple<string,string> ("Seattle", "New-York"), 2.5 },
41 { new Tuple<string,string> ("Seattle", "Chicago"), 1.7 },
42 { new Tuple<string,string> ("Seattle", "Topeka"), 1.8 },
43 { new Tuple<string,string> ("San-Diego", "New-York"), 2.5 },
44 { new Tuple<string,string> ("San-Diego", "Chicago"), 1.8 },
45 { new Tuple<string,string> ("San-Diego", "Topeka"), 1.4 }
46 };
47 #endregion Static data section
48
49
51 if (Environment.GetCommandLineArgs().Length > 1)
52 ws = new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
53 else
54 ws = new GAMSWorkspace();
55
56 Transport t = new Transport(ws);
57
58 #region Input data binding
59 foreach (string p in plants)
60 t.i.AddRecord(p);
61
62 foreach (string m in markets)
63 t.j.AddRecord(m);
64
65 foreach (string p in plants)
66 t.a.AddRecord(p).Value = capacity[p];
67
68 foreach (string m in markets)
69 t.b.AddRecord(m).Value = demand[m];
70
71 foreach (Tuple<string, string> dis in distance.Keys)
72 t.d.AddRecord(dis.Item1, dis.Item2).Value = distance[dis];
73
74 t.f.AddRecord().Value = 90;
75 #endregion Input data binding
76
77 t.opt.AllModelTypes = "cplex";
78
79 t.Run(output: Console.Out);
80
81 #region Output data binding
82 Console.WriteLine("Objective: " + t.z.FirstRecord().Level);
83
84 foreach (GAMSVariableRecord rec in t.x)
85 Console.WriteLine("x(" + rec.Key(0) + "," + rec.Key(1) + "): level=" + rec.Level + " marginal=" + rec.Marginal);
86 #endregion Output data binding
87 }
88 }
89}
string Key(int index)
This is the 13th model in a series of tutorial examples. Here we show: How to run a GAMSJob using a w...
Definition: Transport13.cs:18
Wrapper class for GAMS trnsport model.