i currently have a problem implementing a contraint. 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? Is there a better way to implement this contraint?
Best regards
The expression like expr1 += expr2 + 50
is only supported by programming languages, which supports operator overloading, as seen in the documentation:
In .NET languages that support operator overloading, you generally build linear expressions using overloaded operators. [...]
The link https://www.gurobi.com/documentation/9.0/refman/cs_lex.html is referencing the .NET API Details for the .NET languages. You want to look at https://www.gurobi.com/documentation/9.0/refman/java_lex.html which is for the Java API Details. There you have the documentation that you can use the add*()
methods for adding two expressions/terms.