SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: some constraints ignored when using solveLP [ Reply ]
By: Arne Henningsen on 2013-12-29 16:36
[forum:40238]
Dear Hans

Thank you for reporting this problem. Please note that solveLP() and probably most other LP solvers (implicitly) impose the restrictions x_i >= 0 for all i (or y_i >= 0 in your notation of the dual problem). Hence, there is no feasible solution for the dual problem that you describe in your first post but there is a feasible solution to the transformed dual problem that you describe in your second post. Of course, solveLP() should not report an infeasible solution but report that the problem is infeasible. This problem might be caused by the same bug that is reported as bug #4727 in the R-Forge system [1]. In case of problems with solveLP(), I recommend setting argument "lpSolve" to "TRUE" so that the R package "lpSolve" is used for solving the LP problem. In this case, I got:

R> res <- solveLP( objVec, rhsConstr, Amat, maximum=TRUE, const.dir = rep("<=", length(rhsConstr)), lpSolve = TRUE)
R> res
Results of Linear Programming / Linear Optimization
(using lpSolve)
lpSolve returned error code '2'

[1] https://r-forge.r-project.org/tracker/index.php?func=detail&aid=4727&group_id=640&atid=2583

Best regards,
Arne

RE: some constraints ignored when using solveLP [ Reply ]
By: Hans Roggeman on 2013-12-28 22:15
[forum:40237]
It looks like it is an issue in with the space it is looking at, because when I transform the dual problem in positive space I do get the right solution for it (1/3,1/3)

# dual problem in positive space
objVec <- c(12,9)
rhsConstr <- c(1,1,0,0)
Amat <- rbind( c( 2, 1),
c( 1, 2),
c( 1, 0),
c( 0, 1))
res <- solveLP( objVec, rhsConstr, Amat, maximum=FALSE, const.dir = rep(">=",length(rhsConstr)) , lpSolve=TRUE)
res$solution

some constraints ignored when using solveLP [ Reply ]
By: Hans Roggeman on 2013-12-28 22:06
[forum:40236]
Hi there,

I am using solveLP in the linprog R package to solve a simple linear programming problem:

minimize -x1-x2
subject to 2*x1+x2+x3 =12
x1+2*x2 +x4 = 9
x1,x2,x3,x4 >=0
which has dual equivalent:

maximize 12*y1+9*y2
subject to 2*y1+y2 <= -1
y1+2*y2 <= -1
y1,y2 <=0
If I state the problem in the primal form I get the right results (5,2,0,0). But when stating the problem in the dual form, the first two constraints simply get ignored. I get the result (0,0) which clearly violates (2*y1+y2 <= -1 and y1+2*y2 <= -1), is there an extra setting or parameter I am missing ? Please have a look at the code underneath and let me know what you think:

require(linprog)
objVec <- c(-1,-1,0,0)
rhsConstr <- c(12, 9,0,0,0,0)
Amat <- rbind( c( 2, 1, 1, 0 ),
c( 1, 2, 0, 1 ),
c( 1, 0, 0, 0 ),
c( 0, 1, 0, 0 ),
c( 0, 0, 1, 0 ),
c( 0, 0, 0, 1 ))
res <- solveLP( objVec, rhsConstr, Amat, maximum=FALSE, const.dir = c("==","==",">=",">=",">=",">=") , lpSolve=TRUE)
res$solution

# dual problem - this is where the problem is
objVec <- c(12,9)
rhsConstr <- c(-1.0,-1.0,0,0)
Amat <- rbind( c( 2, 1),
c( 1, 2),
c( 1, 0),
c( 0, 1))
res <- solveLP( objVec, rhsConstr, Amat, maximum=TRUE, const.dir = rep("<=",length(rhsConstr)))
res$solution

Thanks to:
Vienna University of Economics and Business Powered By FusionForge