Concepts
Features
Reference
Gurobi constraint object. Constraints are always associated with aparticular model. You create a constraint object by adding a constraintto a model (usingGRBModel.addConstr), rather than by usingaGRBConstr constructor.
The methods on constraint objects are used to get and set constraintattributes. For example, constraint right-hand sides can be queried bycallingget (GRB.DoubleAttr.RHS). 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 an attribute.
attr – The attribute being queried.
The current value of the requested attribute.
// Get constraint sensecharsense=constr.get(GRB.CharAttr.Sense);// Get RHS of the constraintdoublerhs=constr.get(GRB.DoubleAttr.RHS);// Get CBasis valueintcbasis=constr.get(GRB.IntAttr.CBasis);// Get constraint nameStringname=constr.get(GRB.StringAttr.ConstrName);
This method returns the current index, or order, of the constraint inthe underlying constraint matrix.
Note that the index of a constraint may change after subsequent modelmodifications.
-2: removed, -1: not in model, otherwise: index of theconstraint in the model
// Get the index of the constraint in the modelintindex=constr.index();
Check whether two constraint objects refer to the same constraint.
otherConstr – The other constraint.
Boolean result indicates whether the two constraint objectsrefer to the same model constraint.
// Compare the constraint with another constraintbooleanisSame=constr.sameAs(otherConstr);
Set the value of an attribute.
attr – The attribute being modified.
newval – The desired new value of the attribute.
// Set constraint senseconstr.set(GRB.CharAttr.Sense,'>');// Set RHS of the constraintconstr.set(GRB.DoubleAttr.RHS,2.0);// Set CBasis valueconstr.set(GRB.IntAttr.CBasis,0);// Set constraint nameconstr.set(GRB.StringAttr.ConstrName,"newName");
Help and Feedback