roptimizationr-optimization

R: Defining bounds for Optimization Problem Constructor OP (package ROI). Error in UseMethod("as.V_bound")


I want to define bounds for the variables when optimizing with the ROI package. I use the OP function for constructing the optimization problem object.

The default is: lower bounds are equal to zero and upper bounds are equal to +infinity.

Here is a sample code which works well:

LP <- OP( c(2, 4, 3),
      L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
                   dir = c("<=", "<=", "<="),
                   rhs = c(60, 40, 80)),
      max = TRUE )

But if I add bounds "by hand" I get an error:

LP <- OP( c(2, 4, 3),
      L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
                   dir = c("<=", "<=", "<="),
                   rhs = c(60, 40, 80)),
                    bounds = list(upper=c(100,100,100), lower=c(0,0,0)),
      max = TRUE )

Error in UseMethod("as.V_bound") : 
no applicable method for 'as.V_bound' applied to an object of class "list"

But the description says that "bounds" needs a list as input.

Has anyone any ideas how to pass on the bounds correctly to the OP function?


Solution

  • LP <- OP(c(2, 4, 3),
             L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
                          dir = c("<=", "<=", "<="),
                          rhs = c(60, 40, 80)),
             bounds = V_bound(ui = seq_len(3), ub = rep.int(100, 3)),
             maximum = TRUE )