8.6.16. Column¶
- class Column¶
Column contains the coefficient information of a variable in existing constraints. When adding a variable, A column can be provided to initialize the coefficients of the variable in existing constraints. For example:
col = Column(model.getConstrs(), coeffs) v = model.addVar(column = col)
Methods
Construct a Column
Add one or more term(s)
Clear all included terms
Return a copy of a Column
Obtain the coefficient of a term in a Column
Get the constraint of a term in a Column
Delete some terms contained in Column
Obtain the number of terms
- __init__(coeffs=None, constrs=None)¶
Construct a Column
- Parameters
coeffs=None – The initial coefficient of the Column, which can be a number or an array.
constrs=None – The initial constraint of a Column, which can be a constraint or an array.
example:
Column(1, c0) Column([1, 2, 3], [c0, c1, c2])
- addTerms(coeffs, constrs)¶
Add one or more term(s)
- Parameters
coeffs – The coefficient of the term(s) to be added, which can be a number or an array.
constrs – The constraint of the term(s) to be added, which can be a single constraint or an array.
example:
column.addTerms([1, 2], [c0, c1]) column.addTerms(1, c0)
- clear()¶
Clear all included terms
example:
column = Column([1, 2], [c0, c1]) column.clear() print(column.size() == 0)
- copy()¶
Return a copy of a Column.
example:
another = column.copy()
- getCoeff(index)¶
Obtain the coefficient of a term in a Column.
- Parameters
index – The index of the term to obtain the coefficient.
example:
column = Column([1, 2], [c0, c1]) print(column.getCoeff(1) == 2.0)
- getConstr(index)¶
Get the constraint of a term in a Column.
- Parameters
index – The index of the term to obtain the constraint.
example:
column = Column([1, 2], [c0, c1]) print(column.getConstr(1).sameAs(c1))
- remove(item)¶
Delete some terms contained in Column
- Parameters
item – If item is a number, the term whose index is item is deleted. If the item is a constraint, all terms that contain the constraint are deleted.
example:
column = Column([1, 2], [c0, c1]) column.remove(0) column.remove(c1) print(column.size() == 0)
- size()¶
Obtain the number of terms.
example:
column = Column([1, 2], [c0, c1]) print(column.size() == 2)