Filter Content By
Version
Languages

Setting the objective

The next step in the example is to set the optimization objective:

      // Set objective: maximize x + y + 2 z
model.SetObjective(x + y + 2 * z, GRB.MAXIMIZE);


The objective is built here using overloaded operators. The C# API overloads the arithmetic operators to allow you to build linear and quadratic expressions involving Gurobi variables.

The second argument indicates that the sense is maximization.

Note that while this simple example builds the objective in a single statement using an explicit list of terms, more complex programs will typically build it incrementally. For example:

  GRBLinExpr obj = 0.0;