用于检索模型中变量和约束的数量的方法似乎不起作用。
代码如下:
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));
输出:
Number of variables: 0
Number of constraints: 0
Error code: 10006. Error at GRBConstr.get
答案 0 :(得分:2)
据我所知,您必须在创建变量之后并添加约束之前调用@client
。