[R] Solve linear program without objective function

Hans W Borchers hwborchers at googlemail.com
Fri Dec 4 12:19:13 CET 2009


Andreas Wittmann <andreas_wittmann <at> gmx.de> writes:

> 
> Dear R-users,
> 
> i try to solve to following linear programm in R
> 
> 0 * x_1 + 2/3 * x_2 + 1/3 * x_3 + 1/3 * x_4 = 0.3
> x_1 + x_2 + x_3 + x_4 = 1
> x_1, x_2, x_3, x_4 > 0,
> x_1, x_2, x_3, x_4 < 1
> 
> as you can see i have no objective function here besides that i use the 
> following code.
> 
> library(lpSolve)
> 
> f.obj<-c(1,1,1,1)
> f.con<-matrix(c(0,2/3,1/3,1/3,
>                 1,1,1,1,
>                 1,0,0,0,
>                 0,1,0,0,
>                 0,0,1,0,
>                 0,0,0,1),nrow=6,byrow=TRUE)
> f.dir <- c("=", "=", ">", ">", ">", ">")
> f.rhs <- c(0.3, 1, 0, 0, 0, 0)
> 
> lp ("max", f.obj, f.con, f.dir, f.rhs)$solution
> 
> the problem is, the condition x_1, x_2, x_3, x_4 > 0 is not fulfilled.

With strict inequalities x_i > 0 your problem will not have a solution. That is
why in linear programming strict inequalities are replaced with non-strict
inequalities, or as the lp_solve manual says:

    "The inequalities can be <=, >= or =
     Because all numbers are real values,
     <= is the same as < and >= is the same as > ." 

Try x_i >= eps > 0 with some eps appropriate for your problem.

Hans Werner

> Any advice would be very helpful.
> 
> best regards
> 
> Andreas
> 
>




More information about the R-help mailing list