8.3.1. MdoCol

class mindoptpy.MdoCol

Bases: object

This object implements the data structure to hold a column object, which consists of a set of constraint and coefficient pairs.

Typical steps to to input a column into the optimization model are:

  1. Create an empty column object, mindoptpy.MdoCol().

  2. Input nonzero elements by calling mindoptpy.MdoCol.add_terms().

A nonzero element can be queried by calling mindoptpy.MdoCol.get_coeff() to access the associated constraint and coefficient.

Note

This is a temporary object with a short lifespan in general.

Examples

from mindoptpy import *

# Create an empty model.
model = MdoModel()
MDO_INFINITY = MdoModel.get_infinity()

# Add variables.
x1 = model.add_var(0, MDO_INFINITY, 1, None, "x1", False)
x2 = model.add_var(0, MDO_INFINITY, 1, None, "x2", False)
x3 = model.add_var(0, 3, 1, None, "x2", False)

# Set/get column object
col1 = MdoCol()
col1.add_term(x2, 1)
col1.add_terms([x3], [2])
col1.get_terms()
col1.get_coeff(0)
col1.get_coeff(1)
col1.get_size()

# Remove
col1.remove_cons((col1.get_cons(1)))
col1.remove_term(0)
col1.clear()
col1.get_size()

Methods

add_term()

This function adds a nonzero term.

add_terms()

This function adds a set of nonzero terms.

clear()

This function removes all nonzero elements from the column object.

get_coeff()

This function returns the value of a nonzero element from the column object.

get_cons()

This function returns the constraint object from the column object.

get_size()

This function returns the number of nonzero elements stored in the column object.

get_terms()

This function returns the nonzero elements stored in the column object.

remove_cons()

This function removes a nonzero element from the column object, given a constraint object.

remove_term()

This function removes a nonzero element from the column object, given a constraint index.

add_term(cons: mindoptpy.MdoCons, coeff: float)

This function adds a nonzero term. A nonzero term is a pair of constraint and coefficient.

Parameters
  • cons (MdoCons) – A constraint object associated with the nonzero term.

  • coeff (float) – A coefficient of the nonzero term.

add_terms(conss: Union[list, mindoptpy.MdoCons], coeffs: Union[list, float])

This function adds a set of nonzero terms. A nonzero term is a pair of constraint and coefficient.

Parameters
  • conss (array-like or single constraint object) – An array that holds the constraint objects, or a single constraint object.

  • coeffs (array-like or a single coefficient) – An array that holds the coefficients of the nonzero terms, or a single coefficient.

clear()

This function removes all nonzero elements from the column object.

get_coeff(pos: int)

This function returns the value of a nonzero element from the column object.

Parameters

pos (int) – The term that is currently stored at position pos.

Returns

The value of the nonzero coefficient.

Return type

float

get_cons(pos: int)

This function returns the constraint object from the column object.

Parameters

pos (int) – The term that is currently stored at position pos.

Returns

The corresponding constraint object of the nonzero coefficient.

Return type

MdoCons

get_size()

This function returns the number of nonzero elements stored in the column object.

Returns

The numner of nonzero elements stored in the column object.

Return type

int

get_terms()

This function returns the nonzero elements stored in the column object.

Returns

The nonzero elements stored in the column object.

Return type

array-like

remove_cons(cons: mindoptpy.MdoCons)

This function removes a nonzero element from the column object, given a constraint object.

Parameters

cons (MdoCons) – A constraint object whose nonzero coefficient will be removed.

Returns

Return true if the specified coefficient is in the column and has been removed.

Return type

bint

remove_term(pos: int)

This function removes a nonzero element from the column object, given a constraint index.

Parameters

pos (int) – The term that is currently stored at position pos.