34#if defined(__unix__) || defined(__linux__) || defined(__APPLE__)
40 cout <<
"---------- Transport 10 --------------" << endl;
41 cout <<
"Transport 10 is a Microsoft Windows only example." << endl;
53 " i canning plants \n"
57 " a(i) capacity of plant i in cases \n"
58 " b(j) demand at market j in cases \n"
59 " d(i,j) distance in thousands of miles \n"
60 " Scalar f freight in dollars per case per thousand miles /90/; \n"
62 "$if not set gdxincname $abort 'no include file name for data file provided'\n"
63 "$gdxin %gdxincname% \n"
67 " Parameter c(i,j) transport cost in thousands of dollars per case ; \n"
69 " c(i,j) = f * d(i,j) / 1000 ; \n"
72 " x(i,j) shipment quantities in cases \n"
73 " z total transportation costs in thousands of dollars ; \n"
75 " Positive Variable x ; \n"
78 " cost define objective function \n"
79 " supply(i) observe supply limit at plant i \n"
80 " demand(j) satisfy demand at market j ; \n"
82 " cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"
84 " supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n"
86 " demand(j) .. sum(i, x(i,j)) =g= b(j) ; \n"
88 " Model transport /all/ ; \n"
90 " Solve transport using lp minimizing z ; \n"
92 " Display x.l, x.m ; \n";
108 QAxObject* sheet = sheets->querySubObject(
"Item( string )", sheetName.c_str() );
111 QAxObject* usedrange = sheet->querySubObject(
"UsedRange");
112 QAxObject * columns = usedrange->querySubObject(
"Columns");
113 int intCols = columns->property(
"Count").toInt();
115 for (
int i = 1; i <= intCols; i++) {
116 std::string name = sheet->querySubObject(
"Cells( int, int )", 1, i)->dynamicCall(
"Value()").toString().toStdString();
117 double value = sheet->querySubObject(
"Cells( int, int )", 2, i)->dynamicCall(
"Value()").toDouble();
139 QAxObject* sheet = sheets->querySubObject(
"Item( string )", sheetName.c_str() );
140 vector<GAMSDomain> sets {set1, set2};
143 QAxObject* usedrange = sheet->querySubObject(
"UsedRange");
144 QAxObject * columns = usedrange->querySubObject(
"Columns");
145 int intCols = columns->property(
"Count").toInt();
146 QAxObject * rows = usedrange->querySubObject(
"Rows");
147 int intRows = rows->property(
"Count").toInt();
149 for (
int j = 2; j <= intCols; j++) {
150 string namej = sheet->querySubObject(
"Cells( int, int )", 1, j)->dynamicCall(
"Value()").toString().toStdString();
151 for (
int i = 2; i <= intRows; ++i) {
152 string namei = sheet->querySubObject(
"Cells( int, int )", i, 1)->dynamicCall(
"Value()").toString().toStdString();
154 double value = sheet->querySubObject(
"Cells( int, int )", i, j)->dynamicCall(
"Value()").toDouble();
166int main(
int argc,
char* argv[])
168 cout <<
"---------- Transport 10 --------------" << endl;
179 QString fileName = QString::fromStdString(ws.systemDirectory())+ cPathSep +
"apifiles" + cPathSep +
"Data" + cPathSep +
"transport.xlsx";
181 QAxObject* excel =
new QAxObject(
"Excel.Application", 0 );
182 QAxObject* workbooks = excel->querySubObject(
"Workbooks" );
183 QAxObject* workbook = workbooks->querySubObject(
"Open(const QString&)", fileName );
184 QAxObject* sheets = workbook->querySubObject(
"Worksheets" );
195 workbook->dynamicCall(
"Close()");
196 excel->dynamicCall(
"Quit()");
201 GAMSJob t10 = ws.addJobFromString(getModelText());
206 cout <<
"x(" << record.key(0) <<
"," << record.key(1) <<
"): level=" << record.level() <<
207 " marginal=" << record.marginal() << endl;
212 cout <<
"GAMSException occured: " << ex.what() << endl;
213 }
catch (exception &ex) {
214 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)