Overloaded Operators#

The Gurobi .NET interface overloads several arithmetic and comparison operators. Overloaded arithmetic operators (+, -, *, /) are used to create linear and quadratic expressions. Overloaded comparison operators (<=, >=, and ==) are used to build linear and quadratic constraints.

Note that the results of overloaded comparison operators are generally never stored in user variables. They are immediately passed to GRBModel.AddConstr or GRBModel.AddQConstr.

GRBTempConstr operator <=(GRBQuadExpr lhsExpr, GRBQuadExpr rhsExpr)#

Create an inequality constraint.

Parameters:
  • lhsExpr – Left-hand side of inequality constraint.

  • rhsExpr – Right-hand side of inequality constraint.

Returns:

A constraint of type GRBTempConstr. The result is typically immediately passed to method GRBModel.AddConstr.

GRBTempConstr operator >=(GRBQuadExpr lhsExpr, GRBQuadExpr rhsExpr)#

Create an inequality constraint.

Parameters:
  • lhsExpr – Left-hand side of inequality constraint.

  • rhsExpr – Right-hand side of inequality constraint.

Returns:

A constraint of type GRBTempConstr. The result is typically immediately passed to method GRBModel.AddConstr.

GRBTempConstr operator ==(GRBLinExpr lhsExpr, GRBLinExpr rhsExpr)#

Create an equality constraint.

Parameters:
  • lhsExpr – Left-hand side of equality constraint.

  • rhsExpr – Right-hand side of equality constraint.

Returns:

A constraint of type GRBTempConstr. The result is typically immediately passed to method GRBModel.AddConstr.

GRBLinExpr operator +(GRBLinExpr expr1, GRBLinExpr expr2)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • expr1 – First linear expression argument.

  • expr2 – Second linear expression argument.

Returns:

A linear expression that is equal to the sum of the two argument expressions.

GRBLinExpr operator +(GRBLinExpr expr, GRBVar var)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • expr – Linear expression argument.

  • var – Variable argument.

Returns:

A linear expression that is equal to the sum of the argument linear expression and the argument variable.

GRBLinExpr operator +(GRBVar var, GRBLinExpr expr)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • var – Variable argument.

  • expr – Linear expression argument.

Returns:

A linear expression that is equal to the sum of the argument linear expression and the argument variable.

GRBLinExpr operator +(GRBVar var1, GRBVar var2)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • var1 – First variable argument.

  • var2 – Second variable argument.

Returns:

A linear expression that is equal to the sum of the two argument variables.

GRBLinExpr operator +(double a, GRBVar var)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • a – Constant.

  • var – Variable.

Returns:

A linear expression that is equal to the sum of the constant and the variable argument.

GRBLinExpr operator +(GRBVar var, double a)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • var – Variable.

  • a – Constant.

Returns:

A linear expression that is equal to the sum of the constant and the variable argument.

GRBQuadExpr operator +(GRBQuadExpr expr1, GRBQuadExpr expr2)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • expr1 – First quadratic expression argument.

  • expr2 – Second quadratic expression argument.

Returns:

A quadratic expression that is equal to the sum of the two argument quadratic expressions.

GRBQuadExpr operator +(GRBQuadExpr expr, GRBVar var)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • expr – Quadratic expression argument.

  • var – Variable argument.

Returns:

A quadratic expression that is equal to the sum of the argument quadratic expression and the argument variable.

GRBQuadExpr operator +(GRBVar var, GRBQuadExpr expr)#

Create a new expression by adding a pair of Gurobi objects.

Parameters:
  • var – Variable argument.

  • expr – Quadratic expression argument.

Returns:

A quadratic expression that is equal to the sum of the argument quadratic expression and the argument variable.

GRBLinExpr operator -(GRBLinExpr expr1, GRBLinExpr expr2)#

Create a new expression by subtracting one Gurobi object from another.

Parameters:
  • expr1 – First linear expression argument.

  • expr2 – Second linear expression argument.

Returns:

A linear expression that is equal to the first expression minus the second.

GRBQuadExpr operator -(GRBQuadExpr expr1, GRBQuadExpr expr2)#

Create a new expression by subtracting one Gurobi object from another.

Parameters:
  • expr1 – First quadratic expression argument.

  • expr2 – Second quadratic expression argument.

Returns:

A quadratic expression that is equal to the first expression minus the second.

GRBLinExpr operator *(double multiplier, GRBLinExpr expr)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • multiplier – Multiplier for expression argument.

  • expr – Expression argument.

Returns:

A linear expression that is equal to the input expression times the input multiplier.

GRBLinExpr operator *(GRBLinExpr expr, double multiplier)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • expr – Linear expression argument.

  • multiplier – Multiplier for expression argument.

Returns:

A linear expression that is equal to the input expression times the input multiplier.

GRBLinExpr operator *(double multiplier, GRBVar var)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • multiplier – Multiplier for variable argument.

  • var – Variable argument.

Returns:

A linear expression that is equal to the input variable times the input multiplier.

GRBLinExpr operator *(GRBVar var, double multiplier)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • var – Variable argument.

  • multiplier – Multiplier for variable argument.

Returns:

A linear expression that is equal to the input variable times the input multiplier.

GRBQuadExpr operator *(double multiplier, GRBQuadExpr expr)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • multiplier – Multiplier for expression argument.

  • expr – Quadratic expression argument.

Returns:

A quadratic expression that is equal to the input expression times the input multiplier.

GRBQuadExpr operator *(GRBQuadExpr expr, double multiplier)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • expr – Quadratic expression argument.

  • multiplier – Multiplier for expression argument.

Returns:

A quadratic expression that is equal to the input expression times the input multiplier.

GRBQuadExpr operator *(GRBVar var1, GRBVar var2)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • var1 – First variable argument.

  • var2 – Second variable argument.

Returns:

A quadratic expression that is equal to the product of the two input variables.

GRBQuadExpr operator *(GRBVar var, GRBLinExpr expr)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • var – Input variable.

  • expr – Input linear expression.

Returns:

A quadratic expression that is equal to the input linear expression times the input variable.

GRBQuadExpr operator *(GRBLinExpr expr, GRBVar var)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • expr – Input linear expression.

  • var – Input variable.

Returns:

A quadratic expression that is equal to the input linear expression times the input variable.

GRBQuadExpr operator *(GRBLinExpr expr1, GRBLinExpr expr2)#

Create a new expression by multiplying a pair of Gurobi objects.

Parameters:
  • expr1 – First linear expression argument.

  • expr2 – Second linear expression argument.

Returns:

A quadratic expression that is equal to the product of the two input linear expressions.

GRBLinExpr operator /(GRBVar var, double divisor)#

Create a new expression by dividing a Gurobi variable by a constant.

Parameters:
  • var – Variable argument.

  • divisor – Divisor for variable argument.

Returns:

A linear expression that is equal to the input variable divided by the input divisor.

implicit cast#

GRBLinExpr GRBLinExpr(double value)#

Create an expression from an implicit cast (e.g., expr = 0.0).

Parameters:

value – Desired value for linear expression.

Returns:

A linear expression that is equal to specified constant.

GRBQuadExpr GRBQuadExpr(double value)#

Create an expression from an implicit cast (e.g., expr = 0.0).

Parameters:

value – Desired value for quadratic expression.

Returns:

A quadratic expression that is equal to specified constant.

GRBLinExpr GRBLinExpr(GRBVar var)#

Create an expression from an implicit cast (e.g., expr = x).

Parameters:

value – Desired value for linear expression.

Returns:

A linear expression that is equal to specified variable.

GRBQuadExpr GRBQuadExpr(GRBVar var)#

Create an expression from an implicit cast (e.g., expr = x).

Parameters:

value – Desired value for quadratic expression.

Returns:

A quadratic expression that is equal to specified variable.

GRBQuadExpr GRBQuadExpr(GRBLinExpr expr)#

Create an expression from an implicit cast (e.g., qexpr = lexpr).

Parameters:

expr – Desired value for quadratic expression.

Returns:

A quadratic expression that is equal to specified linear expression.