GRB列#
- GRBColumn#
Gurobi列对象。列由一系列系数和约束对组成。列用于表示变量参与的约束集及其相关系数。它们是临时对象,通常具有较短的寿命。
通常,您通过从一个空列开始(使用
GRBColumn构造函数)来构建列,然后添加项。可以使用addTerm单独添加项,或使用addTerms批量添加项。也可以使用remove从列中移除项。可以使用
getConstr和getCoeff方法查询列中的单个项。可以使用size方法查询列中的项数。- GRBColumn GRBColumn()#
创建一个空列的列构造函数。
- Return value:
一个空的列对象。
- Example:
// Create an empty column object GRBColumn col = new GRBColumn();
- GRBColumn GRBColumn(GRBColumn col)#
复制现有列的列构造函数。
- Arguments:
col – 现有的列对象。
- Return value:
输入列对象的副本。
- Example:
// Copy an existing column object GRBColumn colCopy = new GRBColumn(col);
- void addTerm(double coeff, GRBConstr constr)#
将单个术语添加到列中。
- Arguments:
coeff – 新项的系数。
constr – 新术语的约束。
- Example:
// Add coefficient-constraint pair (2.0, constr1) to a column object col.addTerm(2.0, constr1);
- void addTerms(double[] coeffs, GRBConstr[] constrs)#
将一系列术语添加到列中。请注意,两个参数数组的长度必须相等。
- Arguments:
coeffs – 添加约束的系数。
constrs – 要添加到列的约束。
- Example:
// Add 3 trivial linear constraints to the model GRBConstr[] constrs = model.addConstrs(3); // Coefficients for the new column double[] coeffs = {1.0, 2.0, 3.0}; // Create and fill GRBColumn object GRBColumn col = new GRBColumn(); col.addTerms(coeffs, constrs);
- void addTerms(double[] coeffs, GRBConstr[] constrs, int start, int len)#
向列中添加新项。此签名允许您使用数组来保存描述数组中项的系数和约束,而不必为数组中的每个成员添加一个项。
start和len参数允许您指定要添加的项。- Arguments:
coeffs – 添加约束的系数。
constrs – 要添加到列的约束。
start – 要添加的列表中的第一项。
len – 要添加的项数。
- Example:
// Add 3 trivial linear constraints to the model GRBConstr[] constrs = model.addConstrs(3); // Coefficients for the new column double[] coeffs = {1.0, 2.0, 3.0}; // Create and fill GRBColumn object, but use only first 2 pairs GRBColumn col = new GRBColumn(); col.addTerms(coeffs, constrs, 0, 2);
- void clear()#
从列中移除所有术语。
- Example:
// Clear all terms from the column col.clear();
- double getCoeff(int i)#
从列中的单个项中检索系数。
- Arguments:
i – 感兴趣的系数的索引。
- Return value:
列中索引为
i的项的系数。- Example:
// Get the coefficient of the first coefficient-constraint pair double coeff = col.getCoeff(0);
- GRBConstr getConstr(int i)#
从列中的单个项中检索约束对象。
- Arguments:
i – 感兴趣的术语的索引。
- Return value:
列中索引为
i的项的约束。- Example:
// Get the constraint of the first coefficient-constraint pair GRBConstr constr = col.getConstr(0);
- void remove(int i)#
移除存储在列的索引
i处的项。- Arguments:
i – 要删除的项的索引。
- Example:
// Remove the first coefficient-constraint pair from the column col.remove(0);
- boolean remove(GRBConstr constr)#
从列中移除与约束
constr相关的术语。- Arguments:
constr – 应删除其项的约束。
- Return value:
如果约束出现在列中(并且已被移除),则返回
true。- Example:
// Remove the pair associated with constr1 boolean removed = col.remove(constr1);
- int size()#
检索列中的术语数量。
- Return value:
列中的术语数量。
- Example:
// Get the number of terms in the column int size = col.size();