Package 'rgmpl'

Title: Helps solving in R linear programming models specified in GMPL
Description: Tools that help to solve linear programming models specified in GMPL
Authors: Sebastian Kranz
Maintainer: Sebastian Kranz <[email protected]>
License: GPL (>= 2)
Version: 0.04
Built: 2024-11-20 02:48:15 UTC
Source: https://github.com/skranz/rgmpl

Help Index


Solve a GLPK linear problem

Description

Solve a GLPK linear problem

Usage

glpk.solve(lp = NULL, delete.lp = TRUE)

Arguments

lp

a GLPK problem generated e.g. by a call to gmpl.load.problem

delete.lp

default = TRUE shall the problem lp be removed from memory after it has been solved?


Internal function that gets a list with sets, variables and parameters of a GMPL model

Description

Internal function that gets a list with sets, variables and parameters of a GMPL model

Usage

gmpl.get.model.info(mod.file)

Arguments

mod.file

path of the .mod file in which the gmpl model is specified


Load a GMPL model and data and generate a GLPK object

Description

Load a GMPL model and data and generate a GLPK object

Usage

gmpl.load.problem(mod.file, dat.file)

Generates a GMPL data file

Description

Generates a GMPL data file for the model specified in dat.file sets and param are lists that contain the values of the sets and parameters that are specified in the GMPL model

Usage

gmpl.make.dat.file(sets = NULL, param = NULL, mod.file, dat.file = NULL)

Arguments

sets

a list with the sets used by the gmpl model

param

a list with the parameters used by the gmpl model

mod.file

path of the .mod file in which the gmpl model is specified

dat.file

path of the .dat file in which the data shall be written

Examples

## Not run: 
  
  # Model of power plant investments and dispatch included in package
  mod.file = paste(.path.package(package = "rgmpl"),"/data/power.mod",sep="")
    
  # Name of dat file, will be generated locally
  dat.file = "power.dat"
  
  # Example data
  
  # Sets
  PLANTS = c("coal","gas")
  PERIODS = 1:4
  sets = list(PLANTS=PLANTS,PERIODS=PERIODS)
  
  # Parameters
  fc = c(12,6)  # fixed cost 
  vc = c(18,30) # variable cost
  load = c(30,50,25,20) # electricity demand
  T = length(PERIODS)
  param = list(vc=vc,fc=fc,load=load,T=T)
  
  # Generate a GMPL .dat file
  gmpl.make.dat.file(sets=sets,param=param,mod.file=mod.file, dat.file=dat.file)
  
  # Solve the model
  res = gmpl.solve(mod.file=mod.file,dat.file=dat.file, delete.lp =FALSE)
  res
  
  # Show production levels graphically
  library(ggplot2)
  qplot(data=res$sol$q, x=PERIODS,y=q,fill=PLANTS,geom="bar",stats="identity", xlab="Period",ylab="Production")
  

## End(Not run)

Solve a GMPL problem using glpkAPI

Description

Solve a GMPL problem using glpkAPI

Usage

gmpl.solve(mod.file = NULL, dat.file = NULL, sets = NULL, param = NULL,
  lp = NULL, delete.lp = is.null(lp), adapt.sol = TRUE)

Arguments

mod.file

path of the .mod file in which the gmpl model is specified

dat.file

path of the .dat file in which the gmpl data is specified. If NULL generate a new .dat file from the given sets and param with the same name as the model file

sets

a list with the sets used by the gmpl model. Needed if no dat.file specified

param

a list with the parameters used by the gmpl model. Needed if no dat.file specified

lp

optional a link to the GLPK problem generated by gmpl.load.problem

delete.lp

default = TRUE if lp is given, shall it be removed from memory after it has been solved?

adapt.sol

default = TRUE shall the solution be returned in a more convenient form

Examples

## Not run: 
  
  # Model of power plant investments and dispatch included in package
  mod.file = paste(.path.package(package = "rgmpl"),"/data/power.mod",sep="")
    
  # Name of dat file, will be generated locally
  dat.file = "power.dat"
  
  # Example data
  
  # Sets
  PLANTS = c("coal","gas")
  PERIODS = 1:4
  sets = list(PLANTS=PLANTS,PERIODS=PERIODS)
  
  # Parameters
  fc = c(12,6)  # fixed cost 
  vc = c(18,30) # variable cost
  load = c(30,50,25,20) # electricity demand
  T = length(PERIODS)
  param = list(vc=vc,fc=fc,load=load,T=T)
  
  # Generate a GMPL .dat file
  gmpl.make.dat.file(sets=sets,param=param,mod.file=mod.file, dat.file=dat.file)
  
  # Solve the model
  res = gmpl.solve(mod.file=mod.file,dat.file=dat.file, delete.lp =FALSE)
  res
  
  # Show production levels graphically
  library(ggplot2)
  qplot(data=res$sol$q, x=PERIODS,y=q,fill=PLANTS,geom="bar",stats="identity", xlab="Period",ylab="Production")
  

## End(Not run)

Paste together columns of a matrix or data.frame

Description

Paste together columns of a matrix or data.frame

Usage

paste.matrix.cols(mat, cols = 1:NCOL(mat), ...)