High level R interface to the CPLEX_LP, MATHPROG and MPS reader of the GNU Linear
Programming Kit (GLPK). Example data from the GLPK release is included
in the './examples/' sub-directory.
Usage
## File reader for various formats
Rglpk_read_file(file, type = c("MPS_fixed", "MPS_free", "CPLEX_LP", "MathProg"),
ignore_first_row = FALSE, verbose = FALSE)
## print method
## S3 method for class 'MP_data_from_file'
print(x, ...)
Arguments
file
a character string specifying the relative or absolute path to
the model file.
type
a character string specifying the file format. This can be either
"MPS_fixed", "MPS_free", "CPLEX_LP", and
GNU "MathProg".
ignore_first_row
a logical indicating whether the first row of
the model file should be ignored or not.
Default: FALSE.
verbose
a logical for turning on/off additional solver output.
Default: FALSE.
x
an object of class "MP_data_from_file".
...
further arguments passed on to the print method.
Details
Rglpk_read_file() takes the path to a file as an
argument and calls GLPK's file reader. The description of the linear or
mixed integer linear program is returned as an object of class
"MP_data_from_file".
Value
Rglpk_read_file() returns the specification of a (mixed integer)
linear program defined in file as an object of class
"MP_data_from_file". The returned object is a list containing
the following components.
objective
a "simple_triplet_matrix" representing the coefficients to x in the objective function.
constraints
a list with three elements: a
"simple_triplet_matrix" of coefficients, a character
vector of constraint directions, and a numeric vector representing the
right hand side.
bounds
a list containing two elements: lower and
upper. Each of which contain a list specifying indices
(ind) and corresponding bounds (val).
types
a character vector specifying whether the corresponding
objective variable is of type binary ("B"), continuous
("C"), or integer ("I").
maximum
a logical indicating whether a minimum or a maximum is sought.
Further meta data is provided as attributes to the object.
Author(s)
Stefan Theussl
Examples
## read a CPLEX LP file
x <- Rglpk_read_file( system.file(file.path("examples", "plan.lp"), package
= "Rglpk"), type = "CPLEX_LP")
x
## optimal solution: 296.2166
Rglpk_solve_LP(x$objective, x$constraints[[1]], x$constraints[[2]],
x$constraints[[3]], x$bounds, x$types, x$maximum)
## read a MATHPROG file
x <- Rglpk_read_file( system.file(file.path("examples", "assign.mod"), package
= "Rglpk"), type = "MathProg")
x
## optimal solution: 76
Rglpk_solve_LP(x$objective, x$constraints[[1]], x$constraints[[2]],
x$constraints[[3]], x$bounds, x$types, x$maximum)
## read a MATHPROG file
x <- Rglpk_read_file( system.file(file.path("examples", "plan.mps"), package
= "Rglpk"), type = "MPS_fixed")
x
## optimal solution: 296.2166
Rglpk_solve_LP(x$objective, x$constraints[[1]], x$constraints[[2]],
x$constraints[[3]], x$bounds, x$types, x$maximum)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Rglpk)
Error in library(Rglpk) : there is no package called 'Rglpk'
Execution halted