Minotaur 0.4.1
Docs for developers
Public Member Functions | List of all members
MINOTAUR_AMPL::AMPLNonlinearFunction Class Reference

Declare the AMPLNonlinearFunction class for setting up evaluation and derivatives of nonlinear Functions. More...

#include <AMPLNonlinearFunction.h>

Inheritance diagram for MINOTAUR_AMPL::AMPLNonlinearFunction:
Inheritance graph
[legend]
Collaboration diagram for MINOTAUR_AMPL::AMPLNonlinearFunction:
Collaboration graph
[legend]

Public Member Functions

 AMPLNonlinearFunction ()
 Default constructor.
 
 AMPLNonlinearFunction (Minotaur::UInt i, Minotaur::UInt nvars, ASL *my_asl, bool is_in_obj)
 Create a nonlinear function for a given constraint. More...
 
Minotaur::NonlinearFunctionPtr cloneWithVars (Minotaur::VariableConstIterator vbeg, int *err) const
 Make a clone using new variables. More...
 
double eval (const double *x, int *error)
 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 (const double mult, const double *x, const Minotaur::LTHessStor *stor, double *values, int *error)
 Evaluate and add hessian at a given point. More...
 
void fillHessStor (Minotaur::LTHessStor *)
 Fill sparsity of hessian into hessian storage. More...
 
void finalHessStor (const Minotaur::LTHessStor *)
 Finalize hessian preparation. More...
 
void fillJac (const double *, double *, int *)
 Evaluate and add gradient at a given point to the jacobian. More...
 
void getVars (Minotaur::VariableSet *)
 Get variables used in this function. More...
 
void multiply (double c)
 Multiply by a constant. More...
 
void prepJac (Minotaur::VarSetConstIter, Minotaur::VarSetConstIter)
 Prepare for evaluating sparse jacobian. More...
 
void setVars (Minotaur::VarSetConstIterator vb, Minotaur::VarSetConstIterator ve)
 Tell what variables are in this function. More...
 
void write (std::ostream &out) const
 Display the nonlinear function. More...
 
- Public Member Functions inherited from Minotaur::NonlinearFunction
 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

- Protected Attributes inherited from Minotaur::NonlinearFunction
VariableSet vars_
 A set of variables used in this function.
 

Detailed Description

Declare the AMPLNonlinearFunction class for setting up evaluation and derivatives of nonlinear Functions.

This class does not contain the computational graph of the function. Use it only for evaluating function values and derivatives.

Constructor & Destructor Documentation

◆ AMPLNonlinearFunction()

AMPLNonlinearFunction::AMPLNonlinearFunction ( Minotaur::UInt  i,
Minotaur::UInt  nvars,
ASL *  my_asl,
bool  is_in_obj 
)

Create a nonlinear function for a given constraint.

Parameters
[in]iThe constraint number of which we need the nonlinear function. This value is ignored if is_obj is True.
[in]nvarsTotal number of variables in the problem.
[in]my_aslPointer to ASL for calling its routines.
[in]is_objIf True, then get function from objective. Otherwise, get function of i-th constriant.

Member Function Documentation

◆ cloneWithVars()

Minotaur::NonlinearFunctionPtr AMPLNonlinearFunction::cloneWithVars ( Minotaur::VariableConstIterator  vbeg,
int *  err 
) const
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.

Implements Minotaur::NonlinearFunction.

◆ eval()

double AMPLNonlinearFunction::eval ( const double *  x,
int *  error 
)
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.

Implements Minotaur::NonlinearFunction.

◆ evalGradient()

void AMPLNonlinearFunction::evalGradient ( const double *  x,
double *  grad_f,
int *  error 
)
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.

Implements Minotaur::NonlinearFunction.

◆ evalHessian()

void AMPLNonlinearFunction::evalHessian ( const double  mult,
const double *  x,
const Minotaur::LTHessStor stor,
double *  values,
int *  error 
)
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.

Implements Minotaur::NonlinearFunction.

◆ fillHessStor()

void AMPLNonlinearFunction::fillHessStor ( Minotaur::LTHessStor stor)
virtual

Fill sparsity of hessian into hessian storage.

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

Implements Minotaur::NonlinearFunction.

◆ fillJac()

void AMPLNonlinearFunction::fillJac ( const double *  x,
double *  values,
int *  error 
)
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.

Implements Minotaur::NonlinearFunction.

◆ finalHessStor()

void AMPLNonlinearFunction::finalHessStor ( const Minotaur::LTHessStor stor)
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.

Implements Minotaur::NonlinearFunction.

◆ getVars()

void AMPLNonlinearFunction::getVars ( Minotaur::VariableSet *  vars)
virtual

Get variables used in this function.

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

Implements Minotaur::NonlinearFunction.

◆ multiply()

void AMPLNonlinearFunction::multiply ( double  c)
virtual

Multiply by a constant.

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

Implements Minotaur::NonlinearFunction.

◆ prepJac()

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

◆ setVars()

void AMPLNonlinearFunction::setVars ( Minotaur::VarSetConstIterator  vb,
Minotaur::VarSetConstIterator  ve 
)

Tell what variables are in this function.

These variabvles are then stored in this class for future use by Minotaur routines.

Parameters
[in]vbIterator pointing to first element of set.
[in]veIterator pointing to end of set.

◆ write()

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

Display the nonlinear function.

Reimplemented from Minotaur::NonlinearFunction.


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

Minotaur source code documented by Doxygen 1.9.4 on Fri Apr 25 2025