Initializing help system before first use

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
Methods
Addition to an expression
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.
Set a term in an expression.
Operators
Assigning (elements to) expressions:
expr1 += expr2
expr1 -= expr2
expr1 = expr2
Composing expressions from other quadratic and linear expressions ( expr), variables ( var) and double values ( val). The following operators are defined:
- var
- expr
expr1 + expr2
expr1 - expr2
expr * val
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

XPRBexpr
Synopsis
XPRBexpr(double d);
XPRBexpr(int i);
XPRBexpr(double d, XPRBvar& v);
XPRBexpr(double d, XPRBvar& v, XPRBvar& v2);
XPRBexpr(XPRBvar& v);
XPRBexpr(XPRBexpr& e);
Arguments
A real value.
An integer value.
v,v2 
BCL variables (may be the same).
A linear or quadratic expression.
Description
Create a new expression.

Method detail

add
Synopsis
XPRBexpr& add(XPRBexpr& e);
XPRBexpr& add(XPRBvar& v);
Arguments
A linear or quadratic expression (may be just a constant).
A BCL variable.
Return value
The modified expression.
Description
This method adds an expression / constant / variable to the linear or quadratic expression it is applied to.
Example

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
var,var2 
BCL decision variables (may be the same).
val 
A real value (coefficient).
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

assign
Synopsis
XPRBexpr& assign(XPRBexpr& e);
Argument
Expression to be copied.
Return value
Copy of the expression in the argument.
Description
This method copies the given expression.

delTerm
Synopsis
int delTerm(XPRBvar& var);
int delTerm(XPRBvar& var, XPRBvar& var2);
Argument
var,var2 
BCL decision variables (may be the same).
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

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
A constant.
An expression (may be just a constant or a single decision variable).
Return value
The modified expression.
Error handling
ArithmeticException `Non-quadratic expression' if the result of the operation is not quadratic.
Description
This method multiplies an expression by a constant factor or another expression. This operation succeeds if one of the expressions is just a constant or if both expressions have only linear terms.
Example

neg
Synopsis
XPRBexpr& neg();
Return value
Negation of the expression.
Description
This method multiplies an expression with -1.
Example

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
var,var2 
BCL decision variables (may be the same).
val 
A real value (coefficient).
Return value
The modified expression.
Description
This method sets the coefficient of a variable or of the product of the two specified variables to the value val. If no variable is specified, the constant term of the expression is set to val.
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
An expression.
var 
A BCL decision variable.
Return value
The square of the variable or expression in the argument.
Description
This function returns the square of the variable or expression passed in the argument if the result is at most quadratic.
Example


© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.