TempConstr

Gurobi temporary constraint object. Objects of this class are created as intermediate results when building constraints using overloaded operators. There are no member functions on this class. Instead, TempConstr objects are created by a set of functions on Var, MVar, LinExpr, QuadExpr, MLinExpr, MQuadExpr, and GenExpr objects (e.g., ==, <=, and >=). You will generally never store objects of this class in your own variables.

The TempConstr object allows you to create several different types of constraints:

Consider the following examples:

  model.addConstr(x + y == 1);
  model.addConstr(x + y == [1, 2]);
  model.addConstr(x*x + y*y <= 1);
  model.addConstr(A @ x <= 1);
  model.addConstr(x @ A @ x <= 1);
  model.addConstr(x == abs_(y));
  model.addConstr(x == or_(y, z));
  model.addConstr(x == max_(y, z));
  model.addConstr((x == 1) >> (y + z <= 5));
In each case, the overloaded comparison operator creates an object of type TempConstr, which is then immediately passed to method Model.addConstr.