我正在使用Glpk java来解决一个LP松弛问题。
奇怪的是,有时它可以工作,但有时JVM会崩溃。当它崩溃时,我会看到这样的错误:
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffedcbb4d92,
pid=16584, tid=17184
#
# JRE version: Java(TM) SE Runtime Environment (8.0_66-b18) (build 1.8.0_66 b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.66-b18 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [ntdll.dll+0x14d92]有时它会悄悄地崩溃,当它崩溃时,它是在glpk DLL文件(即glp_simplex和glp_delete_prob)中的一个随机本机函数上。
下面是我的代码的一部分:
// Allocate memory
ind = GLPK.new_intArray(problem.getNbrConstraints());
val = GLPK.new_doubleArray(problem.getNbrConstraints());
// Create rows
GLPK.glp_add_rows(lp, problem.getNbrConstraints());
// Set row details
for (int i = 0; i < problem.getNbrConstraints(); i++) {
GLPK.glp_set_row_name(lp, i + 1, "c" + (i + 1));
GLPK.glp_set_row_bnds(lp, i + 1, GLPKConstants.GLP_DB, 0, problem.getB(i));
for (int j = 0; j < problem.getNbrVaribles(); j++) {
GLPK.intArray_setitem(ind, j + 1, j + 1);
GLPK.doubleArray_setitem(val, j + 1, problem.getItem(j).getRessource(i));
}
GLPK.glp_set_mat_row(lp, i + 1, problem.getNbrVaribles(), ind, val);
}
// Free memory
GLPK.delete_intArray(ind);
GLPK.delete_doubleArray(val);
// Define objective
GLPK.glp_set_obj_name(lp, "z");
GLPK.glp_set_obj_dir(lp, GLPKConstants.GLP_MAX);
for (int j = 0; j < problem.getNbrVaribles(); j++) {
GLPK.glp_set_obj_coef(lp, j + 1, problem.getItem(j).getProfit());
}
// Write model to file
GLPK.glp_write_lp(lp, null, "lp.lp");
// Solve model
parm = new glp_smcp();
GLPK.glp_init_smcp(parm);
ret = GLPK.glp_simplex(lp, parm);
// Free memory
GLPK.glp_delete_prob(lp);有什么想法吗?
谢谢。
发布于 2018-07-14 01:54:50
ind = GLPK.new_intArray(problem.getNbrConstraints());
正如doc/glpk.pdf中所述,glpk不使用索引0。
所以数组应该有一个额外的元素
ind = GLPK.new_intArray(problem.getNbrConstraints() + 1);
val = GLPK.new_doubleArray(problem.getNbrConstraints() + 1);https://stackoverflow.com/questions/46123806
复制相似问题