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

The base class linear function is of the form c'x. More...

#include <LinearFunction.h>

Public Member Functions

 LinearFunction ()
 Default constructor.
 
 LinearFunction (const double tol)
 
 LinearFunction (double *a, VariableConstIterator vbeg, VariableConstIterator vend, double tol)
 
 ~LinearFunction ()
 Destroy.
 
void add (LinearFunctionPtr lf)
 
void add (ConstLinearFunctionPtr lf)
 
void addTerm (ConstVariablePtr var, const double a)
 
void clearAll ()
 
LinearFunctionPtr clone () const
 
LinearFunctionPtr cloneWithVars (VariableConstIterator vbeg) const
 
LinearFunctionPtr cloneWithVarsPermute (VariableConstIterator vbeg, UIntVector variableaddress) const
 
void computeBounds (double *l, double *u)
 Get bounds based on lower and upperbounds of each variable. More...
 
double eval (const std::vector< double > &x) const
 
double eval (const double *x) const
 
void evalGradient (double *grad_f) const
 
void fillJac (double *values, int *error)
 
double getFixVarOffset (VariablePtr v, double val)
 
size_t getNumTerms () const
 Get the number of terms in this function.
 
void getVars (VariableSet *vars)
 
double getWeight (ConstVariablePtr var) const
 
bool hasVar (ConstVariablePtr v) const
 Check if function contains a variable. More...
 
void incTerm (ConstVariablePtr var, const double a)
 
void minus (LinearFunctionPtr lf)
 
void multiply (double d)
 Multiply the linear function by a number.
 
void prepJac (UInt s, VarSetConstIter vbeg, VarSetConstIter vend)
 
void removeVar (VariablePtr v, double val)
 Remove a variable v from the function.
 
QuadraticFunctionPtr square ()
 Square the function.
 
VariableGroupConstIterator termsBegin () const
 Iterate over the terms in the linear function: begin.
 
VariableGroupConstIterator termsEnd () const
 Iterate over the terms in the linear function: end.
 
void write (std::ostream &out) const
 Writes the function to a stream.
 
LinearFunctionPtr copyAdd (ConstLinearFunctionPtr l1)
 
LinearFunctionPtr copyMinus (ConstLinearFunctionPtr l1)
 
LinearFunctionPtr copyMult (const double c)
 
QuadraticFunctionPtr copyMult (ConstLinearFunctionPtr l1)
 

Detailed Description

The base class linear function is of the form c'x.

Constructor & Destructor Documentation

◆ LinearFunction() [1/2]

LinearFunction::LinearFunction ( const double  tol)

Constructor with a tolerance level below which a coefficient is considered to be zero.

◆ LinearFunction() [2/2]

LinearFunction::LinearFunction ( double *  a,
VariableConstIterator  vbeg,
VariableConstIterator  vend,
double  tol 
)

Construct a linear function from a coefficient array of size n and n variables.

Member Function Documentation

◆ addTerm()

void LinearFunction::addTerm ( ConstVariablePtr  var,
const double  a 
)

Add new a linear term to this linear function, with coefficient a. Use this method only when you are sure that the linear function does not already contain this variable. Otherwise use incTerm(). If the weight "a" is zero, then nothing is added.

◆ clearAll()

void LinearFunction::clearAll ( )

Removes all terms from the function

◆ clone()

LinearFunctionPtr LinearFunction::clone ( ) const

Copy the linear function. Variables and weights are copied. The weights in the clone and the original do not share the same space in memory.

◆ computeBounds()

void LinearFunction::computeBounds ( double *  l,
double *  u 
)

Get bounds based on lower and upperbounds of each variable.

Parameters
[out]lThis pointer should contain lower bound.
[out]uThis pointer should contain upper bound.

◆ copyAdd()

LinearFunctionPtr LinearFunction::copyAdd ( ConstLinearFunctionPtr  l1)

Create a new LinearFunction by copying this function and adding another one.

◆ copyMinus()

LinearFunctionPtr LinearFunction::copyMinus ( ConstLinearFunctionPtr  l1)

Create a new LinearFunction by copying this function and subtracting another one from it.

◆ copyMult() [1/2]

LinearFunctionPtr LinearFunction::copyMult ( const double  c)

Create a new LinearFunction by copying this function and multiplying by a constant.

◆ copyMult() [2/2]

QuadraticFunctionPtr LinearFunction::copyMult ( ConstLinearFunctionPtr  l1)

Create a new QuadraticFunction by multiplying this function and another LinearFunction.

◆ eval() [1/2]

double LinearFunction::eval ( const double *  x) const

Evaluate the value of this linear function at a given vector of doubles. It is assumed that the x[i] has the value for variable with id 'i'.

◆ eval() [2/2]

double LinearFunction::eval ( const std::vector< double > &  x) const

Evaluate the value of this linear function at a given vector of doubles. It is assumed that the x[i] has the value for variable with id 'i'.

◆ evalGradient()

void LinearFunction::evalGradient ( double *  grad_f) const

Evaluate the gradient of this linear function. It is assumed that x[id] will have the gradient along the direction of variable with ID=id.

◆ getWeight()

double LinearFunction::getWeight ( ConstVariablePtr  var) const

Get the weight of a variable in this function. If the variable is not found, it returns zero. Conversely, if the weight returned is zero, then variable is not stored in the data structures of this function.

◆ hasVar()

bool LinearFunction::hasVar ( ConstVariablePtr  v) const

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.

◆ incTerm()

void LinearFunction::incTerm ( ConstVariablePtr  var,
const double  a 
)

Add new a linear term to this linear function, with coefficient a. If the function already contains this variable, then the value is incremented. If the new value becomes zero, the variable is dropped.

◆ minus()

void LinearFunction::minus ( LinearFunctionPtr  lf)

Document me.


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