transport13.cpp File Reference
This is the 13th model in a series of tutorial examples. More...
#include "gams.h"#include "transport.h"#include <iostream>#include <map>#include <string>#include <tuple>#include <vector>Go to the source code of this file.
Functions | |
| int | main (int argc, char *argv[]) | 
Detailed Description
This is the 13th model in a series of tutorial examples.
Here we show:
- How to run a GAMSJob using a wrapper class to package a particular GAMS model
 
Definition in file transport13.cpp.
Function Documentation
◆ main()
| int main | ( | int | argc, | 
| char * | argv[] ) | 
Definition at line 42 of file transport13.cpp.
   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;
   94            cout << "x(" << rec.key(0) << "," << rec.key(1) << "): level=" << rec.level() <<
   95                    " marginal=" << rec.marginal() << endl;
   96 
   98        cout << "GAMSException occured: " << ex.what() << endl;
   99    } catch (exception &ex) {
  100        cout << ex.what() << endl;
  101    }
  102 
  103    return 0;
  104}
Definition transport.h:37
void setSystemDirectory(const std::string &systemDir)