transport5.cpp File Reference
This is the 5th model in a series of tutorial examples. More...
#include "gams.h"#include <vector>#include <iostream>Go to the source code of this file.
Functions | |
| string | getModelText () | 
| Get model as string.   | |
| int | main (int argc, char *argv[]) | 
Detailed Description
This is the 5th model in a series of tutorial examples.
Here we show:
- How to initialize a GAMSCheckpoint by running a GAMSJob
 - How to initialize a GAMSJob from a GAMSCheckpoint
 
Definition in file transport5.cpp.
Function Documentation
◆ getModelText()
| string getModelText | ( | ) | 
Get model as string.
Definition at line 33 of file transport5.cpp.
   34{
   35    return " Sets                                                               \n"
   36           "     i   canning plants   / seattle, san-diego /                    \n"
   37           "     j   markets          / new-york, chicago, topeka / ;           \n"
   38           "                                                                    \n"
   39           "Parameters                                                          \n"
   40           "     a(i)  capacity of plant i in cases                             \n"
   41           "       /    seattle     350                                         \n"
   42           "            san-diego   600  /                                      \n"
   43           "                                                                    \n"
   44           "     b(j)  demand at market j in cases                              \n"
   45           "       /    new-york    325                                         \n"
   46           "            chicago     300                                         \n"
   47           "            topeka      275  / ;                                    \n"
   48           "                                                                    \n"
   49           "Table d(i,j)  distance in thousands of miles                        \n"
   50           "                  new-york       chicago      topeka                \n"
   51           "    seattle          2.5           1.7          1.8                 \n"
   52           "    san-diego        2.5           1.8          1.4  ;              \n"
   53           "                                                                    \n"
   54           "Scalar f      freight in dollars per case per thousand miles  /90/ ;\n"
   55           "Scalar bmult  demand multiplier /1/;                                \n"
   56           "                                                                    \n"
   57           "Parameter c(i,j)  transport cost in thousands of dollars per case ; \n"
   58           "                                                                    \n"
   59           "          c(i,j) = f * d(i,j) / 1000 ;                              \n"
   60           "                                                                    \n"
   61           "Variables                                                           \n"
   62           "     x(i,j)  shipment quantities in cases                           \n"
   63           "     z       total transportation costs in thousands of dollars ;   \n"
   64           "                                                                    \n"
   65           "Positive Variable x ;                                               \n"
   66           "                                                                    \n"
   67           "Equations                                                           \n"
   68           "     cost        define objective function                          \n"
   69           "     supply(i)   observe supply limit at plant i                    \n"
   70           "     demand(j)   satisfy demand at market j ;                       \n"
   71           "                                                                    \n"
   72           "cost ..        z  =e=  sum((i,j), c(i,j)*x(i,j)) ;                  \n"
   73           "                                                                    \n"
   74           "supply(i) ..   sum(j, x(i,j))  =l=  a(i) ;                          \n"
   75           "                                                                    \n"
   76           "demand(j) ..   sum(i, x(i,j))  =g=  bmult*b(j) ;                    \n"
   77           "                                                                    \n"
   78           "Model transport /all/ ;                                             \n"
   79           "Scalar ms 'model status', ss 'solve status';                        \n";
   80}
Referenced by main().
◆ main()
| int main | ( | int | argc, | 
| char * | argv[] ) | 
Definition at line 88 of file transport5.cpp.
   89{
   90    cout << "---------- Transport 5 --------------" << endl;
   91 
   92    try {
   93        GAMSWorkspaceInfo wsInfo;
   94        if (argc > 1)
   95            wsInfo.setSystemDirectory(argv[1]);
   96        GAMSWorkspace ws(wsInfo);
   97        GAMSCheckpoint cp = ws.addCheckpoint();
   98 
   99        // initialize a GAMSCheckpoint by running a GAMSJob
  100        ws.addJobFromString(getModelText()).run(cp);
  101 
  102        vector<double> bmultlist = { 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 };
  103 
  104        // create a new GAMSJob that is initialized from the GAMSCheckpoint
  105        for (double b : bmultlist)
  106        {
  107            GAMSJob t5 = ws.addJobFromString("bmult=" + to_string(b) + "; solve transport min z use lp; ms=transport.modelstat; ss=transport.solvestat;", cp);
  108            t5.run();
  109            cout << "Scenario bmult=" << b << ":" << endl;
  113        }
  114 
  116        cout << "GAMSException occured: " << ex.what() << endl;
  117    } catch (exception &ex) {
  118        cout << ex.what() << endl;
  119    }
  120 
  121    return 0;
  122}
GAMSParameter getParameter(const std::string &name)
GAMSVariable getVariable(const std::string &name)
GAMSDatabase outDB()
void run()
double value()
GAMSParameterRecord findRecord(const std::vector< std::string > &keys)
double level()
GAMSVariableRecord findRecord(const std::vector< std::string > &keys)
void setSystemDirectory(const std::string &systemDir)