Concepts
Features
Reference
Gurobi quadratic constraint object. Quadratic constraints are alwaysassociated with a particular model. You create a quadratic constraintobject by adding a quadratic constraint to a model (usingGRBModel.AddQConstr), rather than by using aGRBQConstr constructor.
// Create variablesGRBVarx=model.AddVar(-2.0,2.0,0.0,GRB.CONTINUOUS,"x");GRBVary=model.AddVar(0.0,3.0,0.0,GRB.CONTINUOUS,"y");// Add quadratic constraint x^2 + x*y + y = 0 with name c1GRBQConstrconstr=model.AddQConstr(x*x+x*y+y==0,"c1");
' Create variablesDimxAsGRBVar=model.AddVar(-2.0,2.0,0.0,GRB.CONTINUOUS,"x")DimyAsGRBVar=model.AddVar(0.0,3.0,0.0,GRB.CONTINUOUS,"y")' Add quadratic constraint x^2 + x*y + y = 0 with name c1DimconstrAsGRBQConstr=model.AddQConstr(x*x+x*y+y==0,"c1")
The methods on quadratic constraint objects are used to get and setquadratic constraint attributes. For example, quadratic constraintright-hand sides can be queried by callingGet (GRB.DoubleAttr.QCRHS).It can also be queried more directly usingqconstr.QCRHS whereqconstr is aGRBQConstr object. Note,however, that it is generally more efficient to query attributes for aset of constraints at once. This is done using the attribute querymethod on theGRBModel object (GRBModel.Get).
The full list of attributescan be found in theAttributes section of thisdocument. Examples of how to query and set attributes can also be foundinthis section.
Query the value of a quadratic constraint attribute.
attr – The attribute being queried.
The current value of the requested attribute.
// Get constraint sensecharsense=constr.Get(GRB.CharAttr.QCSense);// Get RHSdoublerhs=constr.Get(GRB.DoubleAttr.QCRHS);// Get information whether constraint participates in a// previously computed IISintiisqconstr=constr.Get(GRB.IntAttr.IISQConstr);// Get constraint namestringname=constr.Get(GRB.StringAttr.QCName);
' Get constraint senseDimsenseAsChar=constr.Get(GRB.CharAttr.QCSense)' Get RHSDimrhsAsDouble=constr.Get(GRB.DoubleAttr.QCRHS)' Get information whether constraint participates in a' previously computed IISDimiisqconstrAsInteger=constr.Get(GRB.IntAttr.IISQConstr)' Get constraint nameDimnameAsString=constr.Get(GRB.StringAttr.QCName)
Set the value of a quadratic constraint attribute.
attr – The attribute being modified.
newvalue – The desired new value of the attribute.
// Set constraint senseconstr.Set(GRB.CharAttr.QCSense,'>');// Set RHSconstr.Set(GRB.DoubleAttr.QCRHS,2.0);// Force constraint into IISconstr.Set(GRB.IntAttr.IISQConstrForce,1);// Set constraint nameconstr.Set(GRB.StringAttr.QCName,"newName");
' Set constraint senseconstr.Set(GRB.CharAttr.QCSense,">")' Set RHSconstr.Set(GRB.DoubleAttr.QCRHS,2.0)' Force constraint into IISconstr.Set(GRB.IntAttr.IISQConstrForce,1)' Set constraint nameconstr.Set(GRB.StringAttr.QCName,"newName")
Help and Feedback