33#if defined(__unix__) || defined(__linux__) || defined(__APPLE__)
39 cout <<
"---------- Transport 10 --------------" << endl;
40 cout <<
"Transport 10 is a Microsoft Windows only example." << endl;
52 " i canning plants \n"
56 " a(i) capacity of plant i in cases \n"
57 " b(j) demand at market j in cases \n"
58 " d(i,j) distance in thousands of miles \n"
59 " Scalar f freight in dollars per case per thousand miles /90/; \n"
61 "$if not set gdxincname $abort 'no include file name for data file provided'\n"
62 "$gdxin %gdxincname% \n"
66 " Parameter c(i,j) transport cost in thousands of dollars per case ; \n"
68 " c(i,j) = f * d(i,j) / 1000 ; \n"
71 " x(i,j) shipment quantities in cases \n"
72 " z total transportation costs in thousands of dollars ; \n"
74 " Positive Variable x ; \n"
77 " cost define objective function \n"
78 " supply(i) observe supply limit at plant i \n"
79 " demand(j) satisfy demand at market j ; \n"
81 " cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"
83 " supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n"
85 " demand(j) .. sum(i, x(i,j)) =g= b(j) ; \n"
87 " Model transport /all/ ; \n"
89 " Solve transport using lp minimizing z ; \n"
91 " Display x.l, x.m ; \n";
107 QAxObject* sheet = sheets->querySubObject(
"Item( string )", sheetName.c_str() );
110 QAxObject* usedrange = sheet->querySubObject(
"UsedRange");
111 QAxObject * columns = usedrange->querySubObject(
"Columns");
112 int intCols = columns->property(
"Count").toInt();
114 for (
int i = 1; i <= intCols; i++) {
115 std::string name = sheet->querySubObject(
"Cells( int, int )", 1, i)->dynamicCall(
"Value()").toString().toStdString();
116 double value = sheet->querySubObject(
"Cells( int, int )", 2, i)->dynamicCall(
"Value()").toDouble();
138 QAxObject* sheet = sheets->querySubObject(
"Item( string )", sheetName.c_str() );
139 vector<GAMSDomain> sets {set1, set2};
142 QAxObject* usedrange = sheet->querySubObject(
"UsedRange");
143 QAxObject * columns = usedrange->querySubObject(
"Columns");
144 int intCols = columns->property(
"Count").toInt();
145 QAxObject * rows = usedrange->querySubObject(
"Rows");
146 int intRows = rows->property(
"Count").toInt();
148 for (
int j = 2; j <= intCols; j++) {
149 string namej = sheet->querySubObject(
"Cells( int, int )", 1, j)->dynamicCall(
"Value()").toString().toStdString();
150 for (
int i = 2; i <= intRows; ++i) {
151 string namei = sheet->querySubObject(
"Cells( int, int )", i, 1)->dynamicCall(
"Value()").toString().toStdString();
153 double value = sheet->querySubObject(
"Cells( int, int )", i, j)->dynamicCall(
"Value()").toDouble();
165int main(
int argc,
char* argv[])
167 cout <<
"---------- Transport 10 --------------" << endl;
178 QString fileName = QString::fromStdString(ws.systemDirectory())+ cPathSep +
"apifiles" + cPathSep +
"Data" + cPathSep +
"transport.xlsx";
180 QAxObject* excel =
new QAxObject(
"Excel.Application", 0 );
181 QAxObject* workbooks = excel->querySubObject(
"Workbooks" );
182 QAxObject* workbook = workbooks->querySubObject(
"Open(const QString&)", fileName );
183 QAxObject* sheets = workbook->querySubObject(
"Worksheets" );
194 workbook->dynamicCall(
"Close()");
195 excel->dynamicCall(
"Quit()");
200 GAMSJob t10 = ws.addJobFromString(getModelText());
205 cout <<
"x(" << record.key(0) <<
"," << record.key(1) <<
"): level=" << record.level() <<
206 " marginal=" << record.marginal() << endl;
211 cout <<
"GAMSException occured: " << ex.what() << endl;
212 }
catch (exception &ex) {
213 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)
GAMSParameter sheetToParameter(QAxObject *sheets, string sheetName, GAMSDatabase db, string paramName, string paramText, GAMSSet set)