[R] Linear programming problem, RGPLK - "no feasible solution".

Hans W Borchers hwborchers at googlemail.com
Mon Oct 10 23:17:34 CEST 2011


Liu Evans, Gareth <Gareth.Liu-Evans <at> liverpool.ac.uk> writes:

> In my post at https://stat.ethz.ch/pipermail/r-help/2011-October/292019.html
> I included an undefined term "ej".  The problem code should be as follows.
> It seems like a simple linear programming problem, but for some reason my
> code is not finding the solution.
> 
> obj <- c(rep(0,3),1)
> 
> col1 <-c(1,0,0,1,0,0,1,-2.330078923,0)
> col2 <-c(0,1,0,0,1,0,1,-2.057855981,0)
> col3 <-c(0,0,1,0,0,1,1,-1.885177032,0)
> col4 <-c(-1,-1,-1,1,1,1,0,0,1)
> 
> mat <- cbind(col1, col2, col3, col4)
> 
> dir <- c(rep("<=", 3), rep(">=", 3), rep("==", 2), ">=")
> 
> rhs <- c(rep(0, 7), 1, 0)
> 
> sol <- Rglpk_solve_LP(obj, mat, dir, rhs, types = NULL, max = FALSE,
> bounds = c(-100,100), verbose = TRUE)
> 
> The R output says there is no feasible solution, but e.g.
> (-2.3756786,  0.3297676,  2.0459110, 2.3756786) is feasible.
> 
> The output is
> 
> "GLPK Simplex Optimizer, v4.42
> 9 rows, 4 columns, 19 non-zeros
>       0: obj =  0.000000000e+000  infeas = 1.000e+000 (2)
> PROBLEM HAS NO FEASIBLE SOLUTION"

Please have a closer look at the help page "?Rglpk_solve_LP". The way to
define the bounds is a bit clumsy, but then it works:

    sol <- Rglpk_solve_LP(obj, mat, dir, rhs, types = NULL, max = FALSE,
            bounds = list(lower=list(ind=1:4, val=rep(-100,4)),
                          upper=list(ind=1:4, val=rep(100,4))),
            verbose=TRUE)
                
    GLPK Simplex Optimizer, v4.42
    9 rows, 4 columns, 19 non-zeros
          0: obj =  -1.000000000e+02  infeas =  1.626e+03 (2)
    *    10: obj =   1.000000000e+02  infeas =  0.000e+00 (0)
    *    13: obj =   2.247686558e+00  infeas =  0.000e+00 (0)
    OPTIMAL SOLUTION FOUND

    > sol
    $optimum
    [1] 2.247687
    $solution
    [1] -2.247687e+00 -6.446292e-31  2.247687e+00  2.247687e+00

> One other thing, a possible bug - if I run this code with "dir" shorter than
> it should be, R crashes.  My version of R is 2.131.56322.0, and I'm running
> it on Windows 7.  

If you can reproduce that R crashes -- which it shall never do -- inform the
maintainer of this package. On Mac it doesn't crash, it goes into an infinite
loop with "Execution aborted.Error detected in file glplib03.c at line 83".

Regards, Hans Werner

> Regards,
> Gareth



More information about the R-help mailing list