0

The lp problem can be found at Portfolio Optimization Problem. The problem is based on cvar optimization in guy yollins presentation R Tools for Portfolio Optimization.

When I read the lp file in R and execute it, optimal solution is found. Whereas when I do the same via glpsol, it says "LP HAS NO PRIMAL FEASIBLE SOLUTION". I'm using glpsol as pulp internally uses glpsol for solving lp when solver argument is given as pulp.GLPK().

Steps to run the lp in R:

library("Rglpk")
problem <- Rglpk_read_file("path/to/problem.lp", "CPLEX_LP")
solution <- Rglpk_solve_LP(problem$objective, problem$constraints[[1]], problem$constraints[[2]], problem$constraints[[3]], problem$bounds, problem$types, problem$maximum, control=list("verbose" = TRUE))
print(solution$status)
print(solution$solution)

Steps to run the lp in glpsol:

glpsol --cpxlp "path/to/problem.lp" -o output.sol

Any idea why? I tried seeing the code for Rglpk_solve_lp function in R. It seems to be calling the glpk c library's glp_simplex function. I'm guessing glpsol also calls glp_simplex internally.

Environment details:
OS: Ubuntu 12.04
R version: 3.02
Rglpk version: 0.5-1(GLPK version 4.52 is shipped with the source package)
glpsol version: 4.52

livinston
  • 1,218
  • 2
  • 12
  • 18
  • I'll leave it only as a comment as I am not 100% sure exactly how to diagnose a numerically unstable problem, but that would be my guess. Adding --dual to your glpsol call solved it for me. – flodel Dec 05 '13 at 12:33
  • The results seem to vary mainly due to the options passed. I'll try out different options and try to see if any specific option matches the R results and add it as answer. You saved my ass dude. Thanks – livinston Dec 05 '13 at 17:49
  • @flodel: After I looked at the source code of Rglpk and glpsol, I found that Rglpk simply calls glp_simplex(problem, NULL). Whereas glpsol passes in valid non null value for the second argument. When I made the value of 2nd argument NULL in glpsol, rebuilt the code and reran the same problem with glpsol, it returned the same output as Rglpk_solve_lp. I'll try to find out if I can replicate the same without having to modify the source code of glpsol and add it as an answer. – livinston Dec 07 '13 at 07:32

1 Answers1

1

Adding options --nopresol, --noscale, --std to glpsol command gave me the same results as Rglpk_solve_lp.

glpsol --cpxlp ~/Downloads/PortfolioOptimization_minReturns_0.190000.lp -o output.sol --nopresol --noscale --std

I had to look into glpsol's code and compare it with Rglpk package's code to figure this out.

livinston
  • 1,218
  • 2
  • 12
  • 18