Loading...
Searching...
No Matches
transport13.cpp
Go to the documentation of this file.
1
25#include "gams.h"
26#include "transport.h"
27
28#include <iostream>
29#include <map>
30#include <string>
31#include <tuple>
32#include <vector>
33
34using namespace gams;
35using namespace std;
36
42int main(int argc, char* argv[])
43{
44 cout << "---------- Transport 13 --------------" << endl;
45
46 try {
47 vector<string> plants {"Seattle", "San-Diego"};
48 vector<string> markets {"New-York", "Chicago", "Topeka"};
49 map<string, double> capacity {
50 { "Seattle", 350.0 }, { "San-Diego", 600.0 }
51 };
52 map<string, double> demand {
53 { "New-York", 325.0 }, { "Chicago", 300.0 }, { "Topeka", 275.0 }
54 };
55 map<tuple<string, string>, double> distance {
56 { make_tuple("Seattle", "New-York"), 2.5 },
57 { make_tuple("Seattle", "Chicago"), 1.7 },
58 { make_tuple("Seattle", "Topeka"), 1.8 },
59 { make_tuple("San-Diego", "New-York"), 2.5 },
60 { make_tuple("San-Diego", "Chicago"), 1.8 },
61 { make_tuple("San-Diego", "Topeka"), 1.4 }
62 };
63
64 GAMSWorkspaceInfo wsInfo;
65 if (argc > 1)
66 wsInfo.setSystemDirectory(argv[1]);
67 GAMSWorkspace ws(wsInfo);
68
69 Transport t(ws);
70
71 for (string p : plants)
72 t.i().addRecord(p);
73
74 for (string m : markets)
75 t.j().addRecord(m);
76
77 for (string p : plants)
78 t.a().addRecord(p).setValue(capacity[p]);
79
80 for (string m : markets)
81 t.b().addRecord(m).setValue(demand[m]);
82
83 for (auto dis : distance)
84 t.d().addRecord(get<0>(dis.first), get<1>(dis.first)).setValue(distance[dis.first]);
85
86 t.f().addRecord().setValue(90);
87
88 t.opt().setAllModelTypes("cplex");
89
90 t.run(GAMSCheckpoint(), cout);
91
92 cout << "Objective: " << t.z().firstRecord().level() << endl;
93 for (GAMSVariableRecord rec : t.x())
94 cout << "x(" << rec.key(0) << "," << rec.key(1) << "): level=" << rec.level() <<
95 " marginal=" << rec.marginal() << endl;
96
97 } catch (GAMSException &ex) {
98 cout << "GAMSException occured: " << ex.what() << endl;
99 } catch (exception &ex) {
100 cout << ex.what() << endl;
101 }
102
103 return 0;
104}
gams::GAMSSet j() const
j(j): markets
Definition transport.h:52
void run(gams::GAMSCheckpoint checkpoint, std::ostream &output)
Executes the trnsport model.
Definition transport.cpp:60
gams::GAMSParameter b() const
b(i): demand at market j in cases
Definition transport.h:64
gams::GAMSParameter f() const
f: freight in dollars per case per thousand miles
Definition transport.h:76
gams::GAMSVariable x() const
x(i,j): shipment quantities in cases
Definition transport.h:82
gams::GAMSParameter a() const
a(i): capacity of plant i in cases
Definition transport.h:58
gams::GAMSParameter d() const
d(i,j): distance in thousands of miles
Definition transport.h:70
gams::GAMSVariable z() const
z: total transportation costs in thousands of dollars
Definition transport.h:88
gams::GAMSOptions opt() const
Options for the execution of the trnsport model.
Definition transport.h:94
gams::GAMSSet i() const
i(i): canning plants
Definition transport.h:46
void setAllModelTypes(const std::string &solver)
void setValue(const double val)
GAMSParameterRecord addRecord(const std::vector< std::string > &keys)
GAMSSetRecord addRecord(const std::vector< std::string > &keys)
GAMSVariableRecord firstRecord(const std::vector< std::string > &slice)
void setSystemDirectory(const std::string &systemDir)
int main(int argc, char *argv[])
Wrapper class definition for GAMS trnsport model.