dirkschumacher / ompr

R package to model Mixed Integer Linear Programs
https://dirkschumacher.github.io/ompr/
Other
268 stars 35 forks source link

get_solution duplicates entries with similar names #318

Closed cookesd closed 2 years ago

cookesd commented 4 years ago

The get_solution function returns values for undesired variables if one variable name is contained in another. In the example below we have variable names x and xx. When we solve and call get_solution for x we also get the variable values for xx, but they are still have x in the variable column (x_df has 6 rows instead of 3).

simp = MIPModel() %>% add_variable(x[i],i=1:3,type='integer',lb=0,ub=5) %>%
  add_variable(xx[i],i=1:3,type='integer',lb=0,ub=5) %>%
  add_constraint(x[i]+1.3*xx[i]<=4,i=1:3) %>%
  set_objective(sum_expr(1.3*x[i]+xx[i],i=1:3),sense='max')
res = solve_model(simp,with_ROI('glpk'))
x_df=get_solution(res,x[i])
xx_df=get_solution(res,xx[i])
dirkschumacher commented 2 years ago

I believe this fixed in the most recent version. In particular I cannot reproduce it with the current master version. Feel free to reopen, if it is still an issue. Thanks a lot for the report!