[R] Solving an optimization problem: selecting an "optimal" subset

Erwin Kalvelagen erwin.kalvelagen at gmail.com
Tue Feb 2 03:36:17 CET 2010


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
erwin at amsterdamoptimization.com
http://amsterdamoptimization.com



More information about the R-help mailing list