Minotaur 0.4.1
Docs for developers
|
Base class for nonlinear functions. More...
#include <NonlinearFunction.h>
Public Member Functions | |
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... | |
Protected Attributes | |
VariableSet | vars_ |
A set of variables used in this function. | |
Base class for nonlinear functions.
|
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 in Minotaur::CGraph.
|
pure 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. |
Implemented in MINOTAUR_AMPL::AMPLNonlinearFunction, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and Minotaur::CGraph.
|
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 in Minotaur::CGraph.
|
pure 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. |
Implemented in Minotaur::CGraph, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.
|
pure 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. |
Implemented in Minotaur::CGraph, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.
|
pure 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. |
Implemented in Minotaur::PolynomialFunction, MINOTAUR_AMPL::AMPLNonlinearFunction, Minotaur::MonomialFunction, and Minotaur::CGraph.
|
pure virtual |
Fill sparsity of hessian into hessian storage.
[in,out] | stor | We add variables into stor->cols |
Implemented in Minotaur::MonomialFunction, Minotaur::CGraph, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.
|
pure 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. |
Implemented in Minotaur::MonomialFunction, MINOTAUR_AMPL::AMPLNonlinearFunction, Minotaur::CGraph, and Minotaur::PolynomialFunction.
|
pure 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. |
Implemented in Minotaur::MonomialFunction, Minotaur::CGraph, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.
|
inlinevirtual |
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 in Minotaur::CGraph.
|
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 in Minotaur::CGraph.
|
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 in Minotaur::CGraph.
|
virtual |
Return the type of function: polynomial, ...
Reimplemented in Minotaur::CGraph, and Minotaur::PolynomialFunction.
|
pure virtual |
Get variables used in this function.
[in] | vars | A set of variable-pointers into which variables are to be inserted. |
Implemented in MINOTAUR_AMPL::AMPLNonlinearFunction, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and Minotaur::CGraph.
|
virtual |
Check if function contains a variable.
[in] | v | The variable that we want to test. |
|
inlinevirtual |
Check if the function is a sum of square terms.
Reimplemented in Minotaur::CGraph.
|
pure virtual |
Multiply by a constant.
[in] | c | double value with which we want to multiply. |
Implemented in Minotaur::CGraph, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.
|
pure 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.
Implemented in MINOTAUR_AMPL::AMPLNonlinearFunction, Minotaur::PolynomialFunction, Minotaur::CGraph, and Minotaur::MonomialFunction.
|
inlinevirtual |
Remove a variable v from the function after fixing it to value val.
Reimplemented in Minotaur::CGraph.
|
virtual |
Change the nonlinear function to its square-root.
[out] | err | must be nonzero if the operation is unsuccessful |
Reimplemented in Minotaur::CGraph.
|
inlinevirtual |
Substitute a variable with another.
Reimplemented in Minotaur::CGraph.
|
inlinevirtual |
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 in Minotaur::CGraph.
|
inlinevirtual |
First iterator for variables.
|
inlinevirtual |
Last iterator for variables.
|
virtual |
Display the nonlinear function.
Reimplemented in Minotaur::CGraph, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.