Originally posted by: bengu
Hello All,
I am trying to use callbacks via java/CPLEX. I modified example AdMIPex5.java ( my original problem has a similar design) and when I run it, I keep getting EXCEPTION_ACCESS_VIOLATION (0xc0000005) error. Original AdMIPex5.java works fine. Pls help.
public class AdMIPex5 {
public static class Callback extends IloCplex.UserCutCallback {
double eps = 1.0e-6;
IloRange[] cut;
IloModeler m;
IloLPMatrix lp;
IloNumVar[] vars;
Callback(IloModeler m, IloLPMatrix lp) {this.m = m; this.lp = lp; try {
vars = lp.getNumVars();
} catch (IloException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
Callback(IloRange[] cuts) { cut = cuts; }
public void main() throws IloException {
add(makeCut(m, vars));
}
}
public static IloRange makeCut(IloModeler m, IloNumVar[] vars)
{
IloRange ir = null;
try {
ir = m.addLe(vars[0], 100);
} catch (IloException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ir;
}
public static void main(String[] args) {
try {
IloCplex cplex = new IloCplex();
cplex.importModel("noswot.mps");
IloLPMatrix lp = (IloLPMatrix)cplex.LPMatrixIterator().next();
cplex.use(new Callback(cplex, lp));
cplex.setParam(IloCplex.Param.MIP.Interval, 1000);
cplex.setParam(IloCplex.Param.MIP.Strategy.Search, IloCplex.MIPSearch.Traditional);
if ( cplex.solve() ) {
System.out.println("Solution status = " + cplex.getStatus());
System.out.println("Solution value = " + cplex.getObjValue());
}
cplex.end();
}
catch (IloException e) {
System.err.println("Concert exception caught: " + e);
}
}
}
#CPLEXOptimizers#DecisionOptimization