gamstransfer#

GAMS Transfer is a package to maintain GAMS data outside a GAMS script in a programming language like Python, Matlab, or R. It allows the user to add GAMS symbols (Sets, Aliases, Parameters, Variables and Equations), to manipulate GAMS symbols, as well as read/write symbols to different data endpoints. GAMS Transfer’s main focus is the highly efficient transfer of data between GAMS and the target programming language, while keeping those operations as simple as possible for the user. In order to achieve this, symbol records - the actual and potentially large-scale data sets - are stored in native data structures of the corresponding programming languages. The benefits of this approach are threefold: (1) The user is usually very familiar with these data structures, (2) these data structures come with a large tool box for various data operations, and (3) optimized methods for reading from and writing to GAMS can transfer the data as a bulk - resulting in the high performance of this package.

Design Philosophy#

Container#

Storing, manipulating, and transforming sparse data requires that it lives within an environment. This data can then be linked together to enable various operations. In GAMS Transfer R, we refer to this “environment” as the Container, it is the main repository for storing and linking our data. Linking data enables data operations such as implicit set growth, domain checking, and data format transformations (to dense/sparse matrix formats). A Container also enables different read/write operations.

Symbols#

In GAMS Transfer R, a symbol is either a GAMS Set, Parameter, Variable, Equation, Alias. In GAMS Transfer R, a symbol cannot live on its own, but is always part of a Container.

Create a symbol#

There are two different ways to create a GAMS set and add it to a Container.

1. Use symbol constructor for Set, Parameter, Variable, Equation, Alias

library(gamstransfer)
m <- Container$new()
p <- Parameter$new(m, "p")

2. Use the Container methods “addSet”, “addParameter”, “addVariable”, “addEquation”, “addAlias” (which internally calls the symbol constructor)

library(gamstransfer)
m <- Container$new()
p <- m$addParameter$new("p")

Add Symbol Records#

Three possibilities exist to assign symbol records: 1. Setting the argument records in the symbol constructor (internally calls setRecords) 2. Using the symbol method setRecords 3. Setting the field records directly

If the data is in a convenient format, a user may want to pass the records directly within the set constructor. This is an optional keyword argument and internally the symbol constructor will simply call the setRecords method. The symbol method setRecords is a convenience method that transforms the given data into an approved data frame format (see Standard Data Formats). Many native R data types can be easily transformed into data frames, so the setRecords method will accept a number of different types for input. The setRecords method is called internally on any data structure that is passed through the records argument.

The examples of setting records using the above-mentioned methods can be found in the respective documentation for each symbol ( adding set records, adding parameter records, adding variable records, adding vquation records, and adding alias records ).