Loading...
Searching...
No Matches
transport1.cpp
Go to the documentation of this file.
1
25#include "gams.h"
26#include <iostream>
27#include <fstream>
28
29using namespace gams;
30using namespace std;
31
43int main(int argc, char* argv[])
44{
45 cout << "---------- Transport 1 --------------" << endl;
46
47 try {
48 GAMSWorkspaceInfo wsInfo;
49 if (argc > 1)
50 wsInfo.setSystemDirectory(argv[1]);
51 GAMSWorkspace ws(wsInfo);
52 // Retrieves [trnsport] model from GAMS Model Library
53 ws.gamsLib("trnsport");
54
55 // create a GAMSJob from file and run it with default settings
56 GAMSJob t1 = ws.addJobFromFile("trnsport.gms");
57
58 // Default run
59 t1.run();
60 cout << "Ran with Defaults:" << endl;
61 for (GAMSVariableRecord rec : t1.outDB().getVariable("x"))
62 cout << "x(" << rec.key(0) << "," << rec.key(1) << "):" << " level=" << rec.level() << " marginal="
63 << rec.marginal() << endl;
64
65 // Run the job again with another solver
66 GAMSOptions opt = ws.addOptions();
67 opt.setAllModelTypes("xpress");
68 t1.run(opt);
69 cout << "Ran with XPRESS:" << endl;
70 for (GAMSVariableRecord rec : t1.outDB().getVariable("x"))
71 cout << "x(" << rec.key(0) << "," << rec.key(1) << "):" << " level=" << rec.level() << " marginal="
72 << rec.marginal() << endl;
73
74 // Run the job with a solver option file
75 ofstream xpressopt(ws.workingDirectory() + cPathSep + "xpress.opt");
76 xpressopt << "algorithm=barrier" << endl;
77 xpressopt.close();
78
79 opt.setOptFile(1);
80 t1.run(opt);
81 cout << "Ran with XPRESS with non-default option:" << endl;
82 for (GAMSVariableRecord rec : t1.outDB().getVariable("x"))
83 cout << "x(" << rec.key(0) << "," << rec.key(1) << "):" << " level=" << rec.level() << " marginal="
84 << rec.marginal() << endl;
85
86 } catch (GAMSException &ex) {
87 cout << "GAMSException occured: " << ex.what() << endl;
88 } catch (exception &ex) {
89 cout << ex.what() << endl;
90 }
91
92 return 0;
93}
GAMSVariable getVariable(const std::string &name)
GAMSDatabase outDB()
void setAllModelTypes(const std::string &solver)
void setOptFile(const int value)
void setSystemDirectory(std::string systemDir)