GRBQConstr#

GRBQConstr#

Gurobi 二次约束对象。二次约束总是与特定模型相关联。您通过向模型添加二次约束(使用 GRBModel.addQConstr)来创建二次约束对象,而不是通过使用 GRBQConstr 构造函数。

二次约束对象上的方法用于获取和设置约束属性。例如,可以通过调用getGRB.DoubleAttr.QCRHS)来查询二次约束的右侧值。然而,通常更高效的做法是一次性查询一组约束的属性。这是通过在GRBModel对象上使用属性查询方法(GRBModel.get)来完成的。

char get(GRB.CharAttr attr)#

查询一个字符型二次约束属性的值。

Arguments:

attr – 被查询的属性。

Return value:

请求属性的当前值。

Example:
// Get constraint sense
char sense = constr.get(GRB.CharAttr.QCSense);
double get(GRB.DoubleAttr attr)#

查询一个双值二次约束属性的值。

Arguments:

attr – 被查询的属性。

Return value:

请求属性的当前值。

Example:
// Get RHS
double rhs = constr.get(GRB.DoubleAttr.QCRHS);
int get(GRB.IntAttr attr)#

查询一个整数值二次约束属性的值。

Arguments:

attr – 被查询的属性。

Return value:

请求属性的当前值。

Example:
// Get information whether constraint participates in a previously computed IIS
int iisqconstr = constr.get(GRB.IntAttr.IISQConstr);
String get(GRB.StringAttr attr)#

查询一个字符串值的二次约束属性的值。

Arguments:

attr – 被查询的属性。

Return value:

请求属性的当前值。

Example:
// Get constraint name
String name = constr.get(GRB.StringAttr.QCName);
void set(GRB.CharAttr attr, char newval)#

设置一个字符型二次约束属性的值。

Arguments:
  • attr – 正在修改的属性。

  • newval – 属性的期望新值。

Example:
// Set constraint sense
constr.set(GRB.CharAttr.QCSense, '>');
void set(GRB.DoubleAttr attr, double newval)#

设置一个双值二次约束属性的值。

Arguments:
  • attr – 正在修改的属性。

  • newval – 属性的期望新值。

Example:
// Set RHS
constr.set(GRB.DoubleAttr.QCRHS, 2.0);
void set(GRB.IntAttr attr, int newval)#

设置一个整数值的二次约束属性的值。

Arguments:
  • attr – 正在修改的属性。

  • newval – 属性的期望新值。

Example:
// Force constraint into IIS
constr.set(GRB.IntAttr.IISQConstrForce, 1);
void set(GRB.StringAttr attr, String newval)#

设置字符串值二次约束属性的值。

Arguments:
  • attr – 正在修改的属性。

  • newval – 属性的期望新值。

Example:
// Set constraint name
constr.set(GRB.StringAttr.QCName, "newName");