Loading...
Searching...
No Matches
Transport5.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using GAMS;
6
7namespace TransportSeq
8{
21 {
22 static void Main(string[] args)
23 {
25 if (Environment.GetCommandLineArgs().Length > 1)
26 ws = new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
27 else
28 ws = new GAMSWorkspace();
30
31 // initialize a GAMSCheckpoint by running a GAMSJob
32 ws.AddJobFromString(GetModelText()).Run(cp);
33
34 double[] bmultlist = new double[] { 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 };
35
36 // create a new GAMSJob that is initialized from the GAMSCheckpoint
37 foreach (double b in bmultlist)
38 {
39 GAMSJob t5 = ws.AddJobFromString("bmult=" + b + "; solve transport min z use lp; ms=transport.modelstat; ss=transport.solvestat;", cp);
40 t5.Run();
41 Console.WriteLine("Scenario bmult=" + b + ":");
42 Console.WriteLine(" Modelstatus: " + t5.OutDB.GetParameter("ms").FindRecord().Value);
43 Console.WriteLine(" Solvestatus: " + t5.OutDB.GetParameter("ss").FindRecord().Value);
44 Console.WriteLine(" Obj: " + t5.OutDB.GetVariable("z").FindRecord().Level);
45 }
46 }
47
48 static String GetModelText()
49 {
50 String model = @"
51 Sets
52 i canning plants / seattle, san-diego /
53 j markets / new-york, chicago, topeka / ;
54
55 Parameters
56
57 a(i) capacity of plant i in cases
58 / seattle 350
59 san-diego 600 /
60
61 b(j) demand at market j in cases
62 / new-york 325
63 chicago 300
64 topeka 275 / ;
65
66 Table d(i,j) distance in thousands of miles
67 new-york chicago topeka
68 seattle 2.5 1.7 1.8
69 san-diego 2.5 1.8 1.4 ;
70
71 Scalar f freight in dollars per case per thousand miles /90/ ;
72 Scalar bmult demand multiplier /1/;
73
74 Parameter c(i,j) transport cost in thousands of dollars per case ;
75
76 c(i,j) = f * d(i,j) / 1000 ;
77
78 Variables
79 x(i,j) shipment quantities in cases
80 z total transportation costs in thousands of dollars ;
81
82 Positive Variable x ;
83
84 Equations
85 cost define objective function
86 supply(i) observe supply limit at plant i
87 demand(j) satisfy demand at market j ;
88
89 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
90
91 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
92
93 demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ;
94
95 Model transport /all/ ;
96 Scalar ms 'model status', ss 'solve status';
97";
98
99 return model;
100 }
101
102 }
103}
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 5th model in a series of tutorial examples. Here we show: How to initialize a GAMSCheckpo...
Definition: Transport5.cs:21