GRBGenConstr#
- GRBGenConstr#
Gurobi general constraint object. General constraints are always associated with a particular model. You create a general constraint object by adding a general constraint to a model (using one of the
GRBModel.AddGenConstr*
methods), rather than by using aGRBGenConstr
constructor.General constraint objects have a number of attributes, which can be queried with the
GRBGenConstr.Get
method. The full list can be found in the Attributes section of this document.- Example:
// Create binary indicator variable GRBVar z = model.AddVar(0.0, 1.0, 0.0, GRB.BINARY, "resvar"); // Create variables GRBVar x = model.AddVar(0.0, GRB.INFINITY, 0.0, GRB.CONTINUOUS, "x"); GRBVar y = model.AddVar(0.0, GRB.INFINITY, 0.0, GRB.CONTINUOUS, "y"); // Add constraint if resvar = 1 then x + y <= 2 GRBGenConstr gc = model.AddGenConstrIndicator(z, 1, x + y <= 2.0, "indicatorconstr");
' Create binary indicator variable Dim z As GRBVar = model.AddVar(0.0, 1.0, 0.0, GRB.BINARY, "resvar") ' Create variables Dim x As GRBVar = model.AddVar(0.0, GRB.INFINITY, 0.0, GRB.CONTINUOUS, "x") Dim y As GRBVar = model.AddVar(0.0, GRB.INFINITY, 0.0, GRB.CONTINUOUS, "y") ' Add constraint if resvar = 1 then x + y <= 2 Dim gc As GRBGenConstr = model.AddGenConstrIndicator(z, 1, x + y <= 2.0, "indicatorconstr")
- double Get(GRB.DoubleAttr attr)#
Query the value of a double-valued general constraint attribute.
- Parameters:
attr – The attribute being queried.
- Returns:
The current value of the requested attribute.
- Example:
// Get PWL approximation error double funcPieceError = gc.Get(GRB.DoubleAttr.FuncPieceError);
' Get PWL approximation error Dime funcPieceError As Double = gc.Get(GRB.DoubleAttr.FuncPieceError)
- int Get(GRB.IntAttr attr)#
Query the value of an int-valued general constraint attribute.
- Parameters:
attr – The attribute being queried.
- Returns:
The current value of the requested attribute.
- Example:
// Get general constraint type int type = gc.Get(GRB.IntAttr.GenConstrType);
' Get general constraint type Dim type As Integer = gc.Get(GRB.IntAttr.GenConstrType)
- string Get(GRB.StringAttr attr)#
Query the value of a string-valued general constraint attribute.
- Parameters:
attr – The attribute being queried.
- Returns:
The current value of the requested attribute.
- Example:
// Get general constraint name string name = gc.Get(GRB.StringAttr.GenConstrName);
' Get general constraint name Dim name As String = gc.Get(GRB.StringAttr.GenConstrName)
- void Set(GRB.DoubleAttr attr, string newvalue)#
Set the value of a double-valued general constraint attribute.
- Parameters:
attr – The attribute being modified.
newvalue – The desired new value of the attribute.
- Example:
// Set PWL approximation error gc.Set(GRB.DoubleAttr.FuncPieceError, 1e-4);
' Set PWL approximation error gc.Set(GRB.DoubleAttr.FuncPieceError, 1e-4)
- void Set(GRB.IntAttr attr, string newvalue)#
Set the value of an int-valued general constraint attribute.
- Parameters:
attr – The attribute being modified.
newvalue – The desired new value of the attribute.
- Example:
// Set number of PWL pieces gc.Set(GRB.IntAttr.FuncPieces, 100);
' Set number of PWL pieces gc.Set(GRB.IntAttr.FuncPieces, 100)
- void Set(GRB.StringAttr attr, string newvalue)#
Set the value of a string-valued general constraint attribute.
- Parameters:
attr – The attribute being modified.
newvalue – The desired new value of the attribute.
- Example:
// Set name of general constraint gc.Set(GRB.StringAttr.GenConstrName, "newName");
' Set name of general constraint gc.Set(GRB.StringAttr.GenConstrName, "newName")