8.4.10. MDOQuadExpr

class MDOQuadExpr

Represent a quadratic expression in MindOpt application. A quadratic expression has quadratic terms plus a linear expression.

Methods

MDOQuadExpr

Construct a quadratic expression with a constant value

MDOQuadExpr

Construct a quadratic expression with a linear term

MDOQuadExpr

Construct a quadratic expression with a linear expression

add

Add a linear expression to this quadratic expression

addConstant

Add a value to the constant contained in quadratic expression

addTerm

Add a linear term to this quadratic expression

addTerm

Add a quadratic term to this quadratic expression

addTerms

Add linear terms to this quadratic expression

addTerms

Add quadratic terms to this quadratic expression

clear

Clear all terms contained in quadratic expression and reset constant to zero

getCoeff

Retrieve the coefficient of the ith quadratic term

getLinExpr

Retrieve the linear expression contained in quadratic term

getValue

Calculate the value of this quadratic expression after problem was solved

getVar1

Retrieve the first variable of the ith quadratic term

getVar2

Retrieve the second variable of the ith quadratic term

remove

Remove the ith quadratic term from this quadratic expression

remove

Remove all terms (include linear terms and quadratic terms) containing a specified variable

size

Retrieve the number of quadratic terms contained in this quadratic expression

MDOQuadExpr(double constant = 0.0)

Construct a quadratic expression with a constant value.

Parameters

double constant=0.0 – The initial constant value.

MDOQuadExpr(MDOVar var, double coeff = 1.0)

Construct a quadratic expression with a linear term.

Parameters
  • MDOVar var – The variable of linear term.

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

MDOQuadExpr(MDOLinExpr le)

Construct a quadratic expression with a linear expression.

Parameters

MDOLinExpr le – The initial linear expression.

void add(const MDOLinExor le)

Add a linear expression to this quadratic expression.

Parameters

const MDOLinExor le – The linear expression to be added.

void addConstant(double c)

Add a value to the constant contained in quadratic expression.

Parameters

double c – The value to be added.

void addTerm(double coeff, MDOVar var)

Add a linear term to this quadratic expression.

Parameters
  • double coeff – The coefficient of linear term to be added.

  • MDOVar var – The variable of linear term to be added.

void addTerm(double coeff, MDOVar var1, MDOVar var2)

Add a quadratic term to this quadratic expression.

Parameters
  • double coeff – The coefficient of quadratic term to be added.

  • MDOVar var1 – The first variable of quadratic term to be added.

  • MDOVar var2 – The second variable of quadratic term to be added.

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

Add linear terms to this quadratic expression.

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

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

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

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

Add quadratic terms to this quadratic expression.

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

  • const MDOVar* var1 – The first variables of quadratic terms to be added.

  • const MDOVar* var2 – The second variables of quadratic terms to be added.

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

void clear()

Clear all terms contained in quadratic expression and reset constant to zero.

double getCoeff(int i)

Retrieve the coefficient of the ith quadratic term.

Parameters

int i – The index of quadratic term.

Returns

The coefficient of the ith quadratic term.

MDOLinExpr getLinExpr()

Retrieve the linear expression contained in quadratic term.

Returns

The linear expression contained in quadratic term.

double getValue()

Calculate the value of this quadratic expression after problem was solved.

Returns

The value of this quadratic expression after problem was solved.

MDOVar getVar1(int i)

Retrieve the first variable of the ith quadratic term.

Parameters

int i – The index of quadratic term.

Returns

The first variable of the ith quadratic term.

MDOVar getVar2(int i)

Retrieve the second variable of the ith quadratic term.

Parameters

int i – The index of quadratic term.

Returns

The second variable of the ith quadratic term.

void remove(int i)

Remove the ith quadratic term from this quadratic expression.

Parameters

int i – The index of quadratic term to be removed.

bool remove(MDOVar v)

Remove all terms (include linear terms and quadratic terms) containing a specified variable.

Parameters

MDOVar v – The variable contained to be removed.

Returns

True if at least 1 term was removed.

int size()

Retrieve the number of quadratic terms contained in this quadratic expression.

Returns

The number of quadratic terms contained in this quadratic expression.