Loading...
Searching...
No Matches
Transport6.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using GAMS;
6
7namespace TransportSeq
8{
18 {
19 static void RunScenario(GAMSWorkspace ws, GAMSCheckpoint cp, object ioMutex, double b)
20 {
21 GAMSJob t6 = ws.AddJobFromString("bmult=" + b + "; solve transport min z use lp; ms=transport.modelstat; ss=transport.solvestat;", cp);
22 t6.Run();
23 // we need to make the ouput a critical section to avoid messed up report information
24 lock (ioMutex)
25 {
26 Console.WriteLine("Scenario bmult=" + b + ":");
27 Console.WriteLine(" Modelstatus: " + t6.OutDB.GetParameter("ms").FindRecord().Value);
28 Console.WriteLine(" Solvestatus: " + t6.OutDB.GetParameter("ss").FindRecord().Value);
29 Console.WriteLine(" Obj: " + t6.OutDB.GetVariable("z").FindRecord().Level);
30 }
31 }
32 static void Main(string[] args)
33 {
35 if (Environment.GetCommandLineArgs().Length > 1)
36 ws = new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
37 else
38 ws = new GAMSWorkspace();
40
41 // initialize a GAMSCheckpoint by running a GAMSJob
42 ws.AddJobFromString(GetModelText()).Run(cp);
43
44 double[] bmultlist = new double[] { 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 };
45
46 // run multiple parallel jobs using the created GAMSCheckpoint
47 Object ioMutex = new Object();
48 System.Threading.Tasks.Parallel.ForEach(bmultlist, delegate(double b) { RunScenario(ws, cp, ioMutex, b); });
49 }
50
51 static String GetModelText()
52 {
53 String model = @"
54 Sets
55 i canning plants / seattle, san-diego /
56 j markets / new-york, chicago, topeka / ;
57
58 Parameters
59
60 a(i) capacity of plant i in cases
61 / seattle 350
62 san-diego 600 /
63
64 b(j) demand at market j in cases
65 / new-york 325
66 chicago 300
67 topeka 275 / ;
68
69 Table d(i,j) distance in thousands of miles
70 new-york chicago topeka
71 seattle 2.5 1.7 1.8
72 san-diego 2.5 1.8 1.4 ;
73
74 Scalar f freight in dollars per case per thousand miles /90/ ;
75 Scalar bmult demand multiplier /1/;
76
77 Parameter c(i,j) transport cost in thousands of dollars per case ;
78
79 c(i,j) = f * d(i,j) / 1000 ;
80
81 Variables
82 x(i,j) shipment quantities in cases
83 z total transportation costs in thousands of dollars ;
84
85 Positive Variable x ;
86
87 Equations
88 cost define objective function
89 supply(i) observe supply limit at plant i
90 demand(j) satisfy demand at market j ;
91
92 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
93
94 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
95
96 demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ;
97
98 Model transport /all/ ;
99 Scalar ms 'model status', ss 'solve status';
100";
101
102 return model;
103 }
104
105 }
106}
GAMSVariable GetVariable(string variableIdentifier)
GAMSParameter GetParameter(string parameterIdentifier)
GAMSDatabase OutDB
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
new GAMSParameterRecord FindRecord(params string[] keys)
new GAMSVariableRecord FindRecord(params string[] keys)
GAMSJob AddJobFromString(string gamsSource, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSCheckpoint AddCheckpoint(string checkpointName=null)
This is the 6th model in a series of tutorial examples. Here we show: How to run multiple GAMSJobs in...
Definition: Transport6.cs:18