Minotaur 0.4.1
Docs for developers
|
Public Member Functions | |
CGraph () | |
Default constructor. | |
~CGraph () | |
Default constructor. | |
void | addConst (const double eps, int &err) |
Add a constant to the function. More... | |
NonlinearFunctionPtr | clone (int *err) const |
NonlinearFunctionPtr | cloneWithVars (VariableConstIterator, int *) const |
Make a clone using new variables. More... | |
NonlinearFunctionPtr | getPersp (VariablePtr z, double eps, int *err) const |
Take perspective of this function with respect to a given variable. More... | |
NonlinearFunctionPtr | getPersp (VariablePtr z, double eps, int *err, QuadraticFunctionPtr qf, UInt maxId, VariableGroup nNonzeroVar, double intTol) |
void | computeBounds (double *lb, double *ub, int *error) |
Calculate upper and lower bounds on the function using bounds of the variables. More... | |
double | eval (const double *x, int *err) |
Evaluate the function at a given point x. More... | |
void | evalGradient (const double *x, double *grad_f, int *error) |
Evaluate and add gradient at a given point. More... | |
void | evalHessian (double mult, const double *x, const LTHessStor *stor, double *values, int *error) |
Evaluate and add hessian at a given point. More... | |
void | fillHessStor (LTHessStor *stor) |
Fill sparsity of hessian into hessian storage. More... | |
void | finalHessStor (const LTHessStor *stor) |
Finalize hessian preparation. More... | |
void | fillJac (const double *x, double *values, int *error) |
Evaluate and add gradient at a given point to the jacobian. More... | |
void | finalize () |
double | getFixVarOffset (VariablePtr v, double val) |
If a variable is fixed at a given value and removed, what is the constant (offset) needed to be added. More... | |
CNode * | getVarNode (VariablePtr v) |
CNode * | getPerspZNode () |
FunctionType | getType () const |
Return the type of function: polynomial, ... More... | |
std::string | getNlString (int *err) |
Return a string in AMPL's .nl format (postfix notation) of this nonlinear function. More... | |
size_t | getNumNodes () |
size_t | getHessNz () |
bool | ifLinear (LinearFunctionPtr lf, UInt pv, double *consVal) |
void | resetNodeIndex () |
const CNode * | getOut () const |
Get the output node. | |
VariablePtr | getVar (const CNode *cnode) const |
void | getVars (VariableSet *vars) |
Get variables used in this function. More... | |
bool | isIdenticalTo (CGraphPtr cg) |
bool | isSumOfSquares () const |
Check if the function is a sum of square terms. More... | |
void | multiply (double c) |
Multiply by a constant. More... | |
CNode * | newNode (OpCode op, CNode *lchild, CNode *rchild) |
Create a new node with one or two children, and add it to the graph. The children should already be a nodes of the graph. More... | |
CNode * | newNode (OpCode op, CNode **child, size_t n) |
Create a new node with more than two children, and add it to the graph. The children should already be a nodes of the graph. More... | |
CNode * | newNode (double d) |
Create a new node with constant real value. It does not have any children. More... | |
CNode * | newNode (int i) |
Create a new node with constant integer value. It does not have any children. More... | |
CNode * | newNode (VariablePtr v) |
Create a new node denoting an input variable. It does not have any children. More... | |
void | prepJac (VarSetConstIter vbeg, VarSetConstIter vend) |
Prepare for evaluating sparse jacobian. More... | |
void | removeVar (VariablePtr v, double val) |
Remove a variable v from the function after fixing it to value val. More... | |
void | setOut (CNode *node) |
Set the node that should be the output of this graph. This node should already be a part of this graph (created by newNode() function). More... | |
void | sqrRoot (int &err) |
Change the nonlinear function to its square-root. More... | |
void | subst (VariablePtr out, VariablePtr in, double rat) |
Substitute a variable with another. More... | |
void | varBoundMods (double lb, double ub, VarBoundModVector &mods, SolveStatus *status) |
Tighten variables based on function bounds. More... | |
CNodeQ | dNodes () |
void | write (std::ostream &out) const |
Display the nonlinear function. More... | |
![]() | |
NonlinearFunction () | |
Default constructor. | |
virtual | ~NonlinearFunction () |
Destroy. | |
virtual void | addConst (const double d, int &err) |
Add a constant to the function. More... | |
virtual void | sqrRoot (int &err) |
Change the nonlinear function to its square-root. More... | |
virtual NonlinearFunctionPtr | cloneWithVars (VariableConstIterator vbeg, int *err) const =0 |
Make a clone using new variables. More... | |
virtual void | computeBounds (double *lb, double *ub, int *error) |
Calculate upper and lower bounds on the function using bounds of the variables. More... | |
virtual double | eval (const double *x, int *error)=0 |
Evaluate the function at a given point x. More... | |
virtual void | evalGradient (const double *x, double *grad_f, int *error)=0 |
Evaluate and add gradient at a given point. More... | |
virtual void | evalHessian (const double mult, const double *x, const LTHessStor *stor, double *values, int *error)=0 |
Evaluate and add hessian at a given point. More... | |
virtual void | fillHessStor (LTHessStor *stor)=0 |
Fill sparsity of hessian into hessian storage. More... | |
virtual void | fillJac (const double *x, double *values, int *error)=0 |
Evaluate and add gradient at a given point to the jacobian. More... | |
virtual void | finalHessStor (const LTHessStor *stor)=0 |
Finalize hessian preparation. More... | |
virtual std::string | getNlString (int *err) |
Return a string in AMPL's .nl format (postfix notation) of this nonlinear function. More... | |
virtual double | getFixVarOffset (VariablePtr, double) |
If a variable is fixed at a given value and removed, what is the constant (offset) needed to be added. More... | |
virtual FunctionType | getType () const |
Return the type of function: polynomial, ... More... | |
virtual void | getVars (VariableSet *vars)=0 |
Get variables used in this function. More... | |
virtual bool | hasVar (ConstVariablePtr v) const |
Check if function contains a variable. More... | |
virtual bool | isSumOfSquares () const |
Check if the function is a sum of square terms. More... | |
virtual void | multiply (double c)=0 |
Multiply by a constant. More... | |
virtual size_t | numVars () |
Return the number of variables in this function. | |
virtual void | prepJac (VarSetConstIter vbeg, VarSetConstIter vend)=0 |
Prepare for evaluating sparse jacobian. More... | |
virtual void | removeVar (VariablePtr, double) |
Remove a variable v from the function after fixing it to value val. More... | |
virtual void | subst (VariablePtr, VariablePtr, double) |
Substitute a variable with another. More... | |
virtual NonlinearFunctionPtr | getPersp (VariablePtr z, double eps, int *err) const |
Take perspective of this function with respect to a given variable. More... | |
virtual void | varBoundMods (double, double, VarBoundModVector &, SolveStatus *) |
Tighten variables based on function bounds. More... | |
virtual VariableSet::iterator | varsBegin () |
First iterator for variables. More... | |
virtual VariableSet::iterator | varsEnd () |
Last iterator for variables. More... | |
virtual void | write (std::ostream &out) const |
Display the nonlinear function. More... | |
Additional Inherited Members | |
![]() | |
VariableSet | vars_ |
A set of variables used in this function. | |
|
virtual |
Add a constant to the function.
Add a constant to the given nonlinear function. Adding a constant alone usually does not make sense. However, it is useful as a intermediate step. For instance, in writing the perspective: z*f(x/(z+e))
[in] | d | The value of the constant. |
[out] | err | must be nonzero if the constant could not be added. |
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Make a clone using new variables.
[in] | vbeg | it points to the variable id 0. vbeg+k points to variable id k, where k>=0. |
[out] | err | must be nonzero if function wasn't cloned. |
Implements Minotaur::NonlinearFunction.
|
virtual |
Calculate upper and lower bounds on the function using bounds of the variables.
[out] | lb | Pointer that will contain the value of lower bound. |
[out] | ub | Pointer that will contain the value of upper bound. |
[out] | error | 0 if no error is encountered, nonzero otherwise. |
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Evaluate the function at a given point x.
[in] | x | The size of the array x must exceed the highest index of the variables used in the function. |
[out] | *error | It should be set a positive value if there is error encountered while evaluating. Leave undisturbed otherwise. |
Implements Minotaur::NonlinearFunction.
|
virtual |
Evaluate and add gradient at a given point.
[in] | x | The size of the array x must exceed the highest index of the variables used in the function. |
[out] | grad_f | The values of grad_f are incremented with the gradient of this function at x. The array grad_f is dense. |
[out] | error | It should be set a positive value if there is error encountered while evaluating. Leave undisturbed otherwise. |
Implements Minotaur::NonlinearFunction.
|
virtual |
Evaluate and add hessian at a given point.
[in] | mult | Multiplier for this objective/constraint function |
[in] | x | The point where we need the hessian. |
[in] | stor | The Hessian storage information. |
[out] | values | The Hessian values to which we add Hessian of this function. |
[out] | error | We set it to nonzero if any errors are encountered. Do not change it otherwise. |
Implements Minotaur::NonlinearFunction.
|
virtual |
Fill sparsity of hessian into hessian storage.
[in,out] | stor | We add variables into stor->cols |
Implements Minotaur::NonlinearFunction.
|
virtual |
Evaluate and add gradient at a given point to the jacobian.
[in] | x | The size of the array x must exceed the highest index of the variables used in the function. |
[out] | values | The values of jacobian are incremented with the gradient of this function at x. 'values' only contains nonzeros of jacobian. The indices (or offsets) where this nonlinear function should put in the values should be calculated in the prepJac function. |
[out] | error | It should be set a zero value if there is error encountered while evaluating. Leave undisturbed otherwise. |
Implements Minotaur::NonlinearFunction.
|
virtual |
Finalize hessian preparation.
[in] | stor | contains the sparsity pattern of hessian of lagrangian. The nonlinear function should save offsets or make other preparation to evaluate hessian. |
Implements Minotaur::NonlinearFunction.
void CGraph::finalize | ( | ) |
After adding all the nodes of the graph, finalize is called to create the forward and backward traversal queues, and related book-keeping.
|
virtual |
If a variable is fixed at a given value and removed, what is the constant (offset) needed to be added.
param [in] v The variable that is fixed.
param [in] val The value at which v is to be fixed.
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Return a string in AMPL's .nl format (postfix notation) of this nonlinear function.
param [out] err 0 if no errors were encountered.
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Take perspective of this function with respect to a given variable.
Perspective of a given function f(x) with respect to a given variable z is g(x,z) = z.f(x/z)
[in] | z | The variable for which you take the perspective |
[in] | eps | The tolerance to tackle function value at 0 value. If the perspective is approximated in the computational graph, the epsilon is added to the z variable. If the perspective uses exact graph, then an approximation in Hessian is used when z < eps. |
[out] | err | must be nonzero if function wasn't cloned. |
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Return the type of function: polynomial, ...
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Get variables used in this function.
[in] | vars | A set of variable-pointers into which variables are to be inserted. |
Implements Minotaur::NonlinearFunction.
|
virtual |
Check if the function is a sum of square terms.
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Multiply by a constant.
[in] | c | double value with which we want to multiply. |
Implements Minotaur::NonlinearFunction.
CNode * CGraph::newNode | ( | double | d | ) |
Create a new node with constant real value. It does not have any children.
[in] | d | The value. |
CNode * CGraph::newNode | ( | int | i | ) |
Create a new node with constant integer value. It does not have any children.
[in] | i | The value. |
Create a new node with more than two children, and add it to the graph. The children should already be a nodes of the graph.
[in] | op | OpCode of the new node |
[in] | child | An array of pointers to children. It should be size 'n'. |
[in] | n | The size of array 'child'. |
Create a new node with one or two children, and add it to the graph. The children should already be a nodes of the graph.
[in] | op | OpCode of the new node |
[in] | lchild | The left child of the new node. It should never be NULL. |
[in] | rchild | If the opcode needs two children, e.g. OpPlus, OpMult etc, then rchild should be the right child. For univariate functions like OpSqrt, it should be NULL. |
CNode * CGraph::newNode | ( | VariablePtr | v | ) |
Create a new node denoting an input variable. It does not have any children.
The function checks if the variable already exists in the graph. If so, it returns the pointer to that node. Otherwise it creates a new node.
[in] | v | The variable. |
|
virtual |
Prepare for evaluating sparse jacobian.
All the variables that are in this function can occur in one or more of linear, quadratic and nonlinear functions. All variables that occur in the whole function can be accessed by iterating between vbeg and vend. This function is used to find the offset for variables that occur in the nonlinear function.
Implements Minotaur::NonlinearFunction.
|
virtual |
Remove a variable v from the function after fixing it to value val.
Reimplemented from Minotaur::NonlinearFunction.
void CGraph::setOut | ( | CNode * | node | ) |
Set the node that should be the output of this graph. This node should already be a part of this graph (created by newNode() function).
[in] | node | The node that is the output. |
|
virtual |
Change the nonlinear function to its square-root.
[out] | err | must be nonzero if the operation is unsuccessful |
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Substitute a variable with another.
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Tighten variables based on function bounds.
Given a lower and upper bound on the allowed values of the function, deduce bounds of variables and return the modifications in bounds. The modifications are not applied to the variables.
param [in] lb A lower bound on function values
param [in] ub An upper bound on function values
param [out] mods A vector of modifications deduced by bound propagation/tightening
param [out] status Tells whether there was an error in executing this routine or if the problem is infeasible etc.
Reimplemented from Minotaur::NonlinearFunction.
|
virtual |
Display the nonlinear function.
Reimplemented from Minotaur::NonlinearFunction.