### Getting Started Examples Source: https://www.gams.com/latest/docs/UG_GAMSCONNECT.html Introduction to the basic functionalities of GAMS Connect agents through simple examples. ```APIDOC ## Getting Started Examples This section introduces the basic functionalities of GAMS Connect agents on some simple examples. For more examples, refer to the 'Examples' section. ``` -------------------------------- ### Install GAMS Python API Source: https://www.gams.com/latest/docs/RN_240.html Use the setup script to install the GAMS Python API into the local environment. ```bash cd /apifiles/Python/api && python setup.py install && cd .. ``` -------------------------------- ### CPLEX solver options file example Source: https://www.gams.com/latest/docs/UG_SolverUsage.html This example shows a typical CPLEX options file. Lines starting with '*' are comments. Options like 'barrier' and 'crossover 2' configure the solver's behavior. ```text * CPLEX options file barrier crossover 2 ``` -------------------------------- ### CSV2GDX Getting Started Source: https://www.gams.com/latest/docs/T_CSV2GDX.html Introduction to the basic functionalities of CSV2GDX with examples, highlighting its utility for specific CSV file structures. ```APIDOC ## Getting Started with CSV2GDX ### Description This section introduces the fundamental capabilities of the `CSV2GDX` tool through simple examples. It emphasizes scenarios where `CSV2GDX` is particularly useful, such as processing files with non-standard delimiters or decimal separators, which are challenging for GAMS's built-in `table` statement. ### Key Use Cases - **Non-Standard Delimiters**: Reading CSV files that use delimiters other than commas (e.g., semicolons or tabs). - **Decimal Separators**: Handling CSV files where decimals are denoted by commas instead of periods. - **Enhanced Data Import**: Provides features beyond the standard `table` statement for more complex CSV data import into GAMS. ``` -------------------------------- ### Transport5 Example - C# Source File Source: https://www.gams.com/latest/docs/apis/examples_dotnet/classTransportSeq_1_1Transport5.html This is the source file for the Transport5 example, which is the 5th in a series of tutorial examples. It shows how to initialize a GAMSCheckpoint by running a GAMSJob and how to initialize a GAMSJob from a GAMSCheckpoint. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Gams; namespace Transport5 { class Program { static void Main(string[] args) { // Initialize GAMS var gams = new GamsMi(); // Create a GAMSJob from a GDX file var job = new GamsJob(gams, "transport.gms"); // Run the job and create a GAMSCheckpoint var checkpoint = job.RunToCheckpoint(); // Create a new GAMSJob from the GAMSCheckpoint var job2 = new GamsJob(gams, checkpoint); // Run the new job job2.Run(); // Dispose GAMS gams.Dispose(); } } } ``` -------------------------------- ### GAMS Python API Source: https://www.gams.com/latest/docs/apis/python/functions_t.html Documentation for the GAMS Python API, including getting started, control, magic, transfer, and examples. ```APIDOC ## GAMS Python API ### Description Documentation for the GAMS Python API, covering its usage, control mechanisms, and examples. ### Getting Started Information on how to begin using the GAMS Python API. ### Control Details on controlling GAMS functionalities through the Python API. #### Classes ##### Class List List of all available classes. ##### Class Index Index of all available classes. ##### Class Hierarchy Hierarchy of all available classes. ##### Class Members Details on members within classes. ###### All Lists all members. ###### Functions Lists all functions. ###### Variables Lists all variables. ###### Properties Lists all properties. ### Magic (Jupyter Notebooks) Information on using GAMS within Jupyter Notebooks. ### Transfer Details on data transfer functionalities. ### Examples Code examples demonstrating the usage of the GAMS Python API. ``` -------------------------------- ### Example SBB Configuration Source: https://www.gams.com/latest/docs/S_SBB.html An example configuration file specifying NLP subsolvers and log frequency. ```text rootsolver conopt.1 subsolver snopt loginterval 10 ``` -------------------------------- ### GAMS API - Python API Source: https://www.gams.com/latest/docs/apis/python/functions_g.html Documentation for the GAMS Python API, including getting started, control, transfer, and examples. ```APIDOC ## GAMS API - Python API ### Description Documentation for the GAMS Python API, covering its usage for controlling GAMS execution, data transfer, and providing examples. ### Sub-sections - Getting Started - Control - Classes - Class List - Class Index - Class Hierarchy - Class Members - All - Functions - Variables - Properties - Magic (Jupyter Notebooks) - Transfer - Examples ``` -------------------------------- ### Parameter Output Examples Source: https://www.gams.com/latest/docs/T_CSV2GDX.html Displays the structure of parameters before and after applying valueDim and performing calculations. ```text ---- 36 PARAMETER d distance in thousands of miles new-york chicago topeka seattle 2.500 1.700 1.800 san-diego 2.500 1.800 1.400 ``` ```text ---- 49 PARAMETER dmod miles seattle .new-york 2.500 seattle .chicago 1.700 seattle .topeka 1.800 san-diego.new-york 2.500 san-diego.chicago 1.800 san-diego.topeka 1.400 ``` ```text ---- 52 PARAMETER dmod miles km seattle .new-york 2.500 4.630 seattle .chicago 1.700 3.148 seattle .topeka 1.800 3.334 san-diego.new-york 2.500 4.630 san-diego.chicago 1.800 3.334 san-diego.topeka 1.400 2.593 ``` -------------------------------- ### Run Connect from Command Line Source: https://www.gams.com/latest/docs/UG_GAMSCONNECT.html Demonstrates how to execute Connect instructions using a YAML file from the command line. Supports passing key-value substitutions. ```Shell gamsconnect [key1=value1 [key2=value2 [key3=value3 [...]]]] ``` -------------------------------- ### Matlab API - Control Source: https://www.gams.com/latest/docs/apis/matlab_control/functions_vars_f.html Documentation for the GAMS Matlab Control API, including getting started, tutorials, classes, and examples. ```APIDOC ## Matlab API - Control ### Description Provides programmatic control over GAMS from Matlab. ### Endpoint N/A (Library-based API) ### Parameters N/A ### Request Example N/A ### Response N/A ## Matlab API - Class Members ### Description Lists documented variables within the GAMS Matlab API, categorized by class. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Body N/A ### Response N/A ## Class: matlab.gams.control.Options ### Description Contains options for controlling GAMS execution via the Matlab API. ### Variables - **FDDelta** (Type: Unknown) - Description: Unknown - **FDOpt** (Type: Unknown) - Description: Unknown - **FErr** (Type: Unknown) - Description: Unknown - **FGHNumericNoScale** (Type: Unknown) - Description: Unknown - **FGHNumericScale** (Type: Unknown) - Description: Unknown - **FILE_SEPARATOR** (Type: Unknown) - Description: Unknown - **fileCase** (Type: Unknown) - Description: Unknown - **fileName** (Type: Unknown) - Description: Unknown - **FileOperationsAcceptedParameters** (Type: Unknown) - Description: Unknown - **fileStem** (Type: Unknown) - Description: Unknown - **fileStemApFromEnv** (Type: Unknown) - Description: Unknown - **filtered** (Type: Unknown) - Description: Unknown - **FirstRecord** (Type: Unknown) - Description: Unknown - **firstRecord** (Type: Unknown) - Description: Unknown - **FIXED** (Type: Unknown) - Description: Unknown - **FixedVarsNotTreatedAsConstants** (Type: Unknown) - Description: Unknown - **FixedVarsTreatedAsConstants** (Type: Unknown) - Description: Unknown - **FollowingError** (Type: Unknown) - Description: Unknown - **forceOptFile** (Type: Unknown) - Description: Unknown - **forceWork** (Type: Unknown) - Description: Unknown - **ForE** (Type: Unknown) - Description: Unknown - **ForEFloatingDec** (Type: Unknown) - Description: Unknown - **forLim** (Type: Unknown) - Description: Unknown - **FormfeedCharNewPage** (Type: Unknown) - Description: Unknown - **FortranStyle** (Type: Unknown) - Description: Unknown - **FREE** (Type: Unknown) - Description: Unknown - **freeEmbeddedPython** (Type: Unknown) - Description: Unknown - **full** (Type: Unknown) - Description: Unknown ### Request Example N/A ### Response Example N/A ``` -------------------------------- ### Execute GAMS C++ Example on Windows Source: https://www.gams.com/latest/docs/API_CPP_TUTORIAL.html Sets the library path and executes the transport1 example binary. ```bash cd transport1\Release set PATH=%PATH%;\apifiles\C++\lib\vs2019 transport1.exe ``` -------------------------------- ### GAMS Python API Source: https://www.gams.com/latest/docs/apis/python/functions_vars_u.html Documentation for the GAMS Python API, including getting started, control, magic (Jupyter Notebooks), transfer, and examples. ```APIDOC ## GAMS Python API ### Description Documentation for the GAMS Python API, covering its usage for controlling GAMS models and data transfer. ### Getting Started Information on how to begin using the Python API. ### Control Details on controlling GAMS execution and model parameters via the Python API. #### Classes ##### Class List Provides a list of all available classes. ##### Class Index An index of all classes. ##### Class Hierarchy Shows the inheritance hierarchy of classes. ##### Class Members ###### Functions Lists all documented functions. ###### Variables Lists all documented variables, including their class and type. * **Unbounded** (gams.control.workspace.ModelStat) * **UnboundedNoSolution** (gams.control.workspace.ModelStat) * **UnexpectedCmexRC** (gams.control.workspace.GamsExitCode) * **Unknown** (gams.control.workspace.VarType) * **Upper** (gams.control.execution.UpdateAction) * **UpperCase** (gams.control.options.Case, gams.control.options.FileCase) * **UpperCaseFileOnly** (gams.control.options.FileCase) * **User** (gams.control.workspace.SolveStat) ###### Properties Lists all documented properties. ### Magic (Jupyter Notebooks) Guidance on using the GAMS API within Jupyter Notebooks. ### Transfer Information on data transfer functionalities. ### Examples Code examples demonstrating various use cases of the Python API. ``` -------------------------------- ### Initialize Save/Restart Process Source: https://www.gams.com/latest/docs/API_DOTNET_TUTORIAL.html Sets up the working directory and initiates the creation of the save/restart file. ```csharp string wDir = Path.Combine(".", "tmp"); CreateSaveRestart(Path.Combine(wDir, "tbase")); ``` -------------------------------- ### Specify Connection String Source: https://www.gams.com/latest/docs/T_SQL2GMS.html Example of providing a connection string via the command line. ```text C="DSN=sample" ``` -------------------------------- ### Matlab API - Control Source: https://www.gams.com/latest/docs/apis/matlab_control/functions_q.html Documentation for the GAMS Matlab API, including control functionalities, getting started guides, tutorials, and class references. ```APIDOC ## Matlab API - Control ### Description Provides access to GAMS functionalities from Matlab, enabling control over GAMS execution and data transfer. ### Method N/A (This is documentation, not an executable endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## Matlab API - Class Reference ### Description Detailed documentation for classes within the GAMS Matlab API. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## Class: QCP ### Description Represents GAMS Options within the Matlab API. ### Class Members - **QCP** : matlab.gams.control.Options ``` -------------------------------- ### License Setup Source: https://www.gams.com/latest/docs/S_MOSEK.html Instructions for setting up a GAMS/MOSEK-Link license. ```APIDOC # Setting up a GAMS/MOSEK-Link license To use the GAMS/MOSEK solver with a GAMS/MOSEK-Link license you have save a MOSEK standalone license and point to the MOSEK license file via environment variable `MOSEKLM_LICENSE_FILE`. ``` -------------------------------- ### Python API - Getting Started Source: https://www.gams.com/latest/docs/apis/python/classgams_1_1control_1_1options_1_1HoldFixed.html Information on getting started with the GAMS Python API. ```APIDOC ## Python API - Getting Started ### Description This section provides guidance on how to begin using the GAMS Python API for model development and execution. ``` -------------------------------- ### XPRESS Option File Example Source: https://www.gams.com/latest/docs/S_XPRESS.html An example of a solver-specific option file used to configure XPRESS parameters. ```text * sample XPRESS options file defaultalg 3 presolve 0 IterLim 50000 ``` -------------------------------- ### Python API - Getting Started Source: https://www.gams.com/latest/docs/apis/python/classgams_1_1control_1_1options_1_1Filtered.html Information on getting started with the GAMS Python API. ```APIDOC ## Python API - Getting Started ### Description This section provides guidance on how to begin using the GAMS Python API for model execution and control. ``` -------------------------------- ### Python API - Getting Started Source: https://www.gams.com/latest/docs/apis/python/classgams_1_1control_1_1options_1_1ECLogLine.html Information on getting started with the GAMS Python API. ```APIDOC ## Python API - Getting Started This section covers the initial steps for using the GAMS Python API. ### Getting Started * Getting Started ``` -------------------------------- ### Configure IPOPT Options in ipopt.opt Source: https://www.gams.com/latest/docs/S_IPOPT.html Create an `ipopt.opt` file to set IPOPT algorithm parameters. Each line should contain an option name, whitespace, and its value. Comments start with '#'. ```text # This is a comment # Turn off the NLP scaling nlp_scaling_method none # Change the initial barrier parameter mu_init 1e-2 # Set the max number of iterations max_iter 500 ``` -------------------------------- ### Get GAMS installation directory Source: https://www.gams.com/latest/docs/apis/examples_java/Transport10_8java_source.html Retrieves the installation directory of GAMS. Appends the file separator if it's not already present. ```java String gamsdir = ws.systemDirectory(); if (!gamsdir.endsWith(GAMSGlobals.FILE_SEPARATOR)) gamsdir += GAMSGLOBALS.FILE_SEPARATOR; return gamsdir + "apifiles" + GAMSGLOBALS.FILE_SEPARATOR + "Data" + GAMSGLOBALS.FILE_SEPARATOR + "transport.xls"; ``` -------------------------------- ### Example of Listing Echo Source: https://www.gams.com/latest/docs/UG_DollarControlOptions.html Basic example of a set definition that would be echoed to the listing file. ```GAMS Set i /0234*0237/ ``` -------------------------------- ### Example: SOLVE RESOURCE using MIP with GAMSCHK Source: https://www.gams.com/latest/docs/S_GAMSCHK.html This example illustrates setting GAMSCHK as the MIP solver and then solving the 'RESOURCE' model maximizing 'PROFIT'. ```gams OPTION MIP=GAMSCHK; SOLVE RESOURCE USING MIP MAXIMIZING PROFIT; ``` -------------------------------- ### Include Headers for GAMS Example Source: https://www.gams.com/latest/docs/apis/examples_cpp/transport4_8cpp.html Include necessary headers for GAMS integration and standard C++ functionalities. This setup is required for the transport4 example. ```cpp #include "gams.h" #include #include #include #include ``` -------------------------------- ### Full GAMS Embedded Code Example Source: https://www.gams.com/latest/docs/T_LIBINCLUDE_PYEMBMI.html A complete example demonstrating model setup, scenario data, and the embedded Python function for solving. ```GAMS * GMSPYTHONLIB gets automatically set to use the internal Python installation in sysdir/GMSPython. $if not setEnv GMSPYTHONLIB $abort.noError Embedded code Python not ready to be used $log --- Using Python library %sysEnv.GMSPYTHONLIB% Set i 'canning plants' / seattle, san-diego / j 'markets' / new-york, chicago, topeka /; Parameter a(i) 'capacity of plant i in cases' / seattle 350 san-diego 600 / b(j) 'demand at market j in cases' / new-york 325 chicago 300 topeka 275 /; Table d(i,j) 'distance in thousands of miles' new-york chicago topeka seattle 2.5 1.7 1.8 san-diego 2.5 1.8 1.4; Scalar f 'freight in dollars per case per thousand miles' / 90 /; Parameter c(i,j) 'transport cost in thousands of dollars per case'; c(i,j) = f*d(i,j)/1000; Variable x(i,j) 'shipment quantities in cases' z 'total transportation costs in thousands of dollars'; Positive Variable x; Equation cost 'define objective function' supply(i) 'observe supply limit at plant i' demand(j) 'satisfy demand at market j'; cost.. z =e= sum((i,j), c(i,j)*x(i,j)); supply(i).. sum(j, x(i,j)) =l= a(i); demand(j).. sum(i, x(i,j)) =g= b(j); Model transport / all /; Set s 'scenarios to run' / base, run1, run2 /; Table newsupply(s,i) 'updater for a (capacity)' seattle san-diego base 350 600 run1 300 650 run2 400 550; Table newdemand(s,j) 'updater for b (demand)' new-york chicago topeka base 325 300 275 run1 325 300 275 run2 350 300 250; $set solverlog $if set useSolverLog $set solverlog output=sys.stdout embeddedCode Python: def solveMI(mi, symIn=[], symOut=[]): for sym in symIn: gams.db[sym].copy_symbol(mi.sync_db[sym]) mi.solve(%solverlog%) for sym in symOut: try: gams.db[sym].clear() # Explicitly clear the symbol to ensure setting "writtenTo" flag for sym ``` -------------------------------- ### Configure SHOT options file Source: https://www.gams.com/latest/docs/S_SHOT.html Example content for a shot.opt file defining solver strategies and output settings. ```text Dual.CutStrategy = 1 Dual.MIP.Solver = 2 Output.Console.DualSolver.Show = true ``` -------------------------------- ### Example: SOLVE FEED using LP with GAMSCHK Source: https://www.gams.com/latest/docs/S_GAMSCHK.html This example shows setting GAMSCHK as the LP solver and then solving the 'FEED' model minimizing 'COST'. ```gams OPTION LP=GAMSCHK; SOLVE FEED USING LP MINIMIZING COST; ``` -------------------------------- ### Test GAMS Installation via Terminal Source: https://www.gams.com/latest/docs/UG_MAC_INSTALL.html Execute these commands in the Terminal to verify your GAMS installation after setup. Ensure GAMS is added to your system's PATH. ```bash gamslib trnsport gams trnsport ``` -------------------------------- ### GET getModelText Source: https://www.gams.com/latest/docs/apis/examples_cpp/transport7_8cpp.html Retrieves the GAMS model definition as a string for the transport7 example. ```APIDOC ## GET getModelText ### Description Retrieves the GAMS model definition as a string, containing sets, parameters, variables, and equations for the transport7 model. ### Method GET ### Response #### Success Response (200) - **model_string** (string) - The full GAMS model definition as a string. #### Response Example { "model_string": " Sets \n i canning plants / seattle, san-diego / \n j markets / new-york, chicago, topeka / ; ..." } ``` -------------------------------- ### Initialize Save/Restart Process Source: https://www.gams.com/latest/docs/API_PY_CONTROL.html Sets up the working directory and triggers the creation of the save/restart file. ```python working_dir = os.path.join(os.curdir, "tmp") create_save_restart(sys_dir, os.path.join(working_dir, "tbase")) ``` -------------------------------- ### gmoGetMatrixCol Source: https://www.gams.com/latest/docs/apis/expert-level/gmoqdrep.html Get constraint matrix in column order with columns start only and NL indicator. ```APIDOC ## gmoGetMatrixCol ### Description Get constraint matrix in column order with columns start only and NL indicator. ### Parameters #### Path Parameters - **colstart** (PLongIntArray) - Required - Index of Jacobian column starts with - **rowidx** (PLongIntArray) - Required - Row index/indices of Jacobian - **jacval** (PDoubleArray) - Required - Value(s) of Jacobian(s) - **nlflag** (PLongIntArray) - Required - NL flag(s) of Jacobian(s) (0 : linear,!=0 : nonlinear) ### Response - **Returns** (Integer) ``` -------------------------------- ### Simple GAMS Server Implementation Source: https://www.gams.com/latest/docs/apis/examples_dotnet/annotated.html Demonstrates how to implement a simple GAMS Server and Client. The example shows how to serialize GAMSJob components, send them to the server, and process the results. ```C# /// /// This example demonstrates how to implement a simple GAMS Server. The example has two parts: GAMSServer and GAMSClient. The example is configured to run the client and server on the same machine, but can easily be altered to run on different machines. Both client and server need access to the GAMSRemoteClass that implements the server. The method to communicate is very simple. The client sets up the ingredients for a GAMSJob (model text, GDX input, parameters) and sends them serialized (via a byte representation of the GDX and parameter file) to the server. The server recreates the GAMS objects from the serialized representations, runs the model, and ships GAMSJob.OutDB serialized back to the client for further processing /// ``` -------------------------------- ### GAMS Search Query Examples Source: https://www.gams.com/latest/docs/apis/cpp/structgams_1_1GAMSOptions_1_1EForceWork-members.html Examples of search queries for GAMS documentation, covering different categories like User's Guide, Solvers, Tools, APIs, and Release Notes. ```APIDOC ## GAMS Search Query Examples ### Description Examples of how to use the search functionality to find specific GAMS resources. ### Query Examples - **User's Guide**: `q=User's Guide` - **Solvers**: `q=Solvers` - **Tools**: `q=Tools` - **APIs**: `q=APIs` - **Release Notes**: `q=Release Notes` - **Model Library**: `q=Model Library` - **Test Data**: `q=Test Data` - **EMP API**: `q=EMP API` - **FIN NOA PSOPT**: `q=FIN NOA PSOPT` ``` -------------------------------- ### Configure CBC Options File Source: https://www.gams.com/latest/docs/S_CBC.html Example content for a cbc.opt file to control solver behavior such as cut generation and perturbation settings. ```text cuts root perturbation off ``` -------------------------------- ### Demo1GUI Program.cs Example Source: https://www.gams.com/latest/docs/apis/examples_dotnet/FarmGUI_2Program_8cs_source.html Example C# code for the Program.cs file within the Demo1GUI project, demonstrating application entry point. ```APIDOC ## Program.cs (Demo1GUI) ### Description This C# code defines the entry point for the Demo1GUI Windows Forms application. ### Method `static void Main()` ### Endpoint N/A ### Request Body N/A ### Request Example ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Demo1GUI { static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } ``` ### Response N/A ``` -------------------------------- ### Markowitz Portfolio Optimization Example Source: https://www.gams.com/latest/docs/apis/examples_python/markowitz_8py.html This example plots the efficient frontier for Markowitz's portfolio selection problem, optimizing for return and risk. It utilizes the GamsModelInstance class and requires the Python package matplotlib to be installed. ```Python This is a small graphical program that plots the efficient frontier of Markowitz' portfolio selection problem with the two objectives return and risk. The example utilizes the GamsModelInstance class to solve the parameterized objective max lambda*return - (1-lambda)*risk in the most efficient way. This example requires the Python package matplotlib to be installed. Definition in file markowitz.py. ``` -------------------------------- ### Main function for Transport 10 example Source: https://www.gams.com/latest/docs/apis/examples_cpp/transport10_8cpp.html This is the main entry point for the Transport 10 example. It initializes the GAMS environment, loads data from Excel, sets up and solves a GAMS model, and prints the results. Ensure COM is initialized if using ActiveX. ```cpp int main | ( | int | _argc_ , ---|---|---|--- | | char * | _argv_[] ) 166{ 167 cout << "---------- Transport 10 --------------" << endl; 168 try { 169 ::CoInitialize(0); // initialize thread to use ActiveX (some systems may need CoInititializeEx) 170 171 GAMSWorkspaceInfo wsInfo; 172 if (argc > 1) 173 wsInfo.setSystemDirectory(argv[1]); 174 GAMSWorkspace ws(wsInfo); 175 176 // Creating the GAMSDatabase and fill with the workbook data 177 GAMSDatabase db = ws.addDatabase(); 178 QString fileName = QString::fromStdString(ws.systemDirectory())+ cPathSep + "apifiles" + cPathSep + "Data" + cPathSep + "transport.xlsx"; 179 180 QAxObject* excel = new QAxObject( "Excel.Application", 0 ); 181 QAxObject* workbooks = excel->querySubObject( "Workbooks" ); 182 QAxObject* workbook = workbooks->querySubObject( "Open(const QString&)", fileName ); 183 QAxObject* sheets = workbook->querySubObject( "Worksheets" ); 184 185 GAMSSet i = db.addSet("i", 1, "Plants"); 186 GAMSSet j = db.addSet("j", 1, "Markets"); 187 188 // read parameters 189 sheetToParameter(sheets, "capacity", db, "a", "Capacity", i); 190 sheetToParameter(sheets, "demand", db, "b", "Demand", j); 191 sheetToParameter(sheets, "distance", db, "d", "Distance", i, j); 192 193 // clean up and close up 194 workbook->dynamicCall("Close ()"); 195 excel->dynamicCall("Quit ()"); 196 197 198 // Create and run the GAMSJob 199 GAMSOptions opt = ws.addOptions(); 200 GAMSJob t10 = ws.addJobFromString(getModelText()); 201 opt.setDefine("gdxincname", db.name()); 202 opt.setAllModelTypes("xpress"); 203 t10.run(opt, db); 204 for (GAMSVariableRecord record : t10.outDB().getVariable("x")) 205 cout << "x(" << record.key(0) << "," << record.key(1) << "): level=" << record.level() << 206 " marginal=" << record.marginal() << endl; 207 208 ::CoUninitialize(); 209 210 } catch (GAMSException &ex) { 211 cout << "GAMSException occured: " << ex.what() << endl; 212 } catch (exception &ex) { 213 cout << ex.what() << endl; 214 } 215 216 return 0; 217} ``` -------------------------------- ### Get Elapsed Time in GAMS Source: https://www.gams.com/latest/docs/UG_Parameters.html Returns the total time in seconds that has passed since the GAMS run started. ```gams timeElapsed ``` -------------------------------- ### Example: Using a Trigonometric Library Source: https://www.gams.com/latest/docs/UG_ExtrinsicFunctions.html This example demonstrates loading the 'tricclib' library with the internal name 'myLib' and declaring its 'Cosine', 'Sine', and 'Pi' functions. It then uses these declared functions to calculate and display a scalar value. ```gams $funcLibIn myLib tricclib Function myCos /myLib.Cosine/ mySin /myLib.Sine/ myPi /myLib.Pi/; Scalar d; d = myCos(myPi/3); display d; ``` -------------------------------- ### Get Process ID of Last Job Source: https://www.gams.com/latest/docs/UG_Parameters.html Returns the process ID (PID) of the most recently started GAMS job. ```gams jobHandle ``` -------------------------------- ### Basic GUSS Scenario Setup Source: https://www.gams.com/latest/docs/S_GUSS.html Example of defining a GUSS dictionary to solve a DEA model across multiple scenarios. ```GAMS Variable eff 'efficiency'; Equations defe 'efficiency definition - weighted output' denom 'weighted input' lime(i) 'output / input < 1'; defe.. eff =e= sum(jo, u(jo)*slice(jo)); denom.. sum(ji, v(ji)*slice(ji)) =e= 1; lime(i).. sum(jo, u(jo)*data(i,jo)) =l= sum(ji, v(ji)*data(i,ji)); model dea /defe, denom, lime /; set headers 'report' / modelstat, solvestat, objval /; parameter scenrep(k,headers) 'solution report summary' scopt / SkipBaseCase 1 /; set dict / k .scenario.'' slice .param. data eff .level. eff_k scopt .opt. scenrep /; slice(j) = 0; option lp=cplex; solve dea using lp max eff scenario dict; display scenrep,eff_k; ``` -------------------------------- ### Creating a solver option file Source: https://www.gams.com/latest/docs/UG_Put.html Example showing how to create and close a solver option file for MINOS. ```GAMS File opt 'Minos option file' / minos.opt /; put opt 'Iteration limit 500'/ 'Feasibility tolerance 1.0E-7'/ ; putclose opt; ``` ```GAMS putclose opt 'Iteration limit 500'/ 'Feasibility tolerance 1.0E-7'/ ; ``` -------------------------------- ### C# .NET Control API Example: Tsp.cs Source: https://www.gams.com/latest/docs/apis/examples_dotnet/dir_4792ddf36049cb83fe2b5e7ad925b420.html This C# code snippet is part of the .NET Control API examples, specifically demonstrating the Tsp (Traveling Salesperson Problem) functionality. It requires the GAMS .NET API to be installed and configured. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Gams { public class Tsp { public Tsp() { } public void Run() { // TODO: Implement Tsp logic here } } } ``` -------------------------------- ### Verifying Gurobi license setup Source: https://www.gams.com/latest/docs/S_GUROBI.html Commands and expected output when solving a model to verify that the Gurobi license is correctly configured. ```bash $ gamslib indus89 Copy ASCII : indus89.gms $ gams indus89 lp gurobi --- Job indus89 Start 09/01/20 12:41:41 32.2.0 rc62c018 LEX-LEG x86 64bit/Linux [...] Gurobi 32.2.0 rc62c018 Released Aug 26, 2020 LEG x86 64bit/Linux Gurobi link license. Gurobi library version 9.0.3 [...] Iteration Objective Primal Inf. Dual Inf. Time 0 7.1618935e+31 2.041808e+32 7.161894e+01 0s 2990 1.1487366e+05 0.000000e+00 0.000000e+00 0s Solved in 2990 iterations and 0.32 seconds Optimal objective 1.148736556e+05 User-callback calls 3040, time in user-callback 0.00 sec LP status(2): Model was solved to optimality (subject to tolerances). --- Reading solution for model wsisn *** Status: Normal completion --- Job indus89.gms Stop 09/01/20 12:29:49 elapsed 0:00:00.835 ``` -------------------------------- ### Define an Ill-Defined MCP Model in GAMS Source: https://www.gams.com/latest/docs/S_PATH.html Example of a model where the function is undefined at the default starting point x=0, requiring an explicit initial value. ```GAMS positive variable x; equations F; F.. 1 / x =g= 0; model simple / F.x /; x.l = 1e-6; solve simple using mcp; ``` -------------------------------- ### Display Initial Echo Print Listing Source: https://www.gams.com/latest/docs/UG_GAMSOutput.html Example of the initial compilation listing showing line numbers for empty lines and comments. ```text A Quadratic Programming Model for Portfolio Analysis (ALAN,SEQ=124a) C o m p i l a t i o n 2 4 This is a mini mean-variance portfolio selection problem described in 'GAMS/MINOS:Three examples' by Alan S. Manne, Department of Operations Research, Stanford University, May 1986. 10 11 * This model has been modified for use in the documentation ``` -------------------------------- ### Get First GAMS Set Record Source: https://www.gams.com/latest/docs/apis/examples_dotnet/TestGAMSSymbol_8cs_source.html Retrieves the first record of a GAMS set. This is commonly used as the starting point for iterating through the elements of a set. ```csharp new GAMSSetRecord FirstRecord() ``` -------------------------------- ### Execute GAMS C++ Example on Linux Source: https://www.gams.com/latest/docs/API_CPP_TUTORIAL.html Configures the library path and runs the transport1 example. ```bash cd transport1 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/apifiles/C++/lib ./transport1 ``` -------------------------------- ### Get First GAMS Parameter Record Source: https://www.gams.com/latest/docs/apis/examples_dotnet/TestGAMSSymbol_8cs_source.html Retrieves the first record of a GAMS parameter. This is typically used as the starting point for iterating over parameter data. ```csharp new GAMSParameterRecord FirstRecord() ``` -------------------------------- ### Initialize and use a GAMSDatabase with GAMSJob Source: https://www.gams.com/latest/docs/apis/dotnet/classGAMS_1_1GAMSDatabase.html Demonstrates creating a database, defining it in GAMS options, and passing it to a GAMS job run. ```csharp GAMSDatabase db = workspace.AddDatabase(); GAMSOptions opt = workspace.AddOptions(); opt.Defines.Add("SupplyDataFileName",db.Name); ... gamsjob.Run(opt, db); ``` -------------------------------- ### Get First GAMS Equation Record Source: https://www.gams.com/latest/docs/apis/examples_dotnet/TestGAMSSymbol_8cs_source.html Retrieves the first record associated with a GAMS equation. This is often used to start iterating through the records of an equation. ```csharp new GAMSEquationRecord FirstRecord() ``` -------------------------------- ### Rank Tool - Usage and Examples Source: https://www.gams.com/latest/docs/T_ALG_RANK.html Provides details on how to use the 'alg.Rank' tool via command line, compile time, and execution time, along with a practical example. ```APIDOC ## alg.Rank Tool ### Description This tool sorts a one-dimensional symbol `sym` and stores the sorted indices in a one-dimensional parameter `symIdx`. ### Method Command line, Compile time, or Execution time ### Endpoint `gamstool [alg.]Rank sym symIdx gdxIn=fileIn.gdx gdxOut=fileOut.gdx` (Command line) `$callTool [alg.]Rank sym symIdx [gdxIn=fileIn.gdx] [gdxOut=fileOut.gdx]` (Compile time) `executeTool '[alg.]Rank sym symIdx [gdxIn=fileIn.gdx] [gdxOut=fileOut.gdx]'` (Execution time) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Arguments - **sym** (string) - Required - Name of parameter or set to be sorted `sym(*)` - **symIdx** (string) - Required - Name of parameter containing sort indexes `symIdx(*)` ### Named Parameters - **gdxIn=fileIn.gdx** (string) - Optional - Name of GDX file that contains symbol sym. Mandatory if called from the command line, otherwise optional. - **gdxOut=fileOut.gdx** (string) - Optional - Name of GDX file that contains symbol symIdx after execution. Mandatory if called from the command line, otherwise optional. ### Request Example ``` set I /i1 * i6/; parameter A(I) /i1=+Inf, i2=-Inf, i3=Eps, i4= 10, i5=30, i6=20/; parameter AIndex(i) 'permutation index'; * sort symbol; result in parameter AIndex $callTool.checkErrorLevel 'alg.Rank A AIndex' display AIndex; ``` ### Response #### Success Response (200) Sorted indices are stored in the `symIdx` parameter. #### Response Example ```json { "AIndex": { "i1": 1, "i2": 2, "i3": 3, "i4": 4, "i5": 6, "i6": 5 } } ``` ### Note This tool is part of the GAMS Tools Library. Please inspect the general information about GAMS Tools. The complete example is also part of the GAMS Data Utilities Library, see model [GDXRANKExample18] for reference. The libInclude rank.gms uses this tool internally. ``` -------------------------------- ### DICOPT Reading Option File Example Source: https://www.gams.com/latest/docs/S_DICOPT.html Illustrates the log messages when DICOPT reads an option file, showing the file being read and the start of the major iteration. ```text --- DICOPT: Reading option file D:\MODELS\SUPPORT\DICOPT.OPT > maxcycles 10 --- DICOPT: Starting major iteration 1 ```