7.2.1. MdoCol

class mindopt::MdoCol

A column 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 input a column into the optimization model are:

  1. Create an empty column object by calling MdoCol::MdoCol().

  2. Input nonzero elements by calling MdoCol::addTerms().

A nonzero element can be queried by calling MdoCol::getCons() and MdoCol::getCoeff() to access the associated constraint and coefficient.

Note

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

Examples

/* Create an empty model. */
MdoModel model;

MdoI32 itmp = 0;
MdoReal dtmp = 0.0;

/* Add empty constraints. */
std::vector<std::reference_wrapper<MdoCons> > cons;
cons.push_back(model.addCons(1.0, 1.0,           "c0"));
cons.push_back(model.addCons(1.0, MDO_INFINITY,  "c1"));

/* Input columns. */
std::vector<MdoCol> col(4);
col[0].addTerm(cons[0], 1.0);
col[0].addTerm(cons[1], 1.0);
col[1].addTerm(cons[0], 1.0);
col[2].addTerm(cons[0], 2.0);
col[2].addTerm(cons[1], -1.0);
col[3].addTerm(cons[0], 3.0);
col[3].addTerm(cons[1], 6.0);

/* Populate column object */
std::cout << "Original col: " << std::endl;
std::cout << "col[0]: " << col[0] << std::endl;
std::cout << "col[1]: " << col[1] << std::endl;
std::cout << "col[2]: " << col[2] << std::endl;

/* Check column */
MdoCons c0 = model.getCons(0);
dtmp = col[0].getCoeff(0);
itmp = col[0].getSize();

/* Remove value from column */
col[0].removeTerm(1);
itmp = col[0].getSize();
col[1].removeTerm(c0);
itmp = col[1].getSize();
col[0].clear();
itmp = col[0].getSize();

/* Adds another column object to itself. */
double *col_coeff_array = new double[col[2].getSize()];
double *col_coeff_chk = new double[col[2].getSize()];
col[0].addCol(col[2], 2);

for (int i=0; i < col[2].getSize(); i++)
{
    col_coeff_array[i] = col[0].getCoeff(i);
    col_coeff_chk[i] = 2 * col[2].getCoeff(i);
}

/* Adds a nonzero term. */
col[1].addTerm(c0, 3);
dtmp = col[1].getCoeff(0);

Constructor / destructor.

MdoCol(void)

Default constructor.

virtual ~MdoCol(void)

Destructor.

MdoCol(const MdoCol &rhs)

Copy constructor.

Parameters

rhs – Object to copy.

Basic operators.

MdoCol &operator=(const MdoCol &rhs)

Assignment operator.

Parameters

rhs – Object to copy.

Return

Updated object.

Functions to access the internal data.

void addCol(const MdoCol &col, MdoReal multipiler)

This function adds another column object to itself.

Parameters
  • col – A column object to be added.

  • multipiler – A constant multiplier.

void addTerm(const MdoCons &cons, MdoReal coeff)

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

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

  • coeff – A coefficient of the nonzero term.

void addTerms(std::vector<std::reference_wrapper<MdoCons>> &conss, const MdoReal *coeffs, MdoI32 size)

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

Parameters
  • conss – A vector object that holds the references to the constraint objects.

  • coeffs – An array that holds the nonzero coefficients.

  • size – Number of terms to be added.

const MdoCons &getCons(MdoI32 pos) const

This function retrieves the the constraint object from the column object.

Parameters

pos – The term that is currently stored at position pos.

Return

The constraint object.

MdoCons &getCons(MdoI32 pos)

This function retrieves the the constraint object from the column object.

Parameters

pos – The term that is currently stored at position pos.

Return

The constraint object.

MdoReal getCoeff(MdoI32 pos) const

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

Parameters

pos – The term that is currently stored at position pos.

Return

The value of the nonzero element.

void removeTerm(MdoI32 pos)

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

Parameters

pos – The term that is currently stored at position pos.

MdoBool removeTerm(const MdoCons &cons)

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

Parameters

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

Return

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

void clear(void)

This function removes all nonzero elements from the column object.

MdoI32 getSize(void) const

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

Returns

the number of nonzero elements stored in the column object.