The Conley-Morse Graphs Software
Classes | Functions
utils.h File Reference

Utilites and helper functions. More...

#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <ios>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <new>
#include "chomp/system/config.h"
#include "chomp/system/textfile.h"
#include "chomp/cubes/cube.h"
#include "chomp/multiwork/mw.h"
#include "chomp/struct/autoarray.h"
#include "config.h"
#include "typedefs.h"

Go to the source code of this file.

Classes

class  local_value< T >
 Initializes the given variable with the value provided and restores the previous value at the end of the current block. More...
 
class  CoordMinMax
 A class whose objects store, update and show coordinate ranges. More...
 
class  set2arrayWrapper< elemType, setType >
 An imitation of an array whose entries are 1 iff the index belongs to the given set. More...
 

Functions

bool fileExists (const char *filename)
 Returns 'true' iff the given file exists and it is allowed to read it. More...
 
std::string fileNameWithoutExt (const std::string &fileName)
 Returns the file name without its extension if any. More...
 
template<class intType1 , class intType2 , class intType3 >
bool internalBoundaryPoint (const intType1 *coord, const intType2 *left, const intType2 *right, const intType3 *limit, int dim)
 Verifies whether the given box is located at the boundary of the small region which is either not at the boundary of the large region, or is adjacent to some other similar region. More...
 
template<class intType >
void computeParam (const intType *curCoord, double *leftMapParam, double *rightMapParam)
 Computes the real coordinates of the parameter cube which corresponds to the given box. More...
 
parRectsubRectangles (parCoord *zeroIter, parCoord *maxIter, std::vector< parCoord > *subCoords, int minCount)
 Determines heuristically an optimal subdivision of a large parameter region into the given minimal number of smaller regions. More...
 
template<class intType >
int countDigits (intType x)
 Returns the number of digits of the given non-negative integer number. More...
 
template<class intType1 , class intType2 >
std::string coord2str (const intType1 *coords, const intType2 *maxCoords, int dim)
 Generates an underscore-separated list of non-negative coordinates padded with zeros to the same width assuming that their values are below the given limits. More...
 
template<class intType >
std::string coord2str (const intType *coords, int dim)
 Generates an underscore-separated list of non-negative coordinates. More...
 
template<class cubeType >
std::string coord2str (const cubeType &q)
 Generates an underscore-separated list of non-negative coordinates. More...
 
std::ostream & operator<< (std::ostream &out, const CoordMinMax &range)
 Outputs the ranges of coordinates to an output stream. More...
 
template<class OutStream >
OutStream & showRealCoords (OutStream &out, const CoordMinMax &range)
 Shows the real coordinates of the coordinate range. More...
 
bool checkIsolation (const spcCubes &theSet, int depth)
 Verifies if the given set of cubes is contained in the interior of the phase space box. More...
 
template<class typeCubes >
void subdivideCubes (const typeCubes &X, typeCubes &result)
 Subdivides one set of cubes to another set of cubes with respect to twice finer grid. More...
 
template<class typeCube , class typeCubes >
void subdivideCube (const typeCube &q, typeCubes &result)
 Subdivides a cube to a set of cubes with respect to twice finer grid. More...
 
template<class typeCubes >
void embedCubes (const typeCubes &X, typeCubes &result)
 Embeds a set of cubes to another set of cubes with respect to twice coarser grid. More...
 
void enhanceCubes (spcCubes &X, int enhanceTimes, int subdivDepth)
 Enhances the given set of cubes provided number of times. More...
 
double cubesVolume (int_t nCubes, int subdiv)
 Returns the volume of the given number of cubes in the phase space at the provided subdivision level. More...
 
template<class CoordType >
void cropRanges (CoordType *left, CoordType *right, int dim, int intwidth, bool throwIfCropped, bool &cropped)
 Crops the ranges, marks this fact if it occurred, and throws an exception if requested to. More...
 
template<class CoordType >
long checkImageSize (const CoordType *left, const CoordType *right, int dim, int &maxImgDiam, int &maxImgVol, int maxImgDiamAllowed, int maxImgVolAllowed)
 Checks if the size of the image does not exceed the globally defined maximal diameter and maximal volume (throws exceptions should this be the case), and updates variables that store maximal values of these quantities. More...
 
template<class ObjectType , class ArrayType >
bool objectInArray (const ObjectType &theObject, const ArrayType &theArray, int_t arraySize)
 Checks if the given object is in the array of the given size. More...
 
template<class HashSetType >
void moveSomeToFront (HashSetType &X, int_t step)
 Replaces the hashed set of objects with another one that contains the same objects, but some of the objects are moved selectively to the front, taking the suggested step size in going through the initial hashed set. More...
 
template<class CoordType , class IntervalType >
double intersectionVolume (const CoordType *c, const IntervalType *intervalBox, int dim)
 Computes the volume of the intersection of the unitary cube with the provided coordinates with the given product of intervals. More...
 
template<class SetType , class GraphType >
void computeRestrictedGraph (GraphType &restr, const GraphType &g, const SetType &full, const SetType &subset)
 Computes the graph corresponding to the restriction of the combinatorial map to the provided subset. More...
 
std::string double2string (const double &x, int precision)
 Creates a text representation of a floating-point number at the prescribed precision. More...
 
void showProgress (int n, char c)
 Shows a progress indicator to the screen as an integer number followed by an additional character (e.g. More...
 

Detailed Description

Utilites and helper functions.

This file contains the definitions of various little useful utility procedures for the Conley-Morse graphs computation software.

Author
Pawel Pilarczyk

Definition in file utils.h.

Function Documentation

◆ checkImageSize()

template<class CoordType >
long checkImageSize ( const CoordType *  left,
const CoordType *  right,
int  dim,
int &  maxImgDiam,
int &  maxImgVol,
int  maxImgDiamAllowed,
int  maxImgVolAllowed 
)
inline

Checks if the size of the image does not exceed the globally defined maximal diameter and maximal volume (throws exceptions should this be the case), and updates variables that store maximal values of these quantities.

Returns the volume of the entire rectangular box.

Definition at line 755 of file utils.h.

Referenced by MapComputation< mapcomp, cubetype, cubsettype >::operator()(), and MapComputationTight< mapcomp, cubetype, cubsettype >::operator()().

◆ checkIsolation()

bool checkIsolation ( const spcCubes theSet,
int  depth 
)
inline

Verifies if the given set of cubes is contained in the interior of the phase space box.

Definition at line 565 of file utils.h.

References custom::difference::spaceDim.

Referenced by computeMorseDecomposition(), and invMorseDec().

◆ computeParam()

template<class intType >
void computeParam ( const intType *  curCoord,
double *  leftMapParam,
double *  rightMapParam 
)

Computes the real coordinates of the parameter cube which corresponds to the given box.

Uses the globally defined ranges.

Definition at line 160 of file utils.h.

References custom::difference::paramCount, custom::difference::paramDim, custom::difference::paramLeft, custom::difference::paramRight, custom::difference::paramSelect, and custom::difference::paramSubdiv.

Referenced by Coordinator::Prepare(), Worker::Process(), runMapComp(), and runSingleComp().

◆ computeRestrictedGraph()

template<class SetType , class GraphType >
void computeRestrictedGraph ( GraphType &  restr,
const GraphType &  g,
const SetType &  full,
const SetType &  subset 
)
inline

Computes the graph corresponding to the restriction of the combinatorial map to the provided subset.

Definition at line 930 of file utils.h.

Referenced by custom::procRecurrence::processMorseSet().

◆ coord2str() [1/3]

template<class cubeType >
std::string coord2str ( const cubeType &  q)
inline

Generates an underscore-separated list of non-negative coordinates.

Definition at line 419 of file utils.h.

References coord2str().

◆ coord2str() [2/3]

template<class intType >
std::string coord2str ( const intType *  coords,
int  dim 
)
inline

Generates an underscore-separated list of non-negative coordinates.

Definition at line 405 of file utils.h.

◆ coord2str() [3/3]

template<class intType1 , class intType2 >
std::string coord2str ( const intType1 *  coords,
const intType2 *  maxCoords,
int  dim 
)
inline

Generates an underscore-separated list of non-negative coordinates padded with zeros to the same width assuming that their values are below the given limits.

Definition at line 386 of file utils.h.

References countDigits().

Referenced by Coordinator::Accept(), coord2str(), Coordinator::Prepare(), and Worker::Process().

◆ countDigits()

template<class intType >
int countDigits ( intType  x)
inline

Returns the number of digits of the given non-negative integer number.

Definition at line 366 of file utils.h.

Referenced by coord2str().

◆ cropRanges()

template<class CoordType >
void cropRanges ( CoordType *  left,
CoordType *  right,
int  dim,
int  intwidth,
bool  throwIfCropped,
bool &  cropped 
)
inline

Crops the ranges, marks this fact if it occurred, and throws an exception if requested to.

Definition at line 724 of file utils.h.

Referenced by MapComputation< mapcomp, cubetype, cubsettype >::operator()(), and MapComputationTight< mapcomp, cubetype, cubsettype >::operator()().

◆ cubesVolume()

double cubesVolume ( int_t  nCubes,
int  subdiv 
)
inline

Returns the volume of the given number of cubes in the phase space at the provided subdivision level.

Definition at line 712 of file utils.h.

References custom::difference::spaceDim, and custom::difference::spaceWidth.

Referenced by invMorseDec().

◆ double2string()

std::string double2string ( const double &  x,
int  precision 
)
inline

Creates a text representation of a floating-point number at the prescribed precision.

Definition at line 958 of file utils.h.

Referenced by computeMorseDecomposition().

◆ embedCubes()

template<class typeCubes >
void embedCubes ( const typeCubes &  X,
typeCubes &  result 
)

Embeds a set of cubes to another set of cubes with respect to twice coarser grid.

Definition at line 644 of file utils.h.

◆ enhanceCubes()

void enhanceCubes ( spcCubes X,
int  enhanceTimes,
int  subdivDepth 
)
inline

Enhances the given set of cubes provided number of times.

Definition at line 666 of file utils.h.

Referenced by computeMorseDecomposition().

◆ fileExists()

bool fileExists ( const char *  filename)
inline

Returns 'true' iff the given file exists and it is allowed to read it.

Definition at line 69 of file utils.h.

Referenced by Coordinator::Accept(), computeMorseDecomposition(), invMorseDec(), Coordinator::Prepare(), and Worker::Process().

◆ fileNameWithoutExt()

std::string fileNameWithoutExt ( const std::string &  fileName)
inline

Returns the file name without its extension if any.

If the file didn't have any extension, returns the original file name.

Definition at line 82 of file utils.h.

◆ internalBoundaryPoint()

template<class intType1 , class intType2 , class intType3 >
bool internalBoundaryPoint ( const intType1 *  coord,
const intType2 *  left,
const intType2 *  right,
const intType3 *  limit,
int  dim 
)
inline

Verifies whether the given box is located at the boundary of the small region which is either not at the boundary of the large region, or is adjacent to some other similar region.

Definition at line 137 of file utils.h.

Referenced by Worker::Process().

◆ intersectionVolume()

template<class CoordType , class IntervalType >
double intersectionVolume ( const CoordType *  c,
const IntervalType intervalBox,
int  dim 
)
inline

Computes the volume of the intersection of the unitary cube with the provided coordinates with the given product of intervals.

Definition at line 844 of file utils.h.

Referenced by MapComputation< mapcomp, cubetype, cubsettype >::operator()().

◆ moveSomeToFront()

template<class HashSetType >
void moveSomeToFront ( HashSetType &  X,
int_t  step 
)
inline

Replaces the hashed set of objects with another one that contains the same objects, but some of the objects are moved selectively to the front, taking the suggested step size in going through the initial hashed set.

The hashed set must have the property that adding an element to it several times causes this element to be added only once. Note: The step should be a (small) number N such that groups of N consecutive objects are clustered together, and the purpose of this procedure is to take representatives of these clusters to the front of the hashed set.

Definition at line 801 of file utils.h.

Referenced by computeMorseDecomposition().

◆ objectInArray()

template<class ObjectType , class ArrayType >
bool objectInArray ( const ObjectType &  theObject,
const ArrayType &  theArray,
int_t  arraySize 
)
inline

Checks if the given object is in the array of the given size.

Returns true if yes, false otherwise.

Definition at line 779 of file utils.h.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
const CoordMinMax range 
)
inline

Outputs the ranges of coordinates to an output stream.

In case the ranges are undefined, outputs "[unknown]".

Definition at line 524 of file utils.h.

References custom::difference::spaceDim.

◆ showProgress()

void showProgress ( int  n,
char  c 
)
inline

Shows a progress indicator to the screen as an integer number followed by an additional character (e.g.

'k').

Definition at line 974 of file utils.h.

Referenced by custom::procRecurrence::computeRecurrence().

◆ showRealCoords()

template<class OutStream >
OutStream & showRealCoords ( OutStream &  out,
const CoordMinMax range 
)
inline

Shows the real coordinates of the coordinate range.

Definition at line 543 of file utils.h.

References custom::difference::finalDepth, custom::difference::spaceDim, custom::difference::spaceOffset, and custom::difference::spaceWidth.

Referenced by invMorseDec(), Coordinator::Prepare(), and runSingleComp().

◆ subdivideCube()

template<class typeCube , class typeCubes >
void subdivideCube ( const typeCube &  q,
typeCubes &  result 
)

Subdivides a cube to a set of cubes with respect to twice finer grid.

Definition at line 620 of file utils.h.

◆ subdivideCubes()

template<class typeCubes >
void subdivideCubes ( const typeCubes &  X,
typeCubes &  result 
)

Subdivides one set of cubes to another set of cubes with respect to twice finer grid.

Definition at line 590 of file utils.h.

Referenced by checkEmptyInv(), computeConleyIndex(), computeMorseDecomposition(), and matchMorseSets().

◆ subRectangles()

parRect * subRectangles ( parCoord zeroIter,
parCoord maxIter,
std::vector< parCoord > *  subCoords,
int  minCount 
)
inline

Determines heuristically an optimal subdivision of a large parameter region into the given minimal number of smaller regions.

Fills in the provided array of vectors with the division coordinates. Allocates a rectangle for iterating this region and returns its pointer. Note: The rectangle is built upon the two arrays provided; they should not be deleted or otherwise the pointers stored within the rectangle become invalid.

Definition at line 213 of file utils.h.

References custom::difference::paramDim, and custom::difference::paramSubdiv.

Referenced by Coordinator::Coordinator().