8.5.11. MDOQuadExpr¶
-
class MDOQuadExpr¶
Represent a quadratic expression in MindOpt application. A quadratic expression has quadratic terms plus a linear expression.
Methods
Construct a quadratic expression with a constant value
Construct a quadratic expression with a linear term
Construct a quadratic expression with a linear expression
Add a linear expression to this quadratic expression
Add a value to the constant contained in quadratic expression
Add a linear term to this quadratic expression
Add a quadratic term to this quadratic expression
Add linear terms to this quadratic expression
Add quadratic terms to this quadratic expression
Clear all terms contained in quadratic expression and reset constant to zero
Retrieve the coefficient of the ith quadratic term
Retrieve the linear expression contained in quadratic term
Calculate the value of this quadratic expression after problem was solved
Retrieve the first variable of the ith quadratic term
Retrieve the second variable of the ith quadratic term
Remove the ith quadratic term from this quadratic expression
Remove all terms (include linear terms and quadratic terms) containing a specified variable
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(const MDOLinExpr &le)¶
Construct a quadratic expression with a linear expression.
- Parameters
const MDOLinExpr& le – The initial linear expression.
-
void add(const MDOLinExpr le)¶
Add a linear expression to this quadratic expression.
- Parameters
const MDOLinExpr 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.
-
MDOQuadExpr(double constant = 0.0)¶