prioritizr / prioritizr

Systematic conservation prioritization in R
https://prioritizr.net
122 stars 25 forks source link

Support The R Optimization Infrastructure (ROI) #16

Open dirkschumacher opened 7 years ago

dirkschumacher commented 7 years ago

If you support ROI as a solver interface, users can use a number of different solvers out of the box. Currently plugins for the ILP solvers GLPK, symphony, lpsolve and cplex are on CRAN.

I am also currently working on CBC as a ROI plugin.

There are also two ROI plugins for Gurobi on Github.

jeffreyhanson commented 7 years ago

Hi,

Thanks for getting in touch about ROI!

Yeah, I think it would be great if we could integrate ROI into prioritizr so we could get access to lots of different solvers.

At the moment, we're using an OptimizationProblem class for storing the model matrix, rhs, objective, etc.

Is there an equivalent class in ROI that we could convert our OptimizationProblem objects to, and then use the solvers offered in RIO to solve the problems?

Cheers,

Jeff

dirkschumacher commented 7 years ago

Hey Jeff,

there is a class called ROI::OP. Here is a simple, arbitrary example :)

library(ROI)
library(ROI.plugin.glpk)

# max: x1 + x2 + x3 + x4
# s.t. x1 + x2 + x3 + x4 <= 4
# 0 <= x1 <= 0
# 0 <= x2 <= 1
# 0 <= x3 <= 1
# 0 <= x4 <= 0

bounds <- ROI::V_bound( # <- sparse bound encoding
  ui = c(1, 2, 3, 4),
  ub = c(0, 1, 1, 0)
)
constraints <- ROI::L_constraint(L = matrix(c(1, 1, 1, 1), ncol = 4) # <- can be sparse,
                                 dir = "<=",
                                 rhs = 4)

op <- ROI::OP(c(1, 1, 1, 1), # <- can be sparse
              constraints,
              bounds = bounds,
              types = c("I", "I", "I", "I"),
              max = TRUE)
result <- ROI::ROI_solve(op, "glpk") # here you can use different solvers
result$solution

Florian Schwendinger is also working on a Gurobi plugin: https://r-forge.r-project.org/scm/viewvc.php/pkg/ROI.plugin.gurobi/?root=roi

jeffreyhanson commented 7 years ago

Thank you very much for the demo and the heads up on Gurobi support.

It looks like it would be pretty straight forward to implement this. I'd really like to implement this. I'm a bit busy at the moment though, so it might take a while before I get to it.

jeffreyhanson commented 7 years ago

I'm disappointed that I never got around to implementing ROI. I just wanted to say it's still on the cards. Do you know if there are any plans to make the gurobi plugin available on CRAN?