r-opt / rmpk

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

CPLEX solver not giving results based on example data #75

Open kevlim83 opened 1 year ago

kevlim83 commented 1 year ago

Hi @dirkschumacher ,

Im testing rmpk using CPLEX on the below example data found on the online vignette:

set.seed(42) n <- 10 returns <- matrix( rnorm(n * 20, mean = runif(n, 0.01, 0.03), sd = runif(n, 0.1, 0.4)), ncol = n) # 20 time periods e <- colMeans(returns) C <- cov(returns) min_mu <- 0.02

solver <- ROI_optimizer("cplex") model <- optimization_model(solver) x <- model$add_variable("x", i = 1:n, lb = 0, ub = 1) model$set_objective(sum_expr(2 C[i, j] x[i] x[j], i = 1:n, j = 1:n)) model$add_constraint(sum_expr(e[i] x[i], i = 1:n) >= min_mu) model$add_constraint(sum_expr(x[i], i = 1:n) == 1) solver$optimize()

But this does not return a solution. The value columns are NA. I have also tested that (1) CPLEX is working using the ROI package, and (2) other solvers work for this example problem. Debugging cplex within rmpk reveals that Q is not a symmetric matrix.

Any ideas?