[R] Optimization Question

Paul Smith phhs80 at gmail.com
Fri Jun 12 12:28:52 CEST 2009


On Thu, Jun 11, 2009 at 9:56 PM, Brecknock, Peter<Peter.Brecknock at bp.com> wrote:
> Apologies if this is not the correct list for this question.
>
> The Rglpk package offers the following example in its documentation
>
> library(Rglpk)
> ## Simple mixed integer linear program.
> ## maximize: 3 x_1 + 1 x_2 + 3 x_3
> ## subject to: -1 x_1 + 2 x_2 + x_3 <= 4
> ## 4 x_2 - 3 x_3 <= 2
> ## x_1 - 3 x_2 + 2 x_3 <= 3
> ## x_1, x_3 are non-negative integers
> ## x_2 is a non-negative real number
> obj <- c(3, 1, 3)
> mat <- matrix(c(-1, 0, 1, 2, 4, -3, 1, -3, 2), nrow = 3)
> dir <- c("<=", "<=", "<=")
> rhs <- c(4, 2, 3)
> types <- c("I", "C", "I")
> max <- TRUE
> Rglpk_solve_LP(obj, mat, dir, rhs, types, max)
>
> ## Same as before but with bounds replaced by
> ## -Inf < x_1 <= 4
> ## 0 <= x_2 <= 100
> ## 2 <= x_3 < Inf
>
> bounds <- list(lower = list(ind = c(1L, 3L), val = c(-Inf, 2)),
> upper = list(ind = c(1L, 2L), val = c(4, 100)))
> Rglpk_solve_LP(obj, mat, dir, rhs, types, max, bounds)
>
> I have 2 questions
>
> 1. What is the purpose of the L in the bounds statement (e.g. 1L, 3L
> etc)?
>
> 2. Is it possible to further constrain a variable such that in the
> optimal solution to the objective function it will be a specific integer
> or an integer multiple of that integer. For example, x_3 must be 2 or
> 4,6,8,10 etc

Regarding your first question, I am not very sure, but it seems that

iL

means the constraint i.

Concerning your second question, the answer is positive. To force x_3
being an even number, just add the following constraints:

x_3 = 2 * y,

y >= 1,

y integer.

Paul




More information about the R-help mailing list