Minotaur 0.4.1
Docs for developers
|
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) |
The base class linear function is of the form c'x.
LinearFunction::LinearFunction | ( | const double | tol | ) |
Constructor with a tolerance level below which a coefficient is considered to be zero.
LinearFunction::LinearFunction | ( | double * | a, |
VariableConstIterator | vbeg, | ||
VariableConstIterator | vend, | ||
double | tol | ||
) |
Construct a linear function from a coefficient array of size n and n variables.
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.
void LinearFunction::clearAll | ( | ) |
Removes all terms from the function
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.
void LinearFunction::computeBounds | ( | double * | l, |
double * | u | ||
) |
Get bounds based on lower and upperbounds of each variable.
[out] | l | This pointer should contain lower bound. |
[out] | u | This pointer should contain upper bound. |
LinearFunctionPtr LinearFunction::copyAdd | ( | ConstLinearFunctionPtr | l1 | ) |
Create a new LinearFunction by copying this function and adding another one.
LinearFunctionPtr LinearFunction::copyMinus | ( | ConstLinearFunctionPtr | l1 | ) |
Create a new LinearFunction by copying this function and subtracting another one from it.
LinearFunctionPtr LinearFunction::copyMult | ( | const double | c | ) |
Create a new LinearFunction by copying this function and multiplying by a constant.
QuadraticFunctionPtr LinearFunction::copyMult | ( | ConstLinearFunctionPtr | l1 | ) |
Create a new QuadraticFunction by multiplying this function and another LinearFunction.
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'.
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'.
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.
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.
bool LinearFunction::hasVar | ( | ConstVariablePtr | v | ) | const |
Check if function contains a variable.
[in] | v | The variable that we want to test. |
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.
void LinearFunction::minus | ( | LinearFunctionPtr | lf | ) |
Document me.