transport7.cpp File Reference
This is the 7th 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 7th model in a series of tutorial examples.
Here we show:
- How to create a GAMSModelInstance from a GAMSCheckpoint
 - How to modify a parameter of a GAMSModelInstance using GAMSModifier
 - How to modify a variable of a GAMSModelInstance using GAMSModifier
 
Definition in file transport7.cpp.
Function Documentation
◆ getModelText()
| string getModelText | ( | ) | 
Get model as string.
Definition at line 33 of file transport7.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}
Referenced by main().
◆ main()
| int main | ( | int | argc, | 
| char * | argv[] ) | 
Definition at line 88 of file transport7.cpp.
   89{
   90    cout << "---------- Transport 7 --------------" << 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
  101        t7.run(cp);
  102 
  103        // create a GAMSModelInstance and solve it multiple times with different scalar bmult
  106        GAMSOptions opt = ws.addOptions();
  108 
  109        // instantiate the GAMSModelInstance and pass a model definition and GAMSModifier to declare bmult mutable
  111 
  113        vector<double> bmultlist = { 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 };
  114 
  115        for (double b : bmultlist) {
  117            mi.solve();
  118            cout << "Scenario bmult=" << b << ":" << endl;
  122        }
  123 
  124        // create a GAMSModelInstance and solve it with single links in the network blocked
  125        mi = cp.addModelInstance();
  126 
  129 
  130        // instantiate the GAMSModelInstance and pass a model definition and GAMSModifier to declare upper bound of X mutable
  131        mi.instantiate("transport use lp min z", GAMSModifier (x, GAMSEnum::SymbolUpdateAction::Upper, xup));
  132 
  135                xup.clear();
  137                mi.solve();
  138                cout << "Scenario link blocked=" << i.key(0) << "-" << j.key(0) << endl;
  142            }
  143        }
  144 
  146        cout << "GAMSException occured: " << ex.what() << endl;
  147    } catch (exception &ex) {
  148        cout << ex.what() << endl;
  149    }
  150 
  151    return 0;
  152}
GAMSModelInstance addModelInstance(const std::string &modelInstanceName="")
GAMSVariable addVariable(const std::string &name, const int dimension, const GAMSEnum::VarType varType, const std::string &explanatoryText="")
GAMSParameter addParameter(const std::string &name, const int dimension, const std::string &explanatoryText="")
GAMSSet getSet(const std::string &name)
GAMSVariable getVariable(const std::string &name)
GAMSDatabase outDB()
void run()
std::string solveStatusAsString()
void instantiate(const std::string &modelDefinition, const gams::GAMSOptions &options, const std::vector< gams::GAMSModifier > &modifiers={ })
std::string modelStatusAsString()
void solve(GAMSEnum::SymbolUpdateType updateType, std::ostream &output, const GAMSModelInstanceOpt &miOpt)
GAMSDatabase syncDb()
void setAllModelTypes(const std::string &solver)
void setValue(const double val)
GAMSParameterRecord firstRecord(const std::vector< std::string > &slice)
GAMSParameterRecord addRecord(const std::vector< std::string > &keys)
bool clear()
double level()
GAMSVariableRecord findRecord(const std::vector< std::string > &keys)
void setSystemDirectory(const std::string &systemDir)