# Adding constraints to the model

Filter Content By
Version
Languages

## Adding constraints to the model

The next step in the example is to add the linear constraints:

      // Add constraint: x + 2 y + 3 z <= 4
model.AddConstr(x + 2 * y + 3 * z <= 4.0, "c0");


As with variables, constraints are always associated with a specific model. They are created using the AddConstr() or AddConstrs() methods on the model object.

We again use overloaded arithmetic operators to build linear expressions. The comparison operators are also overloaded to make it easier to build constraints.

The second argument to AddConstr gives the constraint name.

The Gurobi .NET interface also allows you to add constraints by building linear expressions in a term-by-term fashion:

  GRBLinExpr expr = 0.0;