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; obj.AddTerm(1.0, x); obj.AddTerm(1.0, y); obj.AddTerm(2.0, z); model.SetObjective(obj, GRB.MAXIMIZE);