[GLPK][Java]整数变量的问题
[GLPK][Java] Problems with integer variable
我正在使用 Glpk java,我必须解决这个问题(原始)
\* Problem: Branch and Bound Problem *\
Maximize
z: + 0.5 x1 + 0.5 x2 + 0.333333333333333 x3 + 0.142857142857143 x4
Subject To
c1: + 14 x4 + 31 x3 + 36 x2 + 45 x1 <= 100
Generals
x1
x2
x3
x4
End
我有这个结果
z = 1.3888888888888888
x1 = 0.0
x2 = 2.7777777777777777
x3 = 0.0
x4 = 0.0
但我只想要整数解。
我所有的专栏都设置为
GLPK.glp_set_col_kind(lp, column, GLPKConstants.GLP_IV);
我解决了:(编辑)
public void solve_prim(){
GLPK.glp_write_lp(lp,
null,
"lp.txt");
parm = new glp_smcp();
GLPK.glp_init_smcp(parm);
ret = GLPK.glp_simplex(lp, parm);
// Retrieve solution
if (ret == 0) {
write_lp_solution_prim(lp);
} else {
System.out.println("The problem could not be solved");
}
// Free memory
GLPK.glp_delete_prob(lp);
}
但我总是有分数解。
有人知道吗?
ret = GLPK.glp_simplex(lp, parm);
这会调用 LP 求解器。你会得到分数结果。要获得整数结果,您需要调用 MIP 求解器:
ret = GLPK.glp_intopt(lp, parm);
我正在使用 Glpk java,我必须解决这个问题(原始)
\* Problem: Branch and Bound Problem *\
Maximize
z: + 0.5 x1 + 0.5 x2 + 0.333333333333333 x3 + 0.142857142857143 x4
Subject To
c1: + 14 x4 + 31 x3 + 36 x2 + 45 x1 <= 100
Generals
x1
x2
x3
x4
End
我有这个结果
z = 1.3888888888888888
x1 = 0.0
x2 = 2.7777777777777777
x3 = 0.0
x4 = 0.0
但我只想要整数解。 我所有的专栏都设置为
GLPK.glp_set_col_kind(lp, column, GLPKConstants.GLP_IV);
我解决了:(编辑)
public void solve_prim(){
GLPK.glp_write_lp(lp,
null,
"lp.txt");
parm = new glp_smcp();
GLPK.glp_init_smcp(parm);
ret = GLPK.glp_simplex(lp, parm);
// Retrieve solution
if (ret == 0) {
write_lp_solution_prim(lp);
} else {
System.out.println("The problem could not be solved");
}
// Free memory
GLPK.glp_delete_prob(lp);
}
但我总是有分数解。 有人知道吗?
ret = GLPK.glp_simplex(lp, parm);
这会调用 LP 求解器。你会得到分数结果。要获得整数结果,您需要调用 MIP 求解器:
ret = GLPK.glp_intopt(lp, parm);