variables.c File Reference

Introduction

Implementation of the functions operating on box Tvariables.

See also
Tvariables, variables.h.

Definition in file variables.c.

Functions

void InitVariables (Tvariables *vs)
 Constructor. More...
 
void CopyVariables (Tvariables *vs_dst, Tvariables *vs_src)
 Copy onstructor. More...
 
unsigned int NVariables (Tvariables *vs)
 Gets the number of variables in a set. More...
 
unsigned int GetNumCartesianVariables (Tvariables *vs)
 Gets the number of cartesian variables in a set. More...
 
unsigned int GetNumDummyVariables (Tvariables *vs)
 Gets the number of dummy variables in a set. More...
 
unsigned int GetNumPositionVariables (Tvariables *vs)
 Gets the number of position variables in a set. More...
 
unsigned int GetNumVelocityVariables (Tvariables *vs)
 Gets the number of velocity variables in a set. More...
 
unsigned int GetNumNonDynamicVariables (Tvariables *vs)
 Gets the number of non-dynamic variables in a set. More...
 
unsigned int GetNumSystemVariables (Tvariables *vs)
 Gets the number of system variables in a set. More...
 
unsigned int GetNumSecondaryVariables (Tvariables *vs)
 Gets the number of secondary variables in a set. More...
 
boolean IsSystemVariable (unsigned int n, Tvariables *vs)
 Identifies system variables in a set. More...
 
boolean IsSecondaryVariable (unsigned int n, Tvariables *vs)
 Identifies secondary variables in a set. More...
 
boolean IsDummyVariable (unsigned int n, Tvariables *vs)
 Identifies dummy variables in a set. More...
 
boolean IsCartesianVariable (unsigned int n, Tvariables *vs)
 Identifies cartesian variables in a set. More...
 
boolean IsPositionVariable (unsigned int n, Tvariables *vs)
 Identifies position variables in a set. More...
 
boolean IsVelocityVariable (unsigned int n, Tvariables *vs)
 Identifies velocity variables in a set. More...
 
boolean IsNonDynamicVariable (unsigned int n, Tvariables *vs)
 Identifies non-dynamic variables in a set. More...
 
unsigned int GetVariableTypeN (unsigned int n, Tvariables *vs)
 Gets the type of a particular variable. More...
 
unsigned int AddVariable (Tvariable *v, Tvariables *vs)
 Adds a variable to the set. More...
 
TvariableGetVariableWithName (char *name, Tvariables *vs)
 Gets the information of a variable given the name of this variable. More...
 
TvariableGetVariable (unsigned int n, Tvariables *vs)
 Gets the information of a variable given its number in the set (i.e., its identifier). More...
 
unsigned int GetVariableID (char *name, Tvariables *vs)
 Gets the variable identifier (i.e., its position in the set) given a variable name. More...
 
unsigned int GetVariablesTopology (unsigned int **t, Tvariables *vs)
 Gets the topology for the variables in the set. More...
 
void GetVariableNames (char **varNames, Tvariables *vs)
 Gets the name for all the variables in the set. More...
 
char * VariableName (unsigned int i, Tvariables *vs)
 Gets the name for a particular variable. More...
 
void RemoveVariable (unsigned int n, Tvariables *vs)
 Removes a variable from a set. More...
 
void BoxFromVariables (Tbox *b, Tvariables *vs)
 Creates a box from the ranges of a set of variables. More...
 
void PointFromVariables (double **p, Tvariables *vs)
 Creates a point from the center of the ranges of a set of variables. More...
 
void VariablesFromBox (Tbox *b, Tvariables *vs)
 Define the range for the variables from a box. More...
 
void PrintVariables (FILE *f, Tvariables *vs)
 Prints a set of variables to an stream. More...
 
void DeleteVariables (Tvariables *vs)
 Destructor. More...
 

Function Documentation

◆ InitVariables()

void InitVariables ( Tvariables vs)

Defines an empty set of variables.

Parameters
vsThe variable set to initalize.

Definition at line 24 of file variables.c.

References Tvariables::car, Tvariables::dum, INIT_NUM_VARIABLES, Tvariables::max_variables, Tvariables::n, Tvariables::ndy, NEW, Tvariables::sec, Tvariables::sys, Tvariables::vel, and Tvariables::vs.

Referenced by InitCuikSystem().

◆ CopyVariables()

void CopyVariables ( Tvariables vs_dst,
Tvariables vs_src 
)

Defines a set of variables from another set

Parameters
vs_dstThe variable set to initalize.
vs_srcThe variable set from where to copy.

Definition at line 42 of file variables.c.

References Tvariables::car, CopyVariable(), Tvariables::dum, Tvariables::max_variables, Tvariables::n, Tvariables::ndy, NEW, Tvariables::sec, Tvariables::sys, Tvariables::vel, and Tvariables::vs.

Referenced by CopyCuikSystem(), CopyMapping(), CuikSystemMerge(), GetCSVariables(), InitMapping(), and SimplifyCuikSystem().

◆ NVariables()

◆ GetNumCartesianVariables()

unsigned int GetNumCartesianVariables ( Tvariables vs)

Returns the number of cartesian variables in a variable set.

Parameters
vsThe variable set to query.
Returns
The number of cartesian variables in the set.

Definition at line 81 of file variables.c.

References Tvariables::car.

◆ GetNumDummyVariables()

unsigned int GetNumDummyVariables ( Tvariables vs)

Returns the number of dummy variables in a variable set.

Parameters
vsThe variable set to query.
Returns
The number of dummy variables in the set.

Definition at line 86 of file variables.c.

References Tvariables::dum.

Referenced by CuikGradientInBox(), CuikNewtonInBox(), and GetCSNumNonDummyVariables().

◆ GetNumPositionVariables()

unsigned int GetNumPositionVariables ( Tvariables vs)

Returns the number of position variables in a variable set.

Parameters
vsThe variable set to query.
Returns
The number of position variables in the set.

Definition at line 91 of file variables.c.

References Tvariables::n, Tvariables::ndy, and Tvariables::vel.

Referenced by CopyNonDynamicsJacobian(), CopyPositionJacobian(), InitNJacobian(), InitPositionJacobian(), and InitScalarPositionJacobian().

◆ GetNumVelocityVariables()

unsigned int GetNumVelocityVariables ( Tvariables vs)

Returns the number of velocity variables in a variable set.

Parameters
vsThe variable set to query.
Returns
The number of velocity variables in the set.

Definition at line 96 of file variables.c.

References Tvariables::vel.

Referenced by AddVelocityEquations(), CuikHasVelocity(), GetCSNumSystemVariables(), InitNHessian(), InitNJacobian(), and PrintCuikSystemWithSimplification().

◆ GetNumNonDynamicVariables()

unsigned int GetNumNonDynamicVariables ( Tvariables vs)

Returns the number of non-dynamic variables in a variable set.

Parameters
vsThe variable set to query.
Returns
The number of non-dynamic variables in the set.

Definition at line 101 of file variables.c.

References Tvariables::ndy.

Referenced by CopyNonDynamicsJacobian(), GetCSNumNonDynamicVariables(), GetCSNumSystemVariables(), InitNHessian(), and PrintCuikSystemWithSimplification().

◆ GetNumSystemVariables()

unsigned int GetNumSystemVariables ( Tvariables vs)

Returns the number of system variables in a variable set.

Parameters
vsThe variable set to query.
Returns
The number of system variables in the set.

Definition at line 109 of file variables.c.

References Tvariables::sys.

Referenced by GetCSNumSystemVariables(), and PrintCuikSystemWithSimplification().

◆ GetNumSecondaryVariables()

unsigned int GetNumSecondaryVariables ( Tvariables vs)

Returns the number of secondary variables in a variable set.

Parameters
vsThe variable set to query.
Returns
The number of secondary variables in the set.

Definition at line 117 of file variables.c.

References Tvariables::sec.

Referenced by GetCSNumSystemVariables(), and PrintCuikSystemWithSimplification().

◆ IsSystemVariable()

boolean IsSystemVariable ( unsigned int  n,
Tvariables vs 
)

Identifies system variables in a set.

Parameters
nThe number of variable to query
vsThe variable set to query.
Returns
TRUE if variable number n is a system variable.

Definition at line 122 of file variables.c.

References GetVariableType(), SYSTEM_VAR, and Tvariables::vs.

Referenced by CSRemoveLCVars(), GetCSSystemVariableName(), GetCSSystemVars(), IncrementalSampleCuikSystemInBox(), IsSystemVarInSimpCS(), and UpdateCuikSystem().

◆ IsSecondaryVariable()

boolean IsSecondaryVariable ( unsigned int  n,
Tvariables vs 
)

Identifies secondary variables in a set.

Parameters
nThe number of variable to query
vsThe variable set to query.
Returns
TRUE if variable number n is a secondary variable.

Definition at line 127 of file variables.c.

References GetVariableType(), SECONDARY_VAR, and Tvariables::vs.

Referenced by GetCSSystemVariableName(), GetCSSystemVars(), IsSystemVarInSimpCS(), and UpdateCuikSystem().

◆ IsDummyVariable()

boolean IsDummyVariable ( unsigned int  n,
Tvariables vs 
)

Identifies dummy variables in a set.

Parameters
nThe number of variable to query
vsThe variable set to query.
Returns
TRUE if variable number n is a dummy variable.

Definition at line 132 of file variables.c.

References DUMMY_VAR, GetVariableType(), and Tvariables::vs.

Referenced by PointInSystemBox(), RegenerateSolution(), and UpdateCuikSystem().

◆ IsCartesianVariable()

boolean IsCartesianVariable ( unsigned int  n,
Tvariables vs 
)

Identifies cartesian variables in a set.

Parameters
nThe number of variable to query
vsThe variable set to query.
Returns
TRUE if variable number n is a cartesian variable.

Definition at line 137 of file variables.c.

References CARTESIAN_VAR, GetVariableType(), and Tvariables::vs.

Referenced by RegenerateSolution().

◆ IsPositionVariable()

boolean IsPositionVariable ( unsigned int  n,
Tvariables vs 
)

Identifies position variables in a set (only used in dynamical systems).

A variable is a position variable if it is not a velocity

Parameters
nThe number of variable to query
vsThe variable set to query.
Returns
TRUE if variable number n is a position variable.

Definition at line 142 of file variables.c.

References GetVariableType(), NON_DYNAMIC_VAR, VELOCITY_VAR, and Tvariables::vs.

Referenced by AddVelocityEquations(), CopyNonDynamicsJacobian(), CopyPositionJacobian(), CSRemoveVarsWithCtRange(), GetCSPositionVars(), GetCSSystemVariableName(), GetCSSystemVars(), InitPositionJacobian(), InitScalarPositionJacobian(), IsSystemVarInSimpCS(), and UpdateCuikSystem().

◆ IsVelocityVariable()

boolean IsVelocityVariable ( unsigned int  n,
Tvariables vs 
)

Identifies velocity variables in a set (only used in dynamical systems).

Parameters
nThe number of variable to query
vsThe variable set to query.
Returns
TRUE if variable number n is a velocity variable.

Definition at line 149 of file variables.c.

References GetVariableType(), VELOCITY_VAR, and Tvariables::vs.

Referenced by CopyNonDynamicsJacobian().

◆ IsNonDynamicVariable()

boolean IsNonDynamicVariable ( unsigned int  n,
Tvariables vs 
)

Identifies non-dynamic variables in a set (only used in dynamical systems).

Parameters
nThe number of variable to query
vsThe variable set to query.
Returns
TRUE if variable number n is a non-dynamic variable.

Definition at line 154 of file variables.c.

References GetVariableType(), NON_DYNAMIC_VAR, and Tvariables::vs.

Referenced by GetCSPositionVelocityVars().

◆ GetVariableTypeN()

unsigned int GetVariableTypeN ( unsigned int  n,
Tvariables vs 
)

Returns the type of a given variable in the set.

If the set has less than n variables, this function triggers an error.

Parameters
nThe number of variable to query
vsThe variable set to query.
Returns
The type of variable n.

Definition at line 159 of file variables.c.

References Error(), GetVariableType(), Tvariables::n, and Tvariables::vs.

Referenced by CropEquation(), CropLinearConstraint(), CSRemoveUnusedVars(), SampleCuikSystemInBox(), and UpdateCuikSystem().

◆ AddVariable()

unsigned int AddVariable ( Tvariable v,
Tvariables vs 
)

◆ GetVariableWithName()

Tvariable* GetVariableWithName ( char *  name,
Tvariables vs 
)

Returns a pointer to the variable information given the name of the variable to query.

Parameters
nameThe name of the variable to retrive.
vsThe variable set to query.
Returns
A pointer to the information relative to the variable with the given name. NULL if there is no variable with the given name.

Definition at line 213 of file variables.c.

References GetVariableID(), NO_UINT, and Tvariables::vs.

Referenced by AddVariable().

◆ GetVariable()

Tvariable* GetVariable ( unsigned int  n,
Tvariables vs 
)

Returns a pointer to the variable information given its position in the set (i.e., its identifier). If the set has less than n variables, this function triggers an error.

Parameters
nThe number of the variable to retrive.
vsThe variable set to query.
Returns
A pointer to the information relative to the variable with the given name.

Definition at line 227 of file variables.c.

References Error(), Tvariables::n, and Tvariables::vs.

Referenced by BoxFromVariables(), CSRemoveLCVars(), CSRemoveVarsWithCtRange(), CuikSystemMerge(), DummifyAndAddEquation(), GetCSVariable(), GetCSVarTopology(), InitMapping(), IsInSimple(), PointFromVariables(), PrintVariables(), SampleCuikSystemInBox(), SetCSVariableRange(), SimplifyCuikSystem(), and VariablesFromBox().

◆ GetVariableID()

unsigned int GetVariableID ( char *  name,
Tvariables vs 
)

Returns the variable identifier (i.e., its position in the set) given a variable name.

Parameters
nameThe name of the variable whose identifier we want to retrive.
vsThe variable set to query.
Returns
The variable indentifier or NO_UINT if there is not a variable with the given name in the set.

Definition at line 239 of file variables.c.

References FALSE, GetVariableName(), NO_UINT, TRUE, and Tvariables::vs.

Referenced by AddVariable2CS(), CSRemoveLCVars(), CSRemoveVarsWithCtRange(), DummifyAndAddEquation(), GetCSVariableID(), GetVariableWithName(), InitMapping(), IsInSimple(), IsSystemVarInSimpCS(), and SimplifyCuikSystem().

◆ GetVariablesTopology()

unsigned int GetVariablesTopology ( unsigned int **  t,
Tvariables vs 
)

Gets an array with the topology of the variables in the set. The array is allocated inside the call and must be deallocated by the caller.

Parameters
tThe topology array to allocate and initialze.
vsThe variable set to query.

Definition at line 260 of file variables.c.

References GetVariableTopology(), Tvariables::n, NEW, and Tvariables::vs.

Referenced by GetCSTopology(), GetSimpCSTopology(), and UpdateCuikSystem().

◆ GetVariableNames()

void GetVariableNames ( char **  varNames,
Tvariables vs 
)

Gets a pointer to the name for all the variables in the set.

Parameters
varNamesSpace for the pointers to the variable names.
vsThe variable set to query.

Definition at line 272 of file variables.c.

References GetVariableName(), Tvariables::n, and Tvariables::vs.

Referenced by AddSimplifiedJacobianEquations(), CopyCuikSystem(), CSRemoveLCVars(), CSRemoveVarsWithCtRange(), GetCSVariableNames(), PrintCuikSystem(), PrintCuikSystemWithSimplification(), PrintMapping(), SimplifyCuikSystem(), and UpdateCuikSystem().

◆ VariableName()

char* VariableName ( unsigned int  i,
Tvariables vs 
)

Gets a pointer to the name if a particular variable.

Parameters
iThe identifier of the variable.
vsThe variable set to query.
Returns
The pointer to the variable name or NULL if the identifier does not correspond to a valid variable.

Definition at line 280 of file variables.c.

References GetVariableName(), and Tvariables::vs.

Referenced by AddSimplifiedJacobianEquations(), AddVelocityEquations(), GetCSSystemVariableName(), and GetCSVariableName().

◆ RemoveVariable()

void RemoveVariable ( unsigned int  n,
Tvariables vs 
)

Removes a variable from a set. After removing, the variable set is compacted, i.e., the gap of the remove variable is eliminated and this changes the variable indentifiers for the variables stored above the removed variable.

Parameters
nThe identifier of the variable to remove.
vsThe variable set to update.

Definition at line 295 of file variables.c.

References Tvariables::car, CARTESIAN_VAR, DeleteVariable(), Tvariables::dum, DUMMY_VAR, GetVariableType(), Tvariables::n, Tvariables::ndy, NON_DYNAMIC_VAR, Tvariables::sec, SECONDARY_VAR, Tvariables::sys, SYSTEM_VAR, Tvariables::vel, VELOCITY_VAR, and Tvariables::vs.

Referenced by CSRemoveLCVars(), CSRemoveUnusedVars(), and CSRemoveVarsWithCtRange().

◆ BoxFromVariables()

void BoxFromVariables ( Tbox b,
Tvariables vs 
)

Creates a box from the ranges of a set of variables.

Parameters
bThe box to be created.
vsThe variable set.

Definition at line 323 of file variables.c.

References GetVariable(), GetVariableInterval(), InitBox(), NVariables(), and SetBoxInterval().

Referenced by GenerateInitialBox(), GenerateSimpInitialBox(), IncrementalSampleCuikSystemInBox(), MPI_SolveCuikSystem(), PostProcessBox(), RegenerateOriginalBox(), SimpleFromOriginal(), SimplifyCuikSystem(), and SolveCuikSystem().

◆ PointFromVariables()

void PointFromVariables ( double **  p,
Tvariables vs 
)

Creates a point from the center of the ranges of a set of variables.

Parameters
pThe point to be created. The space for this point is allocated inside this function but must be deallocated externally.
vsThe variable set.

Definition at line 334 of file variables.c.

References GetVariable(), GetVariableInterval(), IntervalCenter(), NEW, and NVariables().

Referenced by RegenerateOriginalPoint(), and SimplePointFromOriginal().

◆ VariablesFromBox()

void VariablesFromBox ( Tbox b,
Tvariables vs 
)

Changes the ranges for all variables from the ranges given in a box. This is the function complementary to BoxFromVariables.

Parameters
bThe box from where to take the ranges.
vsThe set of variables whose ranges to changes.

Definition at line 345 of file variables.c.

References GetBoxInterval(), GetVariable(), NVariables(), and SetVariableInterval().

Referenced by IncrementalSampleCuikSystemInBox().

◆ PrintVariables()

void PrintVariables ( FILE *  f,
Tvariables vs 
)

Prints a set of variables to an stream, that can be stdout. Variables are printed in a format that can be properly parsed by the .cuik file parser.

Parameters
fThe stream where to print.
vsThe variable set to print.
See also
readcuiksystem.l, readcuiksystem.y.

Definition at line 358 of file variables.c.

References CARTESIAN_VAR, DUMMY_VAR, Error(), GetVariable(), GetVariableType(), Tvariables::n, NON_DYNAMIC_VAR, PrintVariable(), SECONDARY_VAR, SYSTEM_VAR, VELOCITY_VAR, and Tvariables::vs.

Referenced by CSRemoveLCVars(), CSRemoveVarsWithCtRange(), PrintCuikSystem(), PrintCuikSystemWithSimplification(), and SimplifyCuikSystem().

◆ DeleteVariables()

void DeleteVariables ( Tvariables vs)

Deletes the Tvariables structure and frees the allocated memory.

Parameters
vsThe variable set to delete.

Definition at line 400 of file variables.c.

References DeleteVariable(), Tvariables::n, and Tvariables::vs.

Referenced by DeleteCuikSystem(), DeleteMapping(), GenerateWorldEquations(), and UnUpdateCuikSystem().