Minotaur 0.4.1
Docs for developers
Public Member Functions | Protected Attributes | Friends | List of all members
Minotaur::Function Class Reference

#include <Function.h>

Public Member Functions

 Function ()
 Default constructor.
 
 Function (LinearFunctionPtr lf)
 Construct a function using only a linear function.
 
 Function (LinearFunctionPtr lf, QuadraticFunctionPtr qf)
 
 Function (LinearFunctionPtr lf, NonlinearFunctionPtr nlf)
 Construct a function using a linear function and a nonlinear function.
 
 Function (LinearFunctionPtr lf, QuadraticFunctionPtr qf, NonlinearFunctionPtr nlf)
 
 Function (NonlinearFunctionPtr nlf)
 Construct a function using only a nonlinear function.
 
virtual ~Function ()
 Destroy.
 
virtual FunctionPtr cloneWithVars (VariableConstIterator vbeg, int *err) const
 
virtual FunctionPtr cloneWithVarsPermute (VariableConstIterator vbeg, UIntVector variableaddress, int *err) const
 similar to above function, but for shuffling variables
 
virtual double eval (const DoubleVector &x, int *error) const
 
virtual double eval (const double *x, int *error) const
 Evaluate the function at a given point x.
 
virtual void prepJac ()
 
virtual void evalGradient (const double *x, double *grad_f, int *error) const
 
virtual void fillJac (const double *x, double *values, int *error)
 
virtual UInt getNumNzInHess ()
 
virtual bool hasVar (VariablePtr var) const
 
virtual FunctionType getType ()
 
bool isLinearIn (ConstVariablePtr v)
 Check if function is linear in a variable. More...
 
virtual FunctionType getVarFunType (ConstVariablePtr v)
 
virtual LinearFunctionPtr getLinearFunction () const
 Return the linear part of the function.
 
virtual QuadraticFunctionPtr getQuadraticFunction () const
 Return the quadratic part of the function.
 
virtual NonlinearFunctionPtr getNonlinearFunction () const
 Return the nonlinear part of the function.
 
VarSetConstIterator varsBegin ()
 Return a begin-iterator for the variables that are in this function.
 
VarSetConstIterator varsEnd ()
 Return an end-iterator for the variables that are in this function.
 
virtual UInt getNumVars () const
 Return the number of variables that are in this function.
 
virtual void evalHessian (const double mult, const double *x, const size_t *offset, double *values, int *error)
 
virtual void evalHessian (double mult, const double *x, const LTHessStor *stor, double *values, int *error)
 
virtual void fillHessOffset (size_t *offset, size_t &pos, std::set< ConstVariablePair, CompareVariablePair > &v_pairs)
 Fill in the values of offset, starting from position pos.
 
virtual void fillHessStor (LTHessStor *stor)
 
virtual void finalHessStor (const LTHessStor *stor)
 
virtual void changeLf (LinearFunctionPtr lf)
 Change the linear function part.
 
virtual void changeNlf (NonlinearFunctionPtr nlf)
 Change the nonlinear function part.
 
virtual void subst (VariablePtr out, VariablePtr in, double rat)
 Substitute a variable with another.
 
virtual void operator*= (const double c)
 
QuadraticFunctionPtr removeQuadratic ()
 
LinearFunctionPtr removeLinear ()
 
NonlinearFunctionPtr removeNonlinear ()
 
void add (ConstLinearFunctionPtr lPtr)
 
void removeVar (VariablePtr v, double val)
 
double getFixVarOffset (VariablePtr v, double val)
 
virtual void write (std::ostream &out) const
 Express the function and send the output to the output stream "out".
 

Protected Attributes

FunctionType type_
 The type of the function.
 
VariableSet vars_
 The variables that occur in this function.
 

Friends

std::ostream & operator<< (std::ostream &out, const Function &f)
 Express the function and send the output to the output stream "out".
 

Detailed Description

The class Function is meant to model functions that are used to specify constraints and objectives in a problem. A function can have three or more components: linear, quadratic and nonlinear. Each of these types is implemented as a separate class. A Function thus keeps a pointer to each of these components and has methods to consolidate methods of these components. For instance, a function evaluation will just call these evaluation routines of the components and add them together. If any of the individual components of a function (linear, quadratic, nonlinear) are modified, one should delete the existing function and create a new one as some of the data-structures may not get updated with the changes.

Constructor & Destructor Documentation

◆ Function() [1/2]

Function::Function ( LinearFunctionPtr  lf,
QuadraticFunctionPtr  qf 
)

Construct a function using a linear function and a quadratic function.

◆ Function() [2/2]

Function::Function ( LinearFunctionPtr  lf,
QuadraticFunctionPtr  qf,
NonlinearFunctionPtr  nlf 
)

Construct a function using a linear function, a quadratic function and a nonlinear function.

Member Function Documentation

◆ add()

void Function::add ( ConstLinearFunctionPtr  lPtr)

Add a linear function. If the function already has a linear function, the new function is algebraically added, otherwise the new function is cloned.

◆ cloneWithVars()

FunctionPtr Function::cloneWithVars ( VariableConstIterator  vbeg,
int *  err 
) const
virtual

Make a clone using new variables. vbeg points to the variable id 0. vbeg+k points to variable id k, where k>=0.

◆ eval()

double Function::eval ( const DoubleVector &  x,
int *  error 
) const
virtual

Evaluate the function at a given point x. error must be zero if no errors were encountered.

◆ evalGradient()

void Function::evalGradient ( const double *  x,
double *  grad_f,
int *  error 
) const
virtual

Evaluate Gradient at the given point x and fill in the array grad_f.

◆ evalHessian()

void Function::evalHessian ( const double  mult,
const double *  x,
const size_t *  offset,
double *  values,
int *  error 
)
virtual

Evaluate the hessian at a given point 'x'. Multiply the evaluated values by the lagrangean multiplier 'mult' and add the given matrix to the existing values in 'values'

◆ getNumNzInHess()

UInt Function::getNumNzInHess ( )
virtual

Get number of terms in the hessian of the function. We only count terms that are nonzero in the lower-triangular half (including the diagonal) of the hessian matrix.

◆ getType()

FunctionType Function::getType ( )
virtual

Return the type of a function: linear, quadratic, nonlinear etc. If the return type is quadratic, we may still have a linear component.

◆ hasVar()

bool Function::hasVar ( VariablePtr  var) const
virtual

Return true if variable var is one of the arguments of this function. Return false otherwise.

◆ isLinearIn()

bool Function::isLinearIn ( ConstVariablePtr  v)

Check if function is linear in a variable.

Parameters
[in]vThe variable that we want to test.
Returns
True if this function is linear or constant in variable v.

◆ operator*=()

void Function::operator*= ( const double  c)
virtual

Multiply with a constant. If c is zero, then function becomes empty. We make the components NULL in such a case

◆ removeLinear()

LinearFunctionPtr Function::removeLinear ( )

Remove the linear part of the function and return a pointer to the linear part.

◆ removeNonlinear()

NonlinearFunctionPtr Function::removeNonlinear ( )

Remove the nonlinear part of the function and return a pointer to the nonlinear part.

◆ removeQuadratic()

QuadraticFunctionPtr Function::removeQuadratic ( )

Remove the quadratic part of the function and return a pointer to the quadratic part.


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