Created
September 29, 2022 15:10
-
-
Save berkorbay/c8ce07e7a34080badeee7d96b6e1101f to your computer and use it in GitHub Desktop.
R example of modelling with HiGHS solver and ompr framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####### | |
### This is a minimal example of using HiGHS solver in R with the help of ROI and ompr packages. | |
####### | |
## SETUP BEGIN | |
pti <- c("ompr.roi","ompr","highs","devtools") | |
pti <- pti[!(pti %in% installed.packages())] | |
if(length(pti) > 0){ | |
install.packages(pti) | |
} | |
if(!("ROI.plugin.highs" %in% installed.packages())){ | |
devtools::install_gitlab("roigrp/solver/roi.plugin.highs") | |
} | |
## SETUP END | |
library(ROI.plugin.highs) | |
library(ompr.roi) | |
library(ompr) | |
## Model taken from https://dirkschumacher.github.io/ompr/ | |
result <- MIPModel() |> | |
add_variable(x, type = "integer") |> | |
add_variable(y, type = "continuous", lb = 0) |> | |
set_bounds(x, lb = 0) |> | |
set_objective(x + y, "max") |> | |
add_constraint(x + y <= 11.25) |> | |
solve_model(with_ROI(solver = "highs")) | |
get_solution(result, x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment