Model creation fails for larger models with "NullPointerException: Cannot invoke "gurobi.GRBVar.getcolno()" because "v" is null"
回答済みprivate fun addTransitivityConstraint(vars: MutableMap<Pair<Node, Node>, GRBVar>, model: GRBModel) {
val visited1 = mutableSetOf<Node>()
partialOrder.vertexSet().forEach { a ->
visited1.add(a)
val visited2 = mutableSetOf<Node>()
partialOrder.vertexSet().filterNot { visited1.contains(it) }.forEach { b ->
visited2.add(b)
partialOrder.vertexSet().filterNot { visited1.contains(it) || visited2.contains(it) }.forEach { c ->
//skip if a b and c are comparable in partial order
logger().debug("Comparing $a - $b - $c")
if (!partialOrder.containsEdge(b,a) && !partialOrder.containsEdge(c,b) && !partialOrder.containsEdge(a,c)) {
val expr = GRBLinExpr()
expr.addConstant(1.0)
if (partialOrder.containsEdge(a, b))
expr.addConstant(-1.0)
else
expr.addTerm(-1.0, vars[Pair(a, b)])
expr.addConstant(1.0)
if (partialOrder.containsEdge(b,c))
expr.addConstant(-1.0)
else
expr.addTerm(-1.0, vars[Pair(b, c)])
if (partialOrder.containsEdge(a,c))
expr.addConstant(1.0)
else
expr.addTerm(1.0, vars[Pair(a, c)])
model.addConstr(expr, GRB.GREATER_EQUAL, 1.0, "c1-x${a.Id}${b.Id}${c.Id}")
//model.update()
}
}
}
}
In this simple function, created to ad the transitivity constraint to a positive completion of an ordering instance, I am trying to add the constraint
//Add constraint (1 - ab) + (1 -bc) + ac >= 1
For all $a, b, c \in V$ with $a < b < c$, $(b, a)\notin \rho$, $(c, b)\notin \rho$, and $(a, c)\notin \rho$ we add the constraint $(1-ab) + (1-bc) + ac \geq 1$
Which is working fine for small instances and fails for larger ones with this ominous error Cannot invoke "gurobi.GRBVar.getcolno()" because "v" is null. Where does this error come from and how to mitigate it ?
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
It is hard to help here without a minimal reproducible example. Your code snippet uses many objects and data structures not defined in the snippet. Additionally, please post a screenshot of the full error code.
' "v" is null' indicates that a variable object you pass is NULL instead of GRBVar. This may happen if, e.g., vars[Pair(a,b)] has not been added to the model yet.
0 -
Thanks for your quick reply.
' "v" is null' indicates that a variable object you pass is NULL instead of GRBVar. This may happen if, e.g., vars[Pair(a,b)] is not present.
I kind of excluded this possibility and expected another error but you are right, some of the vars were not present. Now it's running like a charm.
0
投稿コメントは受け付けていません。
コメント
3件のコメント