Reputation: 668
I'm trying to solve a Linear Programming problem based on binary variables with GLPK for Java (http://glpk-java.sourceforge.net/), but the result of the computation gives fractional results for the variables.
I omit most part of the code, but the important part is the following, where I define the variables as binary
GLPK.glp_add_cols(lp, data.size());
for (int i = 0; i < data.size(); i++) {
GLPK.glp_set_col_name(lp, i + 1, "x" + (i + 1));
GLPK.glp_set_col_kind(lp, i + 1, GLPKConstants.GLP_BV);
}
Data is a table containing the coefficients.
If I try to solve the problem using the presolver
glp_iocp iocpParm = new glp_iocp();
iocpParm.setPresolve(GLPK.GLP_ON);
GLPK.glp_init_iocp(iocpParm);
ret = GLPK.glp_intopt(lp, iocpParm);
the result is an error
glp_intopt: optimal basis to initial LP relaxation not provided
The problem could not be solved
If I add a pre-processing using simplex (as suggested by the documentation)
glp_smcp smcpParm = new glp_smcp();
GLPK.glp_init_smcp(smcpParm);
GLPK.glp_simplex(lp, smcpParm);
The results are fractional
Problem created
GLPK Simplex Optimizer, v4.63
1 row, 4 columns, 4 non-zeros
0: obj = 0.000000000e+00 inf = 1.231e+03 (1)
1: obj = 1.231000000e+03 inf = 0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
GLPK Integer Optimizer, v4.63
1 row, 4 columns, 4 non-zeros
4 integer variables, all of which are binary
Integer optimization begins...
+ 1: mip = not found yet >= -inf (1; 0)
Solution found by heuristic: 1600
+ 2: >>>>> 1.400000000e+03 >= 1.400000000e+03 0.0% (1; 0)
+ 2: mip = 1.400000000e+03 >= tree is empty 0.0% (0; 1)
INTEGER OPTIMAL SOLUTION FOUND
z = 1231.0
x1 = 0.769375
x2 = 0.0
x3 = 0.0
x4 = 0.0
How can I get binary solutions?
Upvotes: 1
Views: 511
Reputation: 64913
GLPK keeps separate results for different kinds of solver (MIP, interior point, simplex), so to get the results of a specific solver, the corresponding functions must be used.
glp_get
functions.glp_ipt
functions.glp_mip
functions.The rest of the name of the function is a bit inconsistent.
Upvotes: 1