Gurobi optimizer with R¶
Gurobi optimizer is a problem solving software that can be used within R. It can solve integer, linear, and quadratic programming optimizations. These techniques can help to find the answers to complex models.
Example of running Gurobi optimizer with R at CARC¶
There are modules for both Gurobi and R on the CARC clusters. All you need to do is load them, and then start an R
session. This command is for version 8.1.0, however there are other versions of gurobi available (enter module avail gurobi to see a full list).
username@hopper:~$ module load gurobi/8.1.0
username@hopper:~$ module load r-3.6.0-gcc-7.3.0-python2-7akol5t
username@hopper:~$ R
Start by installing the gurobi package:
> install.packages('/opt/local/gurobi/8.1.0/linux64/R/gurobi_8.1-0_R_3.5.0.tar.gz')
Installing package into '/users/username/R/x86_64-pc-linux-gnu-library/3.6'
* installing *binary* package 'gurobi' ...
* DONE (gurobi)
> model <- list()
> model$A <- matrix(c(1,2,3,1,1,0), nrow=2, ncol=3, byrow=T)
> model$obj <- c(1,1,2)
> model$modelsense <- 'max'
> model$rhs <- c(4,1)
> model$sense <- c('<', '>')
> model$vtype <- 'B'
> params <- list(OutputFlag=0)
> result <- gurobi(model, params)
> print('Solution:')
[1] "Solution:"
> print(result$objval)
[1] 3
> print(result$x)
[1] 1 0 1
Migrated from UNM-CARC QuickBytes (last source update 2021-02-17). Spotted a problem? Open an issue or pull request.