Minotaur 0.4.1
Docs for developers
Public Member Functions | Protected Attributes | List of all members
Minotaur::NonlinearFunction Class Referenceabstract

Base class for nonlinear functions. More...

#include <NonlinearFunction.h>

Inheritance diagram for Minotaur::NonlinearFunction:
Inheritance graph
[legend]

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.
 

Detailed Description

Base class for nonlinear functions.

Member Function Documentation

◆ addConst()

void NonlinearFunction::addConst ( const double  d,
int &  err 
)
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))

Parameters
[in]dThe value of the constant.
[out]errmust be nonzero if the constant could not be added.

Reimplemented in Minotaur::CGraph.

◆ cloneWithVars()

virtual NonlinearFunctionPtr Minotaur::NonlinearFunction::cloneWithVars ( VariableConstIterator  vbeg,
int *  err 
) const
pure virtual

Make a clone using new variables.

Parameters
[in]vbegit points to the variable id 0. vbeg+k points to variable id k, where k>=0.
[out]errmust be nonzero if function wasn't cloned.

Implemented in MINOTAUR_AMPL::AMPLNonlinearFunction, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and Minotaur::CGraph.

◆ computeBounds()

void NonlinearFunction::computeBounds ( double *  lb,
double *  ub,
int *  error 
)
virtual

Calculate upper and lower bounds on the function using bounds of the variables.

Parameters
[out]lbPointer that will contain the value of lower bound.
[out]ubPointer that will contain the value of upper bound.
[out]error0 if no error is encountered, nonzero otherwise.

Reimplemented in Minotaur::CGraph.

◆ eval()

virtual double Minotaur::NonlinearFunction::eval ( const double *  x,
int *  error 
)
pure virtual

Evaluate the function at a given point x.

Parameters
[in]xThe size of the array x must exceed the highest index of the variables used in the function.
[out]*errorIt should be set a positive value if there is error encountered while evaluating. Leave undisturbed otherwise.
Returns
The value of function of x.

Implemented in Minotaur::CGraph, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.

◆ evalGradient()

virtual void Minotaur::NonlinearFunction::evalGradient ( const double *  x,
double *  grad_f,
int *  error 
)
pure virtual

Evaluate and add gradient at a given point.

Parameters
[in]xThe size of the array x must exceed the highest index of the variables used in the function.
[out]grad_fThe values of grad_f are incremented with the gradient of this function at x. The array grad_f is dense.
[out]errorIt 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.

◆ evalHessian()

virtual void Minotaur::NonlinearFunction::evalHessian ( const double  mult,
const double *  x,
const LTHessStor stor,
double *  values,
int *  error 
)
pure virtual

Evaluate and add hessian at a given point.

Parameters
[in]multMultiplier for this objective/constraint function
[in]xThe point where we need the hessian.
[in]storThe Hessian storage information.
[out]valuesThe Hessian values to which we add Hessian of this function.
[out]errorWe 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.

◆ fillHessStor()

virtual void Minotaur::NonlinearFunction::fillHessStor ( LTHessStor stor)
pure virtual

Fill sparsity of hessian into hessian storage.

Parameters
[in,out]storWe add variables into stor->cols

Implemented in Minotaur::MonomialFunction, Minotaur::CGraph, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.

◆ fillJac()

virtual void Minotaur::NonlinearFunction::fillJac ( const double *  x,
double *  values,
int *  error 
)
pure virtual

Evaluate and add gradient at a given point to the jacobian.

Parameters
[in]xThe size of the array x must exceed the highest index of the variables used in the function.
[out]valuesThe 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]errorIt 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.

◆ finalHessStor()

virtual void Minotaur::NonlinearFunction::finalHessStor ( const LTHessStor stor)
pure virtual

Finalize hessian preparation.

Parameters
[in]storcontains 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.

◆ getFixVarOffset()

virtual double Minotaur::NonlinearFunction::getFixVarOffset ( VariablePtr  ,
double   
)
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.

Returns
Return the value of the offset.

Reimplemented in Minotaur::CGraph.

◆ getNlString()

std::string NonlinearFunction::getNlString ( int *  err)
virtual

Return a string in AMPL's .nl format (postfix notation) of this nonlinear function.

param [out] err 0 if no errors were encountered.

Returns
Return the string.

Reimplemented in Minotaur::CGraph.

◆ getPersp()

NonlinearFunctionPtr NonlinearFunction::getPersp ( VariablePtr  z,
double  eps,
int *  err 
) const
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)

Parameters
[in]zThe variable for which you take the perspective
[in]epsThe 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]errmust be nonzero if function wasn't cloned.
Returns
A new nonlinear function with an additional variable that gives the perspective of this function

Reimplemented in Minotaur::CGraph.

◆ getType()

FunctionType NonlinearFunction::getType ( ) const
virtual

Return the type of function: polynomial, ...

Reimplemented in Minotaur::CGraph, and Minotaur::PolynomialFunction.

◆ getVars()

virtual void Minotaur::NonlinearFunction::getVars ( VariableSet *  vars)
pure virtual

Get variables used in this function.

Parameters
[in]varsA set of variable-pointers into which variables are to be inserted.

Implemented in MINOTAUR_AMPL::AMPLNonlinearFunction, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and Minotaur::CGraph.

◆ hasVar()

bool NonlinearFunction::hasVar ( ConstVariablePtr  v) const
virtual

Check if function contains a variable.

Parameters
[in]vThe variable that we want to test.
Returns
True if this function is has v. False if it doesn't use it.

◆ isSumOfSquares()

virtual bool Minotaur::NonlinearFunction::isSumOfSquares ( ) const
inlinevirtual

Check if the function is a sum of square terms.

Returns
True if this function is a sum of squares, False otherwise

Reimplemented in Minotaur::CGraph.

◆ multiply()

virtual void Minotaur::NonlinearFunction::multiply ( double  c)
pure virtual

Multiply by a constant.

Parameters
[in]cdouble value with which we want to multiply.

Implemented in Minotaur::CGraph, Minotaur::MonomialFunction, Minotaur::PolynomialFunction, and MINOTAUR_AMPL::AMPLNonlinearFunction.

◆ prepJac()

virtual void Minotaur::NonlinearFunction::prepJac ( VarSetConstIter  vbeg,
VarSetConstIter  vend 
)
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.

◆ removeVar()

virtual void Minotaur::NonlinearFunction::removeVar ( VariablePtr  ,
double   
)
inlinevirtual

Remove a variable v from the function after fixing it to value val.

Reimplemented in Minotaur::CGraph.

◆ sqrRoot()

void NonlinearFunction::sqrRoot ( int &  err)
virtual

Change the nonlinear function to its square-root.

Parameters
[out]errmust be nonzero if the operation is unsuccessful

Reimplemented in Minotaur::CGraph.

◆ subst()

virtual void Minotaur::NonlinearFunction::subst ( VariablePtr  ,
VariablePtr  ,
double   
)
inlinevirtual

Substitute a variable with another.

Reimplemented in Minotaur::CGraph.

◆ varBoundMods()

virtual void Minotaur::NonlinearFunction::varBoundMods ( double  ,
double  ,
VarBoundModVector &  ,
SolveStatus  
)
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.

◆ varsBegin()

virtual VariableSet::iterator Minotaur::NonlinearFunction::varsBegin ( )
inlinevirtual

First iterator for variables.

Returns
first iterator for the variables in this function.

◆ varsEnd()

virtual VariableSet::iterator Minotaur::NonlinearFunction::varsEnd ( )
inlinevirtual

Last iterator for variables.

Returns
last iterator for the variables in this function.

◆ write()

void NonlinearFunction::write ( std::ostream &  out) const
virtual

The documentation for this class was generated from the following files:

Minotaur source code documented by Doxygen 1.9.4 on Thu Apr 24 2025