Problems to define GRBLinExpr / Lazy-Contraint (Java)
回答済みHello,
i currently try to implement a lazy-contraint in java (JDK 13), but it seems that i miss something.
I have two sets (s1 and s2) of specific GRBVars and try to implement the following contraint:
Sum(s1) - Sum(s2) + constantValue <= someValue
My implementation (modified for easier reading):
GRBVar[][] vars;
....
GRBLinExpr expr1 = new GRBLinExpr();
GRBLinExpr expr2 = new GRBLinExpr();
for (Edge edge : s1) {
expr1.addTerm(1.0, vars[edge.getVertex1][edge.getVertex2]);
}
for (Edge edge : s2) {
expr2.addTerm(-1.0, vars[edge.getVertex1][edge.getVertex1]);
}
expr1 += expr2 + 50;
The last line expr1 += expr2 + 50 is marked as an error, without any helpful information. According to the documentation (https://www.gurobi.com/documentation/9.0/refman/cs_lex.html) it should be possible. What am i missing?
Best regards,
Tobias Klein
-
正式なコメント
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 why not try our AI Gurobot?. -
Hi Tobias,
The documentation you linked is for the .NET API. This syntax doesn't work in Java (which doesn't support operator overloading). Instead, you can use the GRBLinExpr.add() and GRBLinExpr.addConstant() methods.
Thanks!
Eli
0
投稿コメントは受け付けていません。
コメント
2件のコメント