39 " i canning plants \n"
43 " a(i) capacity of plant i in cases \n"
44 " b(j) demand at market j in cases \n"
45 " d(i,j) distance in thousands of miles \n"
46 "Scalar f freight in dollars per case per thousand miles; \n"
48 "$if not set gdxincname $abort 'no include file name for data file provided'\n"
49 "$gdxin %gdxincname% \n"
50 "$load i j a b d f \n"
53 " Parameter c(i,j) transport cost in thousands of dollars per case ; \n"
55 " c(i,j) = f * d(i,j) / 1000 ; \n"
58 " x(i,j) shipment quantities in cases \n"
59 " z total transportation costs in thousands of dollars ; \n"
61 " Positive Variable x ; \n"
65 " cost define objective function \n"
66 " supply(i) observe supply limit at plant i \n"
67 " demand(j) satisfy demand at market j ; \n"
69 " cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"
71 " supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n"
73 " demand(j) .. sum(i, x(i,j)) =g= b(j) ; \n"
75 " Model transport /all/ ; \n"
77 " Solve transport using lp minimizing z ; \n"
79 "Display x.l, x.m ; \n";
88int main(
int argc,
char* argv[])
90 cout <<
"---------- Transport 4 --------------" << endl;
99 vector<string> plants = {
100 "Seattle",
"San-Diego"
102 vector<string> markets = {
103 "New-York",
"Chicago",
"Topeka"
105 map<string, double> capacity = {
106 {
"Seattle", 350.0 }, {
"San-Diego", 600.0 }
108 map<string, double> demand = {
109 {
"New-York", 325.0 }, {
"Chicago", 300.0 }, {
"Topeka", 275.0 }
111 map<tuple<string, string>,
double> distance = {
112 { make_tuple(
"Seattle",
"New-York"), 2.5 },
113 { make_tuple(
"Seattle",
"Chicago"), 1.7 },
114 { make_tuple(
"Seattle",
"Topeka"), 1.8 },
115 { make_tuple(
"San-Diego",
"New-York"), 2.5 },
116 { make_tuple(
"San-Diego",
"Chicago"), 1.8 },
117 { make_tuple(
"San-Diego",
"Topeka"), 1.4 }
124 for (
string p: plants)
128 for (
string m: markets)
132 for (
string p: plants)
136 for (
string m: markets)
140 for (
auto t : distance)
154 cout <<
"x(" << rec.key(0) <<
"," << rec.key(1) <<
"):" <<
" level=" << rec.level() <<
" marginal="
155 << rec.marginal() << endl;
158 cout <<
"GAMSException occured: " << ex.what() << endl;
159 }
catch (exception &ex) {
160 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.