XPRBexpr
XPRBexpr |
Description
Methods and operators for constructing
linear and quadratic expressions. Note that all variables in an expression must belong to the same problem.
Constructors
XPRBexpr(double d);
XPRBexpr(int i);
XPRBexpr(double d, XPRBvar& v);
XPRBexpr(double d, XPRBvar& v, XPRBvar& v2);
XPRBexpr(XPRBvar& v);
XPRBexpr(XPRBexpr& e);
XPRBexpr(int i);
XPRBexpr(double d, XPRBvar& v);
XPRBexpr(double d, XPRBvar& v, XPRBvar& v2);
XPRBexpr(XPRBvar& v);
XPRBexpr(XPRBexpr& e);
Methods
Addition to an expression
int addTerm(XPRBvar& var, XPRBvar& var2, double val);
int addTerm(double val, XPRBvar& var, XPRBvar& var2);
int addTerm(XPRBvar& var, double val);
int addTerm(double val, XPRBvar& var);
int addTerm(XPRBvar& var);
int addTerm(double val);
int addTerm(double val, XPRBvar& var, XPRBvar& var2);
int addTerm(XPRBvar& var, double val);
int addTerm(double val, XPRBvar& var);
int addTerm(XPRBvar& var);
int addTerm(double val);
Add a term to an expression.
Copy an expression.
Delete a term from an expression.
Get evaluation of an expression.
Multiply an expression by a constant factor or an expression.
Negation of an expression.
int setTerm(XPRBvar& var, XPRBvar& var2, double val);
int setTerm(double val, XPRBvar& var, XPRBvar& var2);
int setTerm(XPRBvar& var, double val);
int setTerm(double val, XPRBvar& var);
int setTerm(double val);
int setTerm(double val, XPRBvar& var, XPRBvar& var2);
int setTerm(XPRBvar& var, double val);
int setTerm(double val, XPRBvar& var);
int setTerm(double val);
Set a term in an expression.
Operators
Assigning (elements to) expressions:
Composing expressions from other quadratic and linear expressions (
expr), variables (
var) and double values (
val). The following operators are defined:
-
var
expr1 -
expr2
val *
expr
var *
val
val *
var
var *
val
var *
expr
Throws exception `Non-quadratic expression' if the result of the operation is not quadratic
expr *
var
Throws exception `Non-quadratic expression' if the result of the operation is not quadratic
expr1 *
expr2
Throws exception `Non-quadratic expression' if the result of the operation is not quadratic
Functions outside any class definition that generate quadratic expressions:
Square of an expression or variable.
Constructor detail
Method detail
add
|
|||||
Synopsis
|
XPRBexpr& add(XPRBexpr& e);
XPRBexpr& add(XPRBvar& v); |
||||
Arguments
|
|
||||
Return value
|
The modified expression.
|
||||
Description
|
|||||
Example
|
See
XPRBexpr.setTerm.
|
||||
addTerm
|
|||||
Synopsis
|
int addTerm(XPRBvar& var, XPRBvar& var2, double val);
int addTerm(double val, XPRBvar& var, XPRBvar& var2); int addTerm(XPRBvar& var, double val); int addTerm(double val, XPRBvar& var); int addTerm(XPRBvar& var); int addTerm(double val); |
||||
Arguments
|
|
||||
Return value
|
The modified expression.
|
||||
Description
|
This method adds a new term to an expression comprising the variable
var (or the product of variables
var and
var2) with coefficient
val. If the expression already has a term with variable
var (respectively variables
var and
var2),
val is added to its coefficient. If no variable is specified, the value
val is added to the constant term of the expression. Terms can also be added with method
XPRBexpr.add.
|
||||
Example
|
See
XPRBexpr.setTerm.
|
||||
assign
|
|||||
Synopsis
|
XPRBexpr& assign(XPRBexpr& e);
|
||||
Argument
|
|
||||
Return value
|
Copy of the expression in the argument.
|
||||
Description
|
|||||
delTerm
|
|||||
Synopsis
|
int delTerm(XPRBvar& var);
int delTerm(XPRBvar& var, XPRBvar& var2); |
||||
Argument
|
|
||||
Return value
|
The modified expression.
|
||||
Description
|
This function deletes a variable term from an expression. The constant term is changed or reset with method
XPRBexpr.setTerm.
|
||||
Example
|
See
XPRBexpr.setTerm.
|
||||
getSol
|
|||||
Synopsis
|
double getSol();
|
||||
Return value
|
Evaluation of the expression with the last solution.
|
||||
Description
|
This method returns the evaluation of an expression with the solution values from the last solution found. If this method is called after completion of a global search and an integer solution has been found (that is, if method
XPRBprob.getMIPStat returns values
XPRB_MIP_SOLUTION or
XPRB_MIP_OPTIMAL), it returns the value corresponding to the best integer solution. If no integer solution is available after a global search this method outputs a warning and returns 0. In all other cases it returns the evaluation corresponding to the last LP that has been solved. If this method is used
during the execution of an optimization process (for instance in Optimizer library callback functions) it needs to be preceded by a call to
XPRBprob.sync with the flag
XPRB_XPRS_SOL.
|
||||
mul
|
|||||
Synopsis
|
XPRBexpr& mul(double d);
XPRBexpr& mul(XPRBexpr& e); |
||||
Arguments
|
|
||||
Return value
|
The modified expression.
|
||||
Error handling
|
ArithmeticException `Non-quadratic expression' if the result of the operation is not quadratic.
|
||||
Description
|
|||||
Example
|
See
XPRBexpr.setTerm.
|
||||
neg
|
|||||
Synopsis
|
XPRBexpr& neg();
|
||||
Return value
|
Negation of the expression.
|
||||
Description
|
|||||
Example
|
See
XPRBexpr.setTerm.
|
||||
setTerm
|
|||||
Synopsis
|
int setTerm(XPRBvar& var, XPRBvar& var2, double val);
int setTerm(double val, XPRBvar& var, XPRBvar& var2); int setTerm(XPRBvar& var, double val); int setTerm(double val, XPRBvar& var); int setTerm(double val); |
||||
Arguments
|
|
||||
Return value
|
The modified expression.
|
||||
Description
|
|||||
Example
|
This example shows different ways of defining and modifying a quadratic expression and finally sets the resulting expression as objective function. The comments display the definition of
qe after each modification.
XPRBvar x,y; XPRBexpr qe; XPRBprob prob("myprob"); x = prob.newVar("x", XPRB_PL, 0, 200); y = prob.newVar("y", XPRB_PL, 0, 200); qe = x; // x qe.mul(3*x); // 3*x^2 qe += x*2*y; // 3*x^2 + 2*x*y qe.add(1); // 1 + 3*x^2 + 2*x*y qe.setTerm(3, x); // 1 + 3*x + 3*x^2 + 2*x*y qe.setTerm(0, x, y); // 1 + 3*x + 3*x^2 qe.delTerm(x, x); // 1 + 3*x qe.setTerm(-1); // - 1 + 3*x qe.addTerm(2, x); // - 1 + 5*x qe -= 3*sqr(3*y); // - 1 + 5*x - 27*y^2 qe.neg(); // 1 - 5*x + 27*y^2 prob.setObj(qe); |
sqr
|
|||||
Synopsis
|
XPRBexpr sqr(XPRBexpr& e);
XPRBexpr sqr(XPRBvar& var); |
||||
Arguments
|
|
||||
Return value
|
The square of the variable or expression in the argument.
|
||||
Description
|
|||||
Example
|
See
XPRBexpr.setTerm.
|
||||
|