GRBGenConstr#
- GRBGenConstr#
Gurobi 通用约束对象。通用约束总是与特定模型相关联。您通过向模型添加通用约束(使用
GRBModel.addGenConstr*
方法之一)来创建通用约束对象,而不是通过使用GRBGenConstr
构造函数。通用约束对象上的方法用于获取和设置约束属性。例如,可以通过调用
get
(GRB.IntAttr.GenConstrType
)来查询通用约束类型。然而,请注意,通常更高效的做法是一次性查询一组约束的属性。这是通过在GRBModel
对象上使用属性查询方法(GRBModel.get
)来完成的。- double get(GRB.DoubleAttr attr)#
查询一个双值通用约束属性的值。
- Arguments:
attr – 被查询的属性。
- Return value:
请求属性的当前值。
- Example:
// Get PWL approximation error double funcpieceerror = gc.get(GRB.DoubleAttr.FuncPieceError);
- int get(GRB.IntAttr attr)#
查询一个整数值的通用约束属性的值。
- Arguments:
attr – 正在查询的属性。
- Return value:
请求属性的当前值。
- Example:
// Get general constraint type int type = gc.get(GRB.IntAttr.GenConstrType);
- String get(GRB.StringAttr attr)#
查询字符串值的一般约束属性的值。
- Arguments:
attr – 被查询的属性。
- Return value:
请求属性的当前值。
- Example:
// Get general constraint name String name = gc.get(GRB.StringAttr.GenConstrName);
- void set(GRB.DoubleAttr attr, double newval)#
设置一个双精度值的一般约束属性的值。
- Arguments:
attr – 正在修改的属性。
newval – 属性的期望新值。
- Example:
// Set PWL approximation error gc.set(GRB.DoubleAttr.FuncPieceError, 1e-4);
- void set(GRB.IntAttr attr, int newval)#
设置一个整数值的通用约束属性的值。
- Arguments:
attr – 正在修改的属性。
newval – 属性的期望新值。
- Example:
// Set number of PWL pieces gc.set(GRB.IntAttr.FuncPieces, 100);
- void set(GRB.StringAttr attr, String newval)#
设置字符串值的一般约束属性的值。
- Arguments:
attr – 正在修改的属性。
newval – 属性的期望新值。
- Example:
// Set name of general constraint gc.set(GRB.StringAttr.GenConstrName, "newName");