r-opt / rmpk

Mixed Integer Linear and Quadratic Programming in R
https://r-opt.github.io/rmpk/
Other
44 stars 4 forks source link

Cannot access value of scalar variable #62

Closed prubin73 closed 2 years ago

prubin73 commented 2 years ago

I have a MIP model initialized as follows:

solver <- ROI_optimizer("cplex") model <- optimization_model(solver)

The model contains binary vector variables named y.var and z.var, continuous vector variable x.var, and scalar (continuous) variables c.var and d.var. After solving the model, I am able to recover the values of w.var via model$get_variable_value(w.var[i]). However, I cannot access the value of d.var or c.var. Neither model$get_variable_value(d.var) nor model$get_variable_value(d.var[i]) works. The first approach (no index variable) produces the error

Error in h(simpleError(msg, call)) : error in evaluating the argument 'index' in selecting a method for function 'moi_get': no slot of name "variable_index" for this object of class "MOI_scalar_affine_term"

while the second approach (with [i] included) produces the error message

Error in extract_solver_variable_value(private, rlang::enquo(variable_selector), : no slot of name "arity" for this object of class "MOI_scalar_affine_term"

I notice that the vector variables have class RMPK_variable_list while the scalars are MOI_scalar_affine_term. Is there an undocumented method for accessing values of the scalar terms?

dirkschumacher commented 2 years ago

Thanks a lot for taking the time to post an issue. I will look into that.

dirkschumacher commented 2 years ago

Please test the most recent version with remotes::install_github("r-opt/rmpk"). Should be fixed now I hope

prubin73 commented 2 years ago

I can confirm it is fixed.