Loading...
Searching...
No Matches
transport1.cpp
Go to the documentation of this file.
1/*
2 * GAMS - General Algebraic Modeling System C++ API
3 *
4 * Copyright (c) 2017-2023 GAMS Software GmbH <support@gams.com>
5 * Copyright (c) 2017-2023 GAMS Development Corp. <support@gams.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
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)