我使用 cplex Java API。
使用以下代码:
//init cplex
IloCplex cplex = new IloCplex();
cplex.setParam(IloCplex.IntParam.Threads, 1);
//is commodity k,l routed over i and j
//x ijkl
IloIntVar[] x = cplex.boolVarArray(inst.getSize()*inst.getSize()*inst.getSize()*inst.getSize());
for (int i = 0; i < x.length; i++) {
x[i] = cplex.boolVar();
}
//is node a hub
IloIntVar[] y = cplex.boolVarArray(inst.getSize());
for (int i = 0; i < y.length; i++) {
y[i] = cplex.boolVar();
}
//=== FITTNESS FUNCTION ===
IloLinearNumExpr expr = cplex.linearNumExpr();
//first big sum
for(int k=0;k<inst.getSize();k++){
for(int i=0;i<inst.getSize();i++) {
for(int j=0;j<inst.getSize();j++) {
for(int l=0;l<inst.getSize();l++) {
expr.addTerm(c[i][j][k][l], x[Static.quadToLinear(i, j, k, l, inst.getSize())]);
}
}
}
}
//second sum
for(int i=0;i<inst.getSize();i++) {
expr.addTerm(inst.getFixed(i), y[i]);
}
//minimise it
cplex.addMinimize(expr);
所以我只使用两个布尔向量 x 和 y。此代码段适用于 inst.getSize() 为例如 25 的较小实例。但是,对于大小为 40 的实例,它在最后一行崩溃。
Exception in thread "main" java.lang.NullPointerException
at ilog.cplex.CpxNumVar.unmark(CpxNumVar.java:296)
at ilog.cplex.CpxLinearExpr.unmarkVars(CpxLinearExpr.java:402)
at ilog.cplex.CpxLinearExpr.removeDuplicates(CpxLinearExpr.java:515)
at ilog.cplex.CpxLinearExpr.removeDuplicates(CpxLinearExpr.java:489)
at ilog.cplex.CpxObjective.setExpr(CpxObjective.java:108)
at ilog.cplex.CpxObjective.<init>(CpxObjective.java:362)
at ilog.cplex.IloCplexModeler.objective(IloCplexModeler.java:706)
at ilog.cplex.IloCplexModeler.addObjective(IloCplexModeler.java:768)
at ilog.cplex.IloCplexModeler.addMinimize(IloCplexModeler.java:790)
at ExactSolver.main(ExactSolver.java:69)
你有什么想法吗?我需要让它工作...