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

The CuikSuite Project

variable_set.h File Reference

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

#include "boolean.h"
#include "interval.h"
#include <stdlib.h>
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  Tvariable_set
 A set of variable indexes with powers. More...

Defines

#define INIT_NUM_VARIABLES   10
 Initial room for variables.

Functions

void InitVarSet (Tvariable_set *vs)
 Constructor.
void ResetVarSet (Tvariable_set *vs)
 Resets the information stored in a variable set.
void CopyVarSet (Tvariable_set *vs_dst, Tvariable_set *vs_orig)
 Copy constructor.
void ShiftVarIndexes (unsigned int nv, Tvariable_set *vs)
 Reduces the variable indexes above a given index.
unsigned int CmpVarSet (Tvariable_set *vs1, Tvariable_set *vs2)
 Variable set comparison.
unsigned int GetPlaceinSet (unsigned int id, Tvariable_set *vs)
 Gets the position of a variable index in a set of variable indexes.
boolean VarIncluded (unsigned int id, Tvariable_set *vs)
 Checks if a variable index is included in a set of variable indexes.
boolean Included (unsigned int id, unsigned int p, Tvariable_set *vs)
 Checks if a variable index is included in a set of variable indexes with a given power.
boolean EmptyVarSet (Tvariable_set *vs)
 Checks if a variable set is empty.
void AddVariable2Set (unsigned int varid, unsigned int p, Tvariable_set *vs)
 Adds an element to a variable set.
void RemoveVariableFromSet (unsigned int varid, Tvariable_set *vs)
 Removes an element to a variable set.
unsigned int VarSetOrder (Tvariable_set *vs)
 Gets the order of a variable set.
unsigned int VariableSetSize (Tvariable_set *vs)
 Gets the number of elements of a variable set.
unsigned int GetVariableN (unsigned int n, Tvariable_set *vs)
 Gets a variable identifier from a variable set.
unsigned int * GetVariables (Tvariable_set *vs)
 Gets the variable identifiers stored in a variable set.
unsigned int GetVariablePowerN (unsigned int n, Tvariable_set *vs)
 Gets a variable power from a variable set.
unsigned int * GetPowers (Tvariable_set *vs)
 Gets the variable powers stored in a variable set.
boolean VarSetIntersect (Tvariable_set *vs1, Tvariable_set *vs2)
 Checks if two variable sets have elements in common.
void SubstractVarSet (Tvariable_set *vs1, Tvariable_set *vs2, Tvariable_set *v_out)
 Removes from a set all the elements.
void UnionVarSet (Tvariable_set *vs1, Tvariable_set *vs2, Tvariable_set *v_out)
 Produces a variable set that is the union of two variable sets.
double EvaluateVarSet (double *varValues, Tvariable_set *vs)
 Evaluates a variable set for a given set of value for the variables.
void EvaluateVarSetInt (Tinterval *varValues, Tinterval *i_out, Tvariable_set *vs)
 Evaluates a variable set for a given set of ranges for the variables.
unsigned int DeriveVarSet (unsigned int nv, Tvariable_set *dvs, Tvariable_set *vs)
 Derives an variable set.
void PrintVarSet (FILE *f, char **varNames, Tvariable_set *vs)
 Prints a variable set.
void DeleteVarSet (Tvariable_set *vs)
 Destructor.

Detailed Description

Definition of the Tvariable_set type and the associated functions.

See also:
Tvariable_set, variable_set.c

Definition in file variable_set.h.


Define Documentation

#define INIT_NUM_VARIABLES   10

Initial room for variables. It will be enlarged if necessary.

See also:
Tvariables

Definition at line 28 of file variable_set.h.

Referenced by InitVariables(), and InitVarSet().


Function Documentation

void InitVarSet ( Tvariable_set vs  ) 

Creates an empty set of variable indexes.

Parameters:
vs The variable set to create.

Definition at line 64 of file variable_set.c.

References INIT_NUM_VARIABLES, Tvariable_set::maxvars, NEW, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by CopyEquation(), DeriveEquation(), InitEquation(), InitMonomial(), and SubstractVarSet().

Here is the caller graph for this function:

void ResetVarSet ( Tvariable_set vs  ) 

Removes the information stored in a variable set (variable identifiers and powers) but not the allocated memory. To re-use a Tvariable_set it is more efficient to reset the variable to re-use instead of deleting it and constructing a new set.

Parameters:
vs The variable set to ber eset.

Definition at line 72 of file variable_set.c.

References Tvariable_set::nvars.

Referenced by AddMonomial(), ResetEquation(), ResetMonomial(), and VarScaleEquation().

Here is the caller graph for this function:

void CopyVarSet ( Tvariable_set vs_dst,
Tvariable_set vs_orig 
)

Creates a set of variable from the informatin stored in another set.

Parameters:
vs_dst The variable set to create.
vs_orig The variable set from where to copy.

Definition at line 77 of file variable_set.c.

References Tvariable_set::maxvars, NEW, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by CopyMonomial(), SubstractVarSet(), and UnionVarSet().

Here is the caller graph for this function:

void ShiftVarIndexes ( unsigned int  nv,
Tvariable_set vs 
)

When eliminating a variable from a problem, the indexes of the variables with an identifier above the removed varaible need to be decreased by one. This function performs this opearation for a single variable set.

The variable that we are removing from the problem need to be removed before applying this operation. If the variable set still includes the variable to be removed this function triggers and error.

Parameters:
nv The index of the variable we removed from the problem. Variable indexes above it need to be shifted.
vs The variable set to update.

Definition at line 90 of file variable_set.c.

References Error(), Tvariable_set::nvars, and Tvariable_set::var_id.

Referenced by FixVariableInMonomial(), ReplaceVariableInEquation(), and ReplaceVariableInMonomial().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int CmpVarSet ( Tvariable_set vs1,
Tvariable_set vs2 
)

Compare two given variable sets. Variable sets are compared first taking into account the numver of indexes they include, then the powers of the variables and, finally, the indexes of the variables.

Parameters:
vs1 The first set to compare.
vs2 The second set to compare.
Returns:
1 if vs1 is larger than vs2, 0 if they are equal and 2 if vs2 is larger than vs1.

Definition at line 103 of file variable_set.c.

References Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by CmpMonomial(), and FindMonomial().

Here is the caller graph for this function:

unsigned int GetPlaceinSet ( unsigned int  id,
Tvariable_set vs 
)

Gets the position of a variable index in a set of variable indexes.

Parameters:
id The index of the variable.
vs The set of variable indexes.
Returns:
The position of the variable in the set or NO_UINT if the index is not included in the set.

Definition at line 151 of file variable_set.c.

References FALSE, NO_UINT, and Tvariable_set::var_id.

Referenced by FixVariableInMonomial(), ReplaceVariableInEquation(), ReplaceVariableInMonomial(), and VarIncluded().

Here is the caller graph for this function:

boolean VarIncluded ( unsigned int  id,
Tvariable_set vs 
)

Determines if a variable index is included in a set of variable indexes.

Parameters:
id The index of the variable.
vs The set of variable indexes.
Returns:
TRUE if id is included in vs.

Definition at line 169 of file variable_set.c.

References GetPlaceinSet(), and NO_UINT.

Referenced by DeriveMonomial(), RemoveEquationsWithVar(), UsedVarInEquations(), and UsedVarInNonDummyEquations().

Here is the call graph for this function:

Here is the caller graph for this function:

boolean Included ( unsigned int  id,
unsigned int  p,
Tvariable_set vs 
)

Determines if a variable index is included in a set of variable indexes with a given power.

Parameters:
id The index of the variable.
p The power of the variable.
vs The set of variables.
Returns:
TRUE if id is included in vs with power p.

Definition at line 174 of file variable_set.c.

References FALSE, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by SubstractVarSet(), and VarSetIntersect().

Here is the caller graph for this function:

boolean EmptyVarSet ( Tvariable_set vs  ) 

Checks if a variable set is empty.

Parameters:
vs The set of variables.
Returns:
TRUE if vs is empty.

Definition at line 146 of file variable_set.c.

References Tvariable_set::nvars.

Referenced by PrintMonomial().

Here is the caller graph for this function:

void AddVariable2Set ( unsigned int  varid,
unsigned int  p,
Tvariable_set vs 
)

Adds a variable index with a given power to a variable set.

Parameters:
varid The index of the variable to be added to the set.
p The power for this variable
vs The set of variables to update.

Definition at line 266 of file variable_set.c.

References AddVariableInt(), FALSE, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by AddVariable2Monomial(), and ReplaceVariableInMonomial().

Here is the call graph for this function:

Here is the caller graph for this function:

void RemoveVariableFromSet ( unsigned int  varid,
Tvariable_set vs 
)

Removes a variable index from a variable set.

Parameters:
varid The index of the variable to be removed to the set.
vs The set of variables to update.

Definition at line 284 of file variable_set.c.

References FALSE, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by FixVariableInMonomial(), and ReplaceVariableInMonomial().

Here is the caller graph for this function:

unsigned int VarSetOrder ( Tvariable_set vs  ) 

Returns the order of a variable set: the sum of the powers of the variables in the set.

Parameters:
vs The set of variables to query.
Returns:
The variable set order.

Definition at line 306 of file variable_set.c.

References Tvariable_set::nvars, and Tvariable_set::power.

Referenced by MonomialOrder().

Here is the caller graph for this function:

unsigned int VariableSetSize ( Tvariable_set vs  ) 

Returns the number of elements of a variable set.

Parameters:
vs The set of variables to query.
Returns:
The number of elements of a variable set.

Definition at line 325 of file variable_set.c.

References Tvariable_set::nvars.

Referenced by BilinearMonomial(), CropEquation(), CtMonomial(), DummifyAndAddEquation(), EvaluateMonomial(), EvaluateMonomialInt(), GetBoxMaxSizeVarSet(), GetBoxMinSizeVarSet(), GetEquationNumVariables(), IsSimplificable(), LinearMonomial(), QuadraticMonomial(), ReplaceVariableInEquation(), RewriteEquation(), and SetEquationInfo().

Here is the caller graph for this function:

unsigned int GetVariableN ( unsigned int  n,
Tvariable_set vs 
)

Returns the identifier for the n-th variable in the set.

If the set has less than n elements this functions triggers an error.

Parameters:
n The position for the index to retrive.
vs The set of variables to query.
Returns:
The index of the variable at position n.

Definition at line 330 of file variable_set.c.

References Error(), and Tvariable_set::var_id.

Referenced by CropEquation(), DummifyAndAddEquation(), ErrorDueToVariable(), GetBoxMaxSizeVarSet(), GetBoxMinSizeVarSet(), GetFirstOrderApproximationToEquation(), IsSimplificable(), LinearEquation2LinearConstraint(), LinearizeCircleEquation(), LinearizeGeneralEquation(), LinearizeParabolaEquation(), LinearizeSaddleEquation(), LinearizeSphereEquation(), RewriteEquation(), SetEquationInfo(), and UpdateSplitWeight().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int* GetVariables ( Tvariable_set vs  ) 

Returns the variable identifiers stored in a variable set.

Parameters:
vs The set of variables to query.
Returns:
The a pointer to the array of variable indexes.

Definition at line 341 of file variable_set.c.

References Tvariable_set::var_id.

unsigned int GetVariablePowerN ( unsigned int  n,
Tvariable_set vs 
)

Returns the power for the n-th variable in the set.

If the set has less than n elements this functions triggers an error.

Parameters:
n The position for the variable whose power we want to retrive.
vs The set of variables to query.
Returns:
The power of the variable at position n.

Definition at line 346 of file variable_set.c.

References Error(), and Tvariable_set::power.

Referenced by BilinearMonomial(), DummifyAndAddEquation(), FixVariableInMonomial(), LinearMonomial(), QuadraticMonomial(), ReplaceVariableInEquation(), and ReplaceVariableInMonomial().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int* GetPowers ( Tvariable_set vs  ) 

Returns the variable powers stored in a variable set.

Parameters:
vs The set of variables to query.
Returns:
The a pointer to the array of variable powers.

Definition at line 357 of file variable_set.c.

References Tvariable_set::power.

boolean VarSetIntersect ( Tvariable_set vs1,
Tvariable_set vs2 
)

Determines if two variable sets have any element in common. To determine if two variable set elements are the same we take into account bot the variable index and its power.

Parameters:
vs1 The first set of variables to intersect.
vs2 The second set of variables to intersect.
Returns:
TRUE if the intersection between the sets is non-empty.

Definition at line 190 of file variable_set.c.

References FALSE, Included(), Tvariable_set::power, and Tvariable_set::var_id.

Here is the call graph for this function:

void SubstractVarSet ( Tvariable_set vs1,
Tvariable_set vs2,
Tvariable_set v_out 
)

Defines a variable set that is the first input, but without the elements in the second parameter. To determine if two variable set elements are the same we take into account bot the variable index and its power.

Parameters:
vs1 The first variable set.
vs2 The set with the variables to remove from vs1.
v_out The resulting set of variables.

Definition at line 206 of file variable_set.c.

References AddVariableInt(), CopyVarSet(), DeleteVarSet(), Included(), InitVarSet(), Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Here is the call graph for this function:

void UnionVarSet ( Tvariable_set vs1,
Tvariable_set vs2,
Tvariable_set v_out 
)

Produces a variable set that is the union of two variable sets: i.e., it includes the variables in both sets.

Parameters:
vs1 The first variable set.
vs2 The second variable set.
v_out The resulting set of variables.

Definition at line 228 of file variable_set.c.

References AddVariableInt(), CopyVarSet(), DeleteVarSet(), FALSE, Tvariable_set::nvars, Tvariable_set::power, TRUE, and Tvariable_set::var_id.

Referenced by AddMonomial(), and VarScaleEquation().

Here is the call graph for this function:

Here is the caller graph for this function:

double EvaluateVarSet ( double *  varValues,
Tvariable_set vs 
)

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

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

Definition at line 362 of file variable_set.c.

References Error(), Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by EvaluateMonomial().

Here is the call graph for this function:

Here is the caller graph for this function:

void EvaluateVarSetInt ( Tinterval varValues,
Tinterval i_out,
Tvariable_set vs 
)

Evaluates a variable set 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.
vs The variable set to evaluate.

Definition at line 382 of file variable_set.c.

References Error(), IntervalPow(), IntervalProduct(), NewInterval(), Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by EvaluateMonomialInt().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int DeriveVarSet ( unsigned int  nv,
Tvariable_set dvs,
Tvariable_set vs 
)

Derives a variable set with respect to a given variable.

Parameters:
nv Identifier of the variable with respect to the one we have to derive.
dvs Output variable set with the derived variable set.
vs The variable set to derive.

Definition at line 403 of file variable_set.c.

References Tvariable_set::maxvars, NEW, Tvariable_set::nvars, Tvariable_set::power, and Tvariable_set::var_id.

Referenced by DeriveMonomial().

Here is the caller graph for this function:

void PrintVarSet ( FILE *  f,
char **  varNames,
Tvariable_set vs 
)

Writes a variable set to a given stream.

Parameters:
f The stream where to print the variable set.
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.
vs The variable set to print.

Definition at line 436 of file variable_set.c.

References Tvariable_set::nvars, Tvariable_set::power, PRINT_VARIABLE_NAME, and Tvariable_set::var_id.

Referenced by PrintMonomial().

Here is the caller graph for this function:

void DeleteVarSet ( Tvariable_set vs  ) 

Deletes the information stored in the variable set and frees the allocated memory space.

Parameters:
vs The variable set to be deleted.

Definition at line 462 of file variable_set.c.

References Tvariable_set::power, and Tvariable_set::var_id.

Referenced by DeleteEquation(), DeleteMonomial(), SubstractVarSet(), and UnionVarSet().

Here is the caller graph for this function: