Title: | A Data Interface Between 'GAMS' and R |
---|---|
Description: | Read, analyze, modify, and write 'GAMS' (General Algebraic Modeling System) data. The main focus of 'gamstransfer' is the highly efficient transfer of data with 'GAMS' <https://www.gams.com/>, while keeping these operations as simple as possible for the user. The transfer of data usually takes place via an intermediate GDX (GAMS Data Exchange) file. Additionally, 'gamstransfer' provides utility functions to get an overview of 'GAMS' data and to check its validity. |
Authors: | Atharv Bhosekar [aut, cre], GAMS Development Corp. [cph, fnd], GAMS Software GmbH [cph, fnd] |
Maintainer: | Atharv Bhosekar <[email protected]> |
License: | MIT + file LICENSE |
Version: | 3.0.4 |
Built: | 2024-10-26 05:57:06 UTC |
Source: | https://github.com/gams-dev/transfer-r |
An abstract symbol class from which the classes Set, Parameter, Variable, and Equation are inherited. Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
A class for Alias objects. Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
# create a container m <- Container$new() # add a set i <- Set$new(m, "i") # add an alias to the set "i" ii <- Alias$new(m, "ii", i)
# create a container m <- Container$new() # add a set i <- Set$new(m, "i") # add an alias to the set "i" ii <- Alias$new(m, "ii", i)
The main object class within GAMS Transfer is called Container. The Container is the vessel that allows symbols to be linked together (through their domain definitions), it enables implicit set definitions, it enables structural manipulations of the data (matrix generation), and it allows the user to perform different read/write operations. Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
Create a new container simply by initializing an object.
loadFrom |
optional argument to point to the GDX file being read into the Container |
data
is a named list containing all symbol data
m <- Container$new() i <- m$addSet("i") j <- m$addSet("j") all_symbols <- m$listSymbols() set_description <- m$describeSets() # create a container and read the file trnsport.gdx m = Container$new(system.file("extdata", "trnsport.gdx", package = "gamstransfer")) # access symbol named "x" from the container x = m["x"] # list all symbols all_symbols = m$listSymbols() # list all sets all_sets = m$listSets() # check if the container contains symbol named "i" has_i = m$hasSymbols("i") # get a summary of the description of all sets in the Container set_description = m$describeSets()
m <- Container$new() i <- m$addSet("i") j <- m$addSet("j") all_symbols <- m$listSymbols() set_description <- m$describeSets() # create a container and read the file trnsport.gdx m = Container$new(system.file("extdata", "trnsport.gdx", package = "gamstransfer")) # access symbol named "x" from the container x = m["x"] # list all symbols all_symbols = m$listSymbols() # list all sets all_sets = m$listSets() # check if the container contains symbol named "i" has_i = m$hasSymbols("i") # get a summary of the description of all sets in the Container set_description = m$describeSets()
Contains information about the domain violation for a symbol. Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
symbol
symbol name
dimension
dimension in which domain violation is present
domain
domain name
violations
vector of violations
m <- Container$new() i <- Set$new(m, "i", records = paste0("i", 1:5)) p <- Parameter$new(m, "p", i, records = data.frame(i = c("i1", "i3", "i6"), value = c(1, 5, 7))) dv <- p$getDomainViolations()[[1]] sym_dv <- dv$symbol dim_dv <- dv$dimension domain_dv <- dv$domain violation_dv <- dv$violations
m <- Container$new() i <- Set$new(m, "i", records = paste0("i", 1:5)) p <- Parameter$new(m, "p", i, records = data.frame(i = c("i1", "i3", "i6"), value = c(1, 5, 7))) dv <- p$getDomainViolations()[[1]] sym_dv <- dv$symbol dim_dv <- dv$dimension domain_dv <- dv$domain violation_dv <- dv$violations
A class for Equation objects. This class inherits from an abstract symbol class.The documentation for methods common to all symbols can be accessed via help(.Symbol). Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
# create a container m <- Container$new() # add a Variable e <- Equation$new(m, "v", type = "eq") # access records e_recs <- e$records
# create a container m <- Container$new() # add a Variable e <- Equation$new(m, "v", type = "eq") # access records e_recs <- e$records
A class for Parameter objects. This class inherits from an abstract Symbol class.The documentation for methods common to all symbols can be accessed via help(.Symbol). Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
# create a container m <- Container$new() # add a Parameter p <- Parameter$new(m, "p") # access records p_recs <- p$records
# create a container m <- Container$new() # add a Parameter p <- Parameter$new(m, "p") # access records p_recs <- p$records
read a GDX file to a list without creating symbol or container objects
readGDX(loadFrom, symbols = NULL, records = TRUE)
readGDX(loadFrom, symbols = NULL, records = TRUE)
loadFrom |
name of the GDX file being read (string) |
symbols |
optional argument - vector of strings containing the symbol names to be read |
records |
optional logical argument - TRUE (default) to read the symbol records, FALSE to only read the meta data. Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package. |
read_list <- readGDX(system.file("extdata", "trnsport.gdx", package = "gamstransfer"))
read_list <- readGDX(system.file("extdata", "trnsport.gdx", package = "gamstransfer"))
A class for Set objects. This class inherits from an abstract Symbol class. The documentation for methods common to all symbols can be accessed via help(.Symbol). Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
# create a container m <- Container$new() # add a set i <- Set$new(m, "i") # access records i_recs <- i$records
# create a container m <- Container$new() # add a set i <- Set$new(m, "i") # access records i_recs <- i$records
This list contains GAMS special values and helper functions to check if a given value is a GAMS special value. Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
SpecialValues
SpecialValues
An object of class list
of length 10.
# check the value of GAMS special value NA NA_val <- SpecialValues[["NA"]] # check the value of GAMS special value EPS EPS_val <- SpecialValues[["EPS"]] # check if a value is GAMS special value `NA` isNA_check <- SpecialValues$isNA(0)
# check the value of GAMS special value NA NA_val <- SpecialValues[["NA"]] # check the value of GAMS special value EPS EPS_val <- SpecialValues[["EPS"]] # check if a value is GAMS special value `NA` isNA_check <- SpecialValues$isNA(0)
A class for Alias objects that are aliased to the Universe set. Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
#' @examples # create a container m = Container$new() # add a UniverseAlias u = UniverseAlias$new(m, "u")
A class for Variable objects. This class inherits from an abstract Symbol class. Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package.
# create a container m <- Container$new() # add a Variable v <- Variable$new(m, "v") # access records v_recs <- v$records
# create a container m <- Container$new() # add a Variable v <- Variable$new(m, "v") # access records v_recs <- v$records
write a GDX file from a list containing symbol data and metadata
writeGDX( writeList, writeTo, symbols = NULL, compress = FALSE, uelPriority = NULL, mode = NULL )
writeGDX( writeList, writeTo, symbols = NULL, compress = FALSE, uelPriority = NULL, mode = NULL )
writeList |
list containing symbol data and metadata |
writeTo |
name of the output GDX file |
symbols |
optional argument - vector of strings containing the symbol names to be read |
compress |
optional logical argument. TRUE to produce a compressed GDX file |
uelPriority |
Specify the priority UELs |
mode |
optional string argument to specify the write mode ("string", "mapped"). Please visit https://transfer-r.readthedocs.io/en/latest/ for detailed documentation of this package. |
writeGDX(list(), tempfile(fileext = ".gdx"))
writeGDX(list(), tempfile(fileext = ".gdx"))