Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Optimizer Reference Manual
Light LogoDark Logo

Concepts

Features

Reference

Gurobi
Back to top

GRBQConstr#

GRBQConstr#

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.

Example:
// 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");

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.

charGet(GRB.CharAttrattr)#
doubleGet(GRB.DoubleAttrattr)#
intGet(GRB.IntAttrattr)#
stringGet(GRB.StringAttrattr)#

Query the value of a quadratic constraint attribute.

Parameters:

attr – The attribute being queried.

Returns:

The current value of the requested attribute.

Example:
// 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);
voidSet(GRB.CharAttrattr,charnewvalue)#
voidSet(GRB.DoubleAttrattr,doublenewvalue)#
voidSet(GRB.IntAttrattr,intnewvalue)#
voidSet(GRB.StringAttrattr,stringnewvalue)#

Set the value of a quadratic constraint attribute.

Parameters:
  • attr – The attribute being modified.

  • newvalue – The desired new value of the attribute.

Example:
// 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

On this page

[8]ページ先頭

©2009-2025 Movatter.jp