Christian
Christian

Reputation: 1460

Gurobi 800, Java, retrieving number of variables returns zero

The methods to retrieve the number of variables and constraints of a model seem to not work.

Here is the code:

        GRBVar x = model.addVar(0.0, GRB.INFINITY, 0.0, GRB.CONTINUOUS, "x");

        GRBLinExpr expr = new GRBLinExpr();
        expr.addTerm(1.0, x);
        GRBConstr c0 = model.addConstr(expr, GRB.LESS_EQUAL, 4.0, "c0");

        System.out.println("Number of variables: " + model.get(IntAttr.NumVars));
        System.out.println("Number of constraints: " + model.get(IntAttr.NumConstrs));
        System.out.println("UB = " + c0.get(DoubleAttr.RHS));

Output:

Number of variables: 0
Number of constraints: 0
Error code: 10006. Error at GRBConstr.get

Upvotes: 2

Views: 93

Answers (1)

Cepheus
Cepheus

Reputation: 589

As far as I remember you have to call model.update() after creating the variables and before adding the constraints.

Upvotes: 2

Related Questions