Package 'rampl'

Title: Tools to work with AMPL from R
Description: Tools to work with AMPL from R. Writing AMPL dat files, running AMPL locally or using the NEOS solvers.
Authors: Sebastian Kranz
Maintainer: Sebastian Kranz <[email protected]>
License: GPL (>= 2)
Version: 0.02
Built: 2024-12-17 02:55:10 UTC
Source: https://github.com/skranz/rampl

Help Index


Generates an AMPL data file

Description

Generates a AMPL 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

ampl.make.dat.file(...)

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


Generate a default run file for a given AMPL model

Description

Generate a default run file for a given AMPL model

Usage

ampl.make.run.file(name, run.name = name, options = "", var.out = NULL,
  neos = FALSE, path = getwd(), mod.file = paste(path, "/", name, ".mod",
  sep = ""), run.file = paste(path, "/", run.name, ".run", sep = ""),
  dat.file = paste(path, "/", run.name, ".dat", sep = ""))

Arguments

neos

if true a run file for the neos server is created, otherwise for a local call to AMPL

path

path in which mod.file, dat.file and run.file can be found


Solves an AMPL model using a local installation of AMPL

Description

You need to have a local AMPL installation with the corresponding solvers. It is assumed that a call to ampl finds the executable file, i.e. in Windows you have to add the AMPL directory to the system PATH variable

Usage

ampl.run.local(name = "", path = getwd(), run.file = paste(path, "/",
  name, ".run", sep = ""), display = TRUE)

Examples

## Not run: 
  # Model of power plant investments and dispatch included in package
  mod.file = paste(.path.package(package = "rampl"),"/data/cournot.mod",sep="")
  dat.file = paste(.path.package(package = "rampl"),"/data/cournot.dat",sep="")
  run.file = paste(getwd(),"/cournot.run",sep="")
  
  ampl.make.run.file(name="cournot", options=c("option solver minos;"), mod.file=mod.file,dat.file=dat.file,run.file=run.file)
  ret = ampl.run.local(name="cournot", display=TRUE, run.file=run.file)
  ret
  
  # Solve for different parameter values
  n = 2
  sets = list(N=1:n)
  param = list(a=1,b=1,c=c(0.1,0.1))
  
  dat.file = paste(getwd(),"/cournot.dat",sep="")
  run.file = paste(getwd(),"/cournot.run",sep="")
  ampl.make.run.file(name="cournot", options=c("option solver minos;"), mod.file=mod.file,dat.file=dat.file,run.file=run.file)
  
  solve.cournot = function(c1=0,c2=0) {
    param$c = c(c1,c2)
    ampl.make.dat.file(mod.file=mod.file,dat.file=dat.file,sets = sets, param=param)
    ret = ampl.run.local(name="cournot", display=FALSE, run.file=run.file)
    t(ret$q)
  }
  solve.cournot(c1=0.1,c2=0)
  library(sktools)
  ret = run.scenarios(solve.cournot, par=list(c1=seq(0,1,length=10),c2=0))
  colnames(ret)=c("scen.id","c1","c2","q1","q2")
  ret

## End(Not run)

Solves an AMPL model remotely using the NEOS Server

Description

Solves an AMPL model remotely using the NEOS Server

Usage

ampl.run.neos(name = "", category = "cp", solver = "PATH",
  path = getwd(), wait = TRUE, mod.file = paste(path, "/", name, ".mod",
  sep = ""), dat.file = paste(path, "/", name, ".dat", sep = ""),
  run.file = paste(path, "/", name, ".run", sep = ""),
  log.file = paste(path, "/log_", name, "_", solver, ".txt", sep = ""))

Arguments

name

the model name

category

category of the optimization problem, call neos.ampl.solvers() for an overview

solver

desired solver, call neos.ampl.solvers() for a list

path

path in which mod.file, dat.file and run.file can be found

wait

default=TRUE shall R wait until NEOS returns the solution (may take some time)

Examples

## Not run: 
  # Model of power plant investments and dispatch included in package
  mod.file = paste(.path.package(package = "rampl"),"/data/cournot.mod",sep="")
  dat.file = paste(.path.package(package = "rampl"),"/data/cournot.dat",sep="")
  run.file = paste(getwd(),"/cournot.run",sep="")
  ampl.make.run.file(name="cournot", neos=TRUE, mod.file=mod.file,dat.file=dat.file,run.file=run.file, options=c(""))
  ret = ampl.run.neos(name="cournot", category="nco", solver="MINOS", mod.file=mod.file, dat.file=dat.file, run.file=run.file)
  ret
  
  # Solve for different parameter values
  n = 2
  sets = list(N=1:n)
  param = list(a=1,b=1,c=c(0.1,0.1))
  
  dat.file = paste(getwd(),"/cournot.dat",sep="")
  run.file = paste(getwd(),"/cournot.run",sep="")
   
  solve.cournot = function(c1=0,c2=0, neos=FALSE) {
    param$c = c(c1,c2)
    ampl.make.dat.file(mod.file=mod.file,dat.file=dat.file,sets = sets, param=param)

    if (!neos) {
      
       ampl.make.run.file(name="cournot", options=c("option solver minos;"), mod.file=mod.file,dat.file=dat.file,run.file=run.file)
      ret = ampl.run.local(name="cournot", display=FALSE, run.file=run.file)
    
    } else {
      ampl.make.run.file(name="cournot", neos=TRUE, mod.file=mod.file,dat.file=dat.file,run.file=run.file, options=c(""))
      ret = ampl.run.neos(name="cournot", category="nco", solver="MINOS", mod.file=mod.file, dat.file=dat.file, run.file=run.file)
    }
    t(ret$q)
  }
  solve.cournot(c1=0.1,c2=0, neos=TRUE)
  

## End(Not run)

Quickly splits strings by a fixed pattern

Description

Quickly splits strings by a fixed pattern

Usage

fast_str_split_fixed(pattern, text, ncol = NULL, ...)

Returns a list of availble solver for AMPL on NEOS

Description

Returns a list of availble solver for AMPL on NEOS

Usage

neos.ampl.solvers()

Examples

## Not run: 
  neos.ampl.solvers()

## End(Not run)