Institut de Robòtica i Informàtica Industrial
KRD Group

The CuikSuite Project

monomial.h File Reference

Definition of the Tmonomial type and the associated functions. More...

#include "boolean.h"
#include "interval.h"
#include "variables.h"
#include "variable_set.h"
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  Tmonomial
 A scaled product of powers of variables. More...

Functions

void InitMonomial (Tmonomial *f)
 Constructor.
void ResetMonomial (Tmonomial *f)
 Reset the monomial information.
void FixVariableInMonomial (unsigned int nv, double v, Tmonomial *f)
 Replaces a variable by a constant.
void ReplaceVariableInMonomial (unsigned int nv, double ct, unsigned int nvNew, Tmonomial *f)
 Replaces a variable.
boolean EmptyMonomial (Tmonomial *f)
 Checks if a monomial is empty.
boolean CtMonomial (Tmonomial *f)
 Checks if a monomial is constant.
boolean QuadraticMonomial (Tmonomial *f)
 Checks if a monomial is quadratic: K*x^2, with K a constant.
boolean BilinearMonomial (Tmonomial *f)
 Checks if a monomial is bilienal: K*x*y, with K a constant.
boolean LinearMonomial (Tmonomial *f)
 Checks if a monomial is lienal: K*x, with K a constant.
unsigned int MonomialOrder (Tmonomial *f)
 Gets the order of a monomial.
void CopyMonomial (Tmonomial *f_dst, Tmonomial *f_orig)
 Copy constructor.
unsigned int CmpMonomial (Tmonomial *f1, Tmonomial *f2)
 Monomial comparison.
void SetMonomialCt (double k, Tmonomial *f)
 Changes the scale factor of a monomial.
double GetMonomialCt (Tmonomial *f)
 Gets the scale factor of a monomial.
Tvariable_setGetMonomialVariables (Tmonomial *f)
 Gets the variables of a monomial.
void AddCt2Monomial (double k, Tmonomial *f)
 Scales a monomial.
void AddVariable2Monomial (unsigned int varid, unsigned int p, Tmonomial *f)
 Adds a power variable to the monomial.
double EvaluateMonomial (double *varValues, Tmonomial *f)
 Evaluates a monomial for a given set of value for the variables.
void EvaluateMonomialInt (Tinterval *varValues, Tinterval *i_out, Tmonomial *f)
 Evaluates a monomial for a given set of ranges for the variables.
void DeriveMonomial (unsigned int nv, Tmonomial *df, Tmonomial *f)
 Derives an monomial.
void PrintMonomial (FILE *file, boolean first, char **varNames, Tmonomial *f)
 Prints a monomial.
void DeleteMonomial (Tmonomial *f)
 Destructor.

Detailed Description

Definition of the Tmonomial type and the associated functions.

See also:
Tmonomial, monomial.c.

Definition in file monomial.h.


Function Documentation

void ResetMonomial ( Tmonomial f  ) 

Removes the information stored in the monomial, but does not frees the memory. It is more efficient to use ResetMonomial instead of DeleteMonomial plus InitMonomial again.

Parameters:
f The monomial to be initialized.

Definition at line 24 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, ResetVarSet(), TRUE, and Tmonomial::vars.

Referenced by AddTerm2SearchCriterion(), ApplyLinkRot(), FixVariableInMonomial(), GenerateCrossProductEquations(), GenerateDotProductEquation(), GenerateEquationsFromBranch(), GenerateGeneralNormEquation(), GenerateJointEquations(), GenerateJointEquationsInBranch(), GenerateJointRangeEquations(), GenerateScaledParabolaEquation(), GenerateScaledSaddleEquation(), ReplaceVariableInMonomial(), and SetMonomialCt().

Here is the call graph for this function:

Here is the caller graph for this function:

void FixVariableInMonomial ( unsigned int  nv,
double  v,
Tmonomial f 
)

Removes a variable from a monomial converting it into a constant. Note, that variables are indexed and that removing a variable shifts down the index of variables with index above the removed variable.

Parameters:
nv Numerical identifier of the variable to remove.
v Value for the variable to remove.
f The monomial to be updated.

Definition at line 31 of file monomial.c.

References Tmonomial::ct, GetPlaceinSet(), GetVariablePowerN(), NO_UINT, RemoveVariableFromSet(), ResetMonomial(), ShiftVarIndexes(), Tmonomial::vars, and ZERO.

Referenced by ReplaceVariableInEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

void ReplaceVariableInMonomial ( unsigned int  nv,
double  ct,
unsigned int  nvNew,
Tmonomial f 
)

Replaces a variable from a monomial converting it into a another variable via a linear relation

VarToBeReplaced = a * NewVar + b


Note, that variables are indexed and that removing a variable shifts down the index of variables with index above the removed variable.

Parameters:
nv Numerical identifier of the variable to remove.
ct Scale factor for the new variable.
nvNew Numerical identifier of the new variable.
f The monomial to be updated.

Definition at line 50 of file monomial.c.

References AddVariable2Set(), Tmonomial::ct, GetPlaceinSet(), GetVariablePowerN(), NO_UINT, RemoveVariableFromSet(), ResetMonomial(), ShiftVarIndexes(), Tmonomial::vars, and ZERO.

Here is the call graph for this function:

boolean EmptyMonomial ( Tmonomial f  ) 

Checks if a monomial is empty.

Parameters:
f The monomial to be checked.
Returns:
TRUE if the input monomia is empty.

Definition at line 71 of file monomial.c.

References Tmonomial::empty.

Referenced by AddMonomial().

Here is the caller graph for this function:

boolean CtMonomial ( Tmonomial f  ) 

Checks if a monomial is constant.

Parameters:
f The monomial to be checked.
Returns:
TRUE if the input monomial is constant.

Definition at line 76 of file monomial.c.

References Tmonomial::empty, VariableSetSize(), and Tmonomial::vars.

Referenced by AddMonomial(), BilinearEquation(), and LinearEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

boolean QuadraticMonomial ( Tmonomial f  ) 

Checks if a monomial is quadratic: K*x^2, with K a constant.

Parameters:
f The monomial to be checked.
Returns:
TRUE if the input monomial is quadratic.

Definition at line 82 of file monomial.c.

References GetVariablePowerN(), VariableSetSize(), and Tmonomial::vars.

Referenced by BilinearEquation(), CircleEquation(), ParabolaEquation(), and SphereEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

boolean BilinearMonomial ( Tmonomial f  ) 

Checks if a monomial is bilineal: K*x*y, with K a constant.

Parameters:
f The monomial to be checked.
Returns:
TRUE if the input monomial is bilienal.

Definition at line 88 of file monomial.c.

References GetVariablePowerN(), VariableSetSize(), and Tmonomial::vars.

Referenced by BilinearEquation(), and SaddleEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

boolean LinearMonomial ( Tmonomial f  ) 

Checks if a monomial is bilineal: K*y, with K a constant.

Parameters:
f The monomial to be checked.
Returns:
TRUE if the input monomial is lineal.

Definition at line 95 of file monomial.c.

References GetVariablePowerN(), VariableSetSize(), and Tmonomial::vars.

Referenced by BilinearEquation(), LinearEquation(), ParabolaEquation(), and SaddleEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int MonomialOrder ( Tmonomial f  ) 

Gets the order of a monomial. Here the order is the sum of the powers of the variables in the monomial (0 for constant, 1 for lineal, 2 for quadratic and bilineal).

Parameters:
f The monomial to be checked.
Returns:
The monomial order as defined above.

Definition at line 101 of file monomial.c.

References Tmonomial::vars, and VarSetOrder().

Referenced by AddMonomial(), and RewriteEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

void CopyMonomial ( Tmonomial f_dst,
Tmonomial f_orig 
)

Copies a constructor copying the data from another monomial.

Parameters:
f_dst The monomial to be created.
f_orig The monomial from where to copy.

Definition at line 106 of file monomial.c.

References CopyVarSet(), Tmonomial::ct, Tmonomial::empty, and Tmonomial::vars.

Referenced by AccumulateEquations(), AddMonomial(), and ReplaceVariableInEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int CmpMonomial ( Tmonomial f1,
Tmonomial f2 
)

Compare two given monomials. Monomials are compared first taking into account the variables and then their scale factor.

Parameters:
f1 The first monomial to compare.
f2 The second monomial to compare.
Returns:
1 if f1 is larger than f2, 0 if they are equal and 2 if f2 is larger than f1.
See also:
CmpVarSet

Definition at line 113 of file monomial.c.

References CmpVarSet(), Tmonomial::ct, Tmonomial::empty, and Tmonomial::vars.

Referenced by AddMonomial(), and CmpEquations().

Here is the call graph for this function:

Here is the caller graph for this function:

void SetMonomialCt ( double  k,
Tmonomial f 
)

Changes the scale factor of a monomial.

Parameters:
k the new monomial scale factor.
f The monomial to update.

Definition at line 154 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, FALSE, ResetMonomial(), and ZERO.

Referenced by AddMonomial(), and NormalizeEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

double GetMonomialCt ( Tmonomial f  ) 

Gets the scale factor of a monomial.

Parameters:
f The monomial to update.
Returns:
The scale factor of the monomial.

Definition at line 146 of file monomial.c.

References Tmonomial::ct, and Tmonomial::empty.

Referenced by AddMonomial(), CircleEquation(), CropEquation(), DummifyAndAddEquation(), GaussianElimination(), IsSimplificable(), LinearEquation2LinearConstraint(), NormalizeEquation(), ParabolaEquation(), PurgeEquation(), RewriteEquation(), SaddleEquation(), SetEquationInfo(), and SphereEquation().

Here is the caller graph for this function:

Tvariable_set* GetMonomialVariables ( Tmonomial f  ) 

Gets the variables of a monomial.

Parameters:
f The monomial to update.
Returns:
A pointer to the set of variables in the monomial.

Definition at line 163 of file monomial.c.

References Tmonomial::vars.

Referenced by AddMonomial(), CropEquation(), DummifyAndAddEquation(), FindMonomial(), IsSimplificable(), LinearEquation2LinearConstraint(), LinearizeParabolaEquation(), LinearizeSaddleEquation(), ReplaceVariableInEquation(), RewriteEquation(), SetEquationInfo(), and VarScaleEquation().

Here is the caller graph for this function:

void AddVariable2Monomial ( unsigned int  varid,
unsigned int  p,
Tmonomial f 
)

Adds a power variable to the monomial.

Parameters:
varid The identifier of the variable to be added to the monomial.
p The power for the variable.
f The monomial to update.

Definition at line 181 of file monomial.c.

References AddVariable2Set(), Tmonomial::ct, Tmonomial::empty, FALSE, and Tmonomial::vars.

Referenced by AddTerm2SearchCriterion(), ApplyLinkRot(), DummifyAndAddEquation(), EquationFromLinearConstraint(), EquationFromLinearConstraintProduct(), GenerateCrossProductEquations(), GenerateDotProductEquation(), GenerateEquationsFromBranch(), GenerateGeneralNormEquation(), GenerateJointEquations(), GenerateJointEquationsInBranch(), GenerateJointRangeEquations(), GenerateScaledParabolaEquation(), GenerateScaledSaddleEquation(), ReplaceVariableInEquation(), and VarScaleEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

double EvaluateMonomial ( double *  varValues,
Tmonomial f 
)

Evaluates a monomial for a given set of value for the variables.

Parameters:
varValues An array of doubles with the values for the variables in the problem.
f The monomial to evaluate.
Returns:
The value of the monomial.

Definition at line 193 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, EvaluateVarSet(), VariableSetSize(), and Tmonomial::vars.

Referenced by EvaluateEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

void EvaluateMonomialInt ( Tinterval varValues,
Tinterval i_out,
Tmonomial f 
)

Evaluates a monomial for a given set of ranges for the variables using interval arithmetics.

Parameters:
varValues An array with the ranges for the variables in the problem.
i_out The output interval.
f The monomial to evaluate.

Definition at line 206 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, EvaluateVarSetInt(), IntervalProduct(), NewInterval(), VariableSetSize(), Tmonomial::vars, and ZERO.

Referenced by EvaluateEquationInt().

Here is the call graph for this function:

Here is the caller graph for this function:

void DeriveMonomial ( unsigned int  nv,
Tmonomial df,
Tmonomial f 
)

Derives a monomial with respect to a given variable.

Parameters:
nv Identifier of the variable with respect to the one we have to derive.
df Output monomial with the derived monomial.
f The monomial to derive.

Definition at line 234 of file monomial.c.

References Tmonomial::ct, DeriveVarSet(), Tmonomial::empty, FALSE, InitMonomial(), VarIncluded(), and Tmonomial::vars.

Referenced by DeriveEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

void PrintMonomial ( FILE *  file,
boolean  first,
char **  varNames,
Tmonomial f 
)

Writes a monomial to a given stream.

Parameters:
file The stream where to print the monomial.
first TRUE if the monomial is the first one in an equation. This is used to avoid a '+' sign at the beginning of the equation.
varNames The name of the variables. If this parameter is NULL the printed names for the variables are v_X with X the index of the variable.
f The monomial to print.

Definition at line 248 of file monomial.c.

References Tmonomial::ct, Tmonomial::empty, EmptyVarSet(), PrintVarSet(), Tmonomial::vars, and ZERO.

Referenced by PrintEquation(), and PrintMonomials().

Here is the call graph for this function:

Here is the caller graph for this function: