Search code examples
javalinear-programmingglpk

[Java][Glpk]Solve dual solution


I have a linear problem and I want to get optimal dual solution with GLPK on Java. I tried this :

parm = new glp_smcp();
parm.setMeth(GLPKConstants.GLP_DUAL);
GLPK.glp_init_smcp(parm);
ret = GLPK.glp_simplex(lp, parm);

but it seems there I always have primal Solution. Someone can help me ?


Solution

  • The line

     parm.setMeth(GLPKConstants.GLP_DUAL);
    

    will select the dual simplex method. It does not give you the dual solution per se. (To be precise: afterwards you can retrieve both the primal and dual solution).

    The way to retrieve the solution after solving is:

    GLPK.glp_get_col_prim(lp,j)   // retrieve primal solution
    GLPK.glp_get_row_dual(lp,i)   // retrieve duals 
    

    Remember in linear programming

    • Dual Simplex Method
    • The Dual of an LP problem
    • Duals in a solution

    are all different things. For more information please consult a book on Linear Programming (e.g. Vanderbei).