38 " i canning plants \n"
42 " a(i) capacity of plant i in cases \n"
43 " b(j) demand at market j in cases \n"
44 " d(i,j) distance in thousands of miles \n"
45 "Scalar f freight in dollars per case per thousand miles; \n"
47 "$if not set gdxincname $abort 'no include file name for data file provided'\n"
48 "$gdxin %gdxincname% \n"
49 "$load i j a b d f \n"
52 " Parameter c(i,j) transport cost in thousands of dollars per case ; \n"
54 " c(i,j) = f * d(i,j) / 1000 ; \n"
57 " x(i,j) shipment quantities in cases \n"
58 " z total transportation costs in thousands of dollars ; \n"
60 " Positive Variable x ; \n"
64 " cost define objective function \n"
65 " supply(i) observe supply limit at plant i \n"
66 " demand(j) satisfy demand at market j ; \n"
68 " cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"
70 " supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n"
72 " demand(j) .. sum(i, x(i,j)) =g= b(j) ; \n"
74 " Model transport /all/ ; \n"
76 " Solve transport using lp minimizing z ; \n"
78 "Display x.l, x.m ; \n";
87int main(
int argc,
char* argv[])
89 cout <<
"---------- Transport 4 --------------" << endl;
98 vector<string> plants = {
99 "Seattle",
"San-Diego"
101 vector<string> markets = {
102 "New-York",
"Chicago",
"Topeka"
104 map<string, double> capacity = {
105 {
"Seattle", 350.0 }, {
"San-Diego", 600.0 }
107 map<string, double> demand = {
108 {
"New-York", 325.0 }, {
"Chicago", 300.0 }, {
"Topeka", 275.0 }
110 map<tuple<string, string>,
double> distance = {
111 { make_tuple(
"Seattle",
"New-York"), 2.5 },
112 { make_tuple(
"Seattle",
"Chicago"), 1.7 },
113 { make_tuple(
"Seattle",
"Topeka"), 1.8 },
114 { make_tuple(
"San-Diego",
"New-York"), 2.5 },
115 { make_tuple(
"San-Diego",
"Chicago"), 1.8 },
116 { make_tuple(
"San-Diego",
"Topeka"), 1.4 }
123 for (
string p: plants)
127 for (
string m: markets)
131 for (
string p: plants)
135 for (
string m: markets)
139 for (
auto t : distance)
153 cout <<
"x(" << rec.key(0) <<
"," << rec.key(1) <<
"):" <<
" level=" << rec.level() <<
" marginal="
154 << rec.marginal() << endl;
157 cout <<
"GAMSException occured: " << ex.what() << endl;
158 }
catch (exception &ex) {
159 cout << ex.what() << endl;
GAMSSet addSet(const std::string &name, const int dimension, const std::string &explanatoryText="", GAMSEnum::SetType setType=GAMSEnum::SetType::Multi)
GAMSParameter addParameter(const std::string &name, const int dimension, const std::string &explanatoryText="")
GAMSVariable getVariable(const std::string &name)
void setAllModelTypes(const std::string &solver)
void setDefine(const std::string &key, const std::string &value)
void setValue(const double val)
GAMSParameterRecord addRecord(const std::vector< std::string > &keys)
GAMSSetRecord addRecord(const std::vector< std::string > &keys)
void setSystemDirectory(std::string systemDir)
string getModelText()
Get model as string.