I am using Glpk java to solve a LP relaxation.
The weird thing is that sometimes it works but sometimes JVM crashes. And when it crashes I have this error:
# 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]
Sometimes it crashes silently, and when it does it's on a random native function from the glpk DLL file (i.e glp_simplex and glp_delete_prob).
Here is a part of my code:
// 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);
Any ideas ?
Thank you.
As described in doc/glpk.pdf the index 0 is not used by glpk.
So you arrays should have one additional element