Re: [Help-glpk] glp_get_col_prim() problem
is there any parallel implementation of GLPK? My other 23 cores are sitting idle.] Currently not. I'm having troubles while trying to get the solution variables via C API. Below is the code I use in my program: return (int) glp_get_col_prim(lp, i); Please note that glp_get_col_prim returns a floating-point value, so it would be better to write: return (int) (glp_get_col_prim(lp, i) + .5); The problem is, while above program outputs: *13: obj = 2.0e+00 infeas = 0.000e+00 (0) OPTIMAL SOLUTION FOUND xs[12]: 0 0 0 0 0 0 0 0 0 0 0 0 ys[3]: 0 0 0 glpsol gives a different result. + 2: mip = 2.0e+00 = tree is empty 0.0% (0; 1) INTEGER OPTIMAL SOLUTION FOUND And the results returned by glpsol are the right ones. What might I be missing in the C code? (To be honest, I'm in a quite hurry and any replies will be really really appreciated.) Most likely your instance has multiple optima, so your program finds one optimal solution while glpsol finds another. As you can see the optimal objective value is the same in both cases. Note that to solve mip you need to call glp_simplex (to find optimal solution to lp relaxation) and *then* call glp_intopt (to find integer optimal solution), in which case the column values should be obtained with glp_mip_col_val, not with glp_get_col_prim. It happened that for your particular instance optimal solution to lp relaxation is integer feasible and therefore integer optimal; however, in a general case glp_intopt should be used. For details please see the glpk reference manual. ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_get_col_prim() problem
I'm having troubles while trying to get the solution variables via C API. Below is the code I use in my program: return (int) glp_get_col_prim(lp, i); Please note that glp_get_col_prim returns a floating-point value, so it would be better to write: return (int) (glp_get_col_prim(lp, i) + .5); Yes, this may cause incorrect results. Imagine that x = 0.99 due to round-off errors in the simplex solver. Then (int)x - 0 (incorrect) while (int)(x + .5) - 1 (correct) ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_get_col_prim() problem
Hi, On Thu, 22 Apr 2010, Andrew Makhorin m...@gnu.org writes: Most likely your instance has multiple optima, so your program finds one optimal solution while glpsol finds another. As you can see the optimal objective value is the same in both cases. Note that to solve mip you need to call glp_simplex (to find optimal solution to lp relaxation) and *then* call glp_intopt (to find integer optimal solution), in which case the column values should be obtained with glp_mip_col_val, not with glp_get_col_prim. It happened that for your particular instance optimal solution to lp relaxation is integer feasible and therefore integer optimal; however, in a general case glp_intopt should be used. For details please see the glpk reference manual. I incorporated glp_mip_col_val() and glp_intopt() into the code, and it works like a charm. OTOH, please excuse my ignorance, but assuming all my variables are marked as binary in CPLEX LP file, do I really need to call glp_intopt() after glp_simplex() even if glp_get_status(lp) == GLP_OPT assertion holds? Regards. ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_get_col_prim() problem
OTOH, please excuse my ignorance, but assuming all my variables are marked as binary in CPLEX LP file, do I really need to call glp_intopt() after glp_simplex() even if glp_get_status(lp) == GLP_OPT assertion holds? Yes. Glp_simplex solves lp relaxation, i.e. it considers all integer variables as continuous (e.g. binary variable x is considered as continuous variable 0 = x = 1), and glp_get_status reports the status of optimal solution to lp relaxation, not to mip. To determine the status of integer solution you need to call glp_mip_status. You can find details in the reference manual. ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk