sample.c File Reference

Detailed Description

Implementaton of the function operating on Tsample.

See Also
Tsample, sample.h.

Definition in file sample.c.

Functions

void InitSample (unsigned int sID, unsigned int n, double *v, unsigned int boxID, Tsample *s)
 Constructor. More...
 
void InitSampleFromBox (unsigned int sID, boolean *systemVar, Tbox *b, unsigned int boxID, Tsample *s)
 Constructor. More...
 
void CopySample (void *s_dst, void *s_src)
 Constructor. More...
 
unsigned int GetSampleDim (Tsample *s)
 Returns the dimensionality of the space where the sample is defined. More...
 
TvectorGetSampleValues (Tsample *s)
 Gets the values of the sample. More...
 
double GetSampleValue (unsigned int n, Tsample *s)
 Gets the value for a given dimension of the sample. More...
 
unsigned int GetSampleBoxID (Tsample *s)
 Gets the identifier of the box that includes the sample. More...
 
unsigned int GetSampleID (Tsample *s)
 Gets the identifier of the sample. More...
 
void SetSampleBoxID (unsigned int boxID, Tsample *s)
 Changes the identifier of the box to which the sample is linked. More...
 
double GetSampleDistance (Tsample *s1, Tsample *s2)
 Computes the Euclidean distance between two samples. More...
 
void PrintSample (FILE *f, Tsample *s)
 Prints a sample. More...
 
void SaveSample (FILE *f, Tsample *s)
 Saves the information of the sample in a file. More...
 
void LoadSample (FILE *f, Tsample *s)
 Constructor. More...
 
void DeleteSample (void *s)
 Destructor. More...
 

Function Documentation

void InitSample ( unsigned int  sID,
unsigned int  n,
double *  v,
unsigned int  boxID,
Tsample s 
)

Initializes a new sample.

Parameters
sIDThe identifier assigned to the sample.
nNumber of system variables in the mechanism at hand.
vArray of doubles, one for each system variable in the mechanism.
boxIDIdentifier of the box that holds the sample. NO_UINT if the sample is not assiged to any box yet.
sThe sample to initialize.

Definition at line 16 of file sample.c.

References Tsample::boxID, CopyDouble(), DeleteDouble(), InitVector(), SetVectorElement(), Tsample::sID, and Tsample::v.

Referenced by InitSampleFromBox().

void InitSampleFromBox ( unsigned int  sID,
boolean systemVar,
Tbox b,
unsigned int  boxID,
Tsample s 
)

Initializes a new sample from a box. The values for the sample are taken from the box center for the system variables.

Parameters
sIDThe identifier assigned to the sample.
systemVarArray of booleans, one for each dimension of the given box where only entries for system variables are set to TRUE.
bThe box from where to get the values.
boxIDIdentifier of the box that holds the sample. NO_UINT if the sample is not assiged to any box yet.
sThe sample to initialize.

Definition at line 29 of file sample.c.

References GetBoxInterval(), GetBoxNIntervals(), InitSample(), IntervalCenter(), and NEW.

Referenced by main().

void CopySample ( void *  s_dst,
void *  s_src 
)

Creates a new sample copying the information from another sample.

Parameters
s_dstThe sample to initialize.
s_srcThe sample from where to copy the data.

Definition at line 62 of file sample.c.

References CopyVector().

unsigned int GetSampleDim ( Tsample s)

Returns the dimensionality of the space where the sample is defined, i.e., the dimensionality of the configuration space.

Parameters
sThe sample to query.

Definition at line 69 of file sample.c.

References Tsample::v, and VectorSize().

Referenced by GetSampleDistance().

Tvector* GetSampleValues ( Tsample s)

Gets the values of the sample.

Parameters
sThe sample to query.
Returns
A pointer to the vector with the doubles, one for each system variable in the mechanism at hand.

Definition at line 74 of file sample.c.

References Tsample::v.

double GetSampleValue ( unsigned int  n,
Tsample s 
)

Gets the value for a given dimension of the sample.

Parameters
nThe dimension to query
sThe sample to query.
Returns
The value of the sample along the requested dimension.

Definition at line 79 of file sample.c.

References Error(), GetVectorElement(), and Tsample::v.

Referenced by GetSampleDistance().

unsigned int GetSampleBoxID ( Tsample s)

Gets the identifier of the box that includes the sample.

Parameters
sThe sample to query.
Returns
The identifier of the box that includes the sample. Can be NO_UINT if the sample is not assigned to any box yet.

Definition at line 91 of file sample.c.

References Tsample::boxID.

unsigned int GetSampleID ( Tsample s)

Gets the identifier of the sample.

Parameters
sThe sample to query.
Returns
The identifier of the sample.

Definition at line 96 of file sample.c.

References Tsample::sID.

void SetSampleBoxID ( unsigned int  boxID,
Tsample s 
)

Changes the identifier of the box to which the sample is linked.

Parameters
boxIDThe new box identifier to store in the sample.
sThe sample to update.

Definition at line 101 of file sample.c.

References Tsample::boxID.

double GetSampleDistance ( Tsample s1,
Tsample s2 
)

Computes the Euclidean distance between two samples. This is a lower bound of the distance between the two samples on the configuration space.

Parameters
s1The first sample.
s2The second sample.

Definition at line 106 of file sample.c.

References Error(), GetSampleDim(), and GetSampleValue().

void PrintSample ( FILE *  f,
Tsample s 
)

Prints the information stored in the sample. Only the values for each one of the system variables is printed. This is in contrast with SaveSample that prints allç the information stored in the sample (values for the variables, identifier, box identifier, etc).

Parameters
fThe file where to save the data.
sThe sample to print.

Definition at line 126 of file sample.c.

References GetVectorElement(), PrintReal(), Tsample::v, and VectorSize().

Referenced by main(), and SaveSample().

void SaveSample ( FILE *  f,
Tsample s 
)

Saves the information of the sample in a file.

Parameters
fThe file where to save the data.
sThe sample to save.

Definition at line 142 of file sample.c.

References Tsample::boxID, PrintSample(), Tsample::sID, Tsample::v, and VectorSize().

void LoadSample ( FILE *  f,
Tsample s 
)

Creates a new sample reading the information from a file.

Parameters
fThe file from where to read the information.
sThe sample to initialize.

Definition at line 148 of file sample.c.

References Tsample::boxID, CopyDouble(), DeleteDouble(), InitVector(), SetVectorElement(), Tsample::sID, and Tsample::v.

void DeleteSample ( void *  s)

Deletes the information stored in a Tsample and frees the allocated memory.

Parameters
sThe sample to delete.

Definition at line 164 of file sample.c.

References DeleteVector().

Referenced by main().