8.5.10. MDOLinExpr

class MDOLinExpr

Represent a linear expression in MindOpt application. A linear expression may contain linear terms and a constant.

Methods

MDOLinExpr

Construct a MDOLinExpr with constant value

MDOLinExpr

Construct a MDOLinExpr with a linear term

addConstant

Add a value to the constant contained in linear expression

addTerms

Add linear terms to this linear expression

clear

Clear this linear expression, that is, remove all terms and reset its constant to zero

getCoeff

Retrieve the coefficient contained in ith linear term

getConstant

Retrieve the value of constant contained in linear expression

getValue

Calculate the value of this linear expression after problem solved

getVar

Retrieve the variable contained in ith linear term

remove

Remove a linear term from this linear expression by its index

remove

Remove all linear terms containing a specified variable

size

Retrieve the total number of linear terms contained in linear expression

MDOLinExpr(double constant = 0.0)

Construct a MDOLinExpr with constant value.

Parameters

double constant=0.0 – The initial constant value.

MDOLinExpr(MDOVar var, double coeff = 1.0)

Construct a MDOLinExpr with a linear term.

Parameters
  • MDOVar var – The varible of linear term.

  • double coeff=1.0 – The coefficient of linear term.

void addConstant(double c)

Add a value to the constant contained in linear expression.

Parameters

double c – The value to be added.

void addTerms(const double *coeff, const MDOVar *var, int cnt)

Add linear terms to this linear expression.

Parameters
  • const double* coeff – The coefficients of terms to be added.

  • const MDOVar* var – The variables of terms to be added.

  • int cnt – The number of terms to be added.

void clear()

Clear this linear expression, that is, remove all terms and reset its constant to zero.

double getCoeff(int i)

Retrieve the coefficient contained in ith linear term.

Parameters

int i – The index of linear term.

Returns

The coefficient contained in ith linear term.

double getConstant()

Retrieve the value of constant contained in linear expression.

Returns

The value of constant contained in linear expression.

double getValue()

Calculate the value of this linear expression after problem solved.

Returns

The value of this linear expression.

MDOVar getVar(int i)

Retrieve the variable contained in ith linear term.

Parameters

int i – The index of linear term.

Returns

The variable contained in ith linear term.

void remove(int i)

Remove a linear term from this linear expression by its index.

Parameters

int i – The index of term to be removed.

bool remove(MDOVar v)

Remove all linear terms containing a specified variable.

Parameters

MDOVar v – The contained variable to be removed.

Returns

True if at least 1 term was removed.

unsigned int size()

Retrieve the total number of linear terms contained in linear expression

Returns

The total number of linear terms