Error in java API: GRBVar.get(Attr) always throws an error
AnsweredThe following simple piece of code throws an error in GRBVar.Get():
GRBEnv env = new GRBEnv(true);
env.set("logFile", "mip.log");
env.start();
model = new GRBModel(env);
GRBVar var = model.addVar(0, 1, 0, GRB.BINARY, "name");
double x = var.get(GRB.DoubleAttr.LB);
gurobi.GRBException: Error at GRBVar.get
at gurobi.GRBVar.get(GRBVar.java:116)
And line 116 in GRBVar says:
public double get(DoubleAttr attr) throws GRBException {
if (this.col_no >= 0 && this.model != 0L) {
int error = GRB.checkattrsize(this.model, attr.toString(), 1);
if (error != 0) {
throw new GRBException("Not variable attribute", error);
} else {
int[] ind = new int[1];
double[] value = new double[1];
error = GurobiJni.getdblattrlist(this.model, attr.toString(), this.col_no, 0, ind, value);
if (error != 0) {
//Line 116 throw new GRBException("Error at GRBVar.get", error);
} else {
return value[0];
}
}
} else {
throw new GRBException(20001);
}
}
Is this some kind of bug? Becaus here is a snippet from the gurobi manuals:
2
-
You are reading an attribute directly after creating the model (without e.g. optimizing first). This is one of the very rare situations where you have to call model.update() first.
Here is more information about update: https://www.gurobi.com/documentation/8.0/refman/java_grbmodel_update.html
1
Please sign in to leave a comment.
Comments
1 comment