Hans W Borchers <hwborchers <at> googlemail.com> writes: > # Prepare inputs for MILP solver > obj <- c(rep(0, n), 0, 1, 1, 0) > typ <- c(rep("B", n), "B", "C", "C", "B") > mat <- matrix(c( s, -z, -1, 1, 0, # a = a_p + a_m > rep(0, n), 1, 0, 0, 0, # constant term > rep(0, n), 0, 1, 0, -M, # a_p <= M * d0 > rep(0, n), 0, 0, 1, M, # a_m <= M * (d0-1) > rep(1, n), 0, 0, 0, 0), # subset size <= k > nrow=5, byrow=T) > dir <- c("==", "==", "<=", "<=", "<=") > rhs <- c(0, 1, 0, M, k) > max <- FALSE
You can drop the binary variable d0. The condition "one of a_p,a_m is zero" holds automatically as we are minimizing a_p+a_m. ---------------------------------------------------------------- Erwin Kalvelagen Amsterdam Optimization Modeling Group er...@amsterdamoptimization.com http://amsterdamoptimization.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.