Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in get_solution() in case there is only one variable #198

Closed
saurav2608 opened this issue Jun 6, 2018 · 6 comments
Closed

Error in get_solution() in case there is only one variable #198

saurav2608 opened this issue Jun 6, 2018 · 6 comments
Assignees
Labels

Comments

@saurav2608
Copy link

library(tidyverse)
#> -- Attaching packages ---------- tidyverse 1.2.1 --
#> v ggplot2 2.2.1 v purrr 0.2.4
#> v tibble 1.4.2 v dplyr 0.7.4
#> v tidyr 0.8.0 v stringr 1.3.0
#> v readr 1.1.1 v forcats 0.3.0
#> -- Conflicts ------------- tidyverse_conflicts() --
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
library(ompr)
library(ompr.roi)
library(ROI.plugin.glpk)
n <- 1; W <- 2
v <- runif(n);w <- runif(n)
model <- MIPModel() %>%
add_variable(x[i], i = 1:n, type = "binary") %>%
set_objective(sum_expr(v[i] * x[i], i = 1:n)) %>%
add_constraint(sum_expr(w[i] * x[i], i = 1:n) <= W)
result <- solve_model(model, with_ROI(solver = "glpk", verbose = FALSE))
solution <- get_solution(result, x[i])
#> Warning in seq_len(ncol(var_index)): first element used of 'length.out'
#> argument
#> Error in seq_len(ncol(var_index)): argument must be coercible to non-negative integer

@saurav2608
Copy link
Author

saurav2608 commented Jun 6, 2018

Located the issue in the definition of extract_solution(). Return type of var_index <- do.call(rbind, regmatches(solution_names, rexp_c)) is not a matrix in case there is only one element in regmatches(solution_names, rexp_c). Thus the line result_df <- as.data.frame(var_index[, seq_len(ncol(var_index))[-1]]) trips as ncol is not define for non-matrix

@dirkschumacher
Copy link
Owner

Ah interesting. Thanks a lot!

@dirkschumacher
Copy link
Owner

Seems to be a bug in dirkschumacher/ompr.roi#19

@dirkschumacher
Copy link
Owner

Thanks a lot. drop = TRUE striked again.

@saurav2608
Copy link
Author

Oh you are quick. I was preparing a PR. I started using your package recently. It is very good.

@dirkschumacher
Copy link
Owner

Thanks for reporting the bug. I am slowly restarting my OS work again after a temoral leave, so I thought this is a good start ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants