37#ifndef _CMGRAPHS_MAPDIST_H_
38#define _CMGRAPHS_MAPDIST_H_
51#include "chomp/system/textfile.h"
52#include "chomp/system/timeused.h"
53#include "chomp/homology/homology.h"
67template <
class cubetype,
68 class cubsettype = chomp::homology::hashedset<cubetype> >
96 mutable chomp::homology::multitable<cubsettype>
distCubes;
113 double &distMin,
double &distMax);
119template <
class cubetype,
class cubsettype>
124template <
class cubetype,
class cubsettype>
130template <
class cubetype,
class cubsettype>
133 if (!checkDistanceChanges)
136 int_t countCubes = 0;
137 int nSubspaces = countSubspaces (dim);
138 for (
int s = 0; s < nSubspaces; ++ s)
140 const char *changeFile [] =
142 const char *changeDesc [] =
143 {
"is closer to ",
"is farther from ",
144 "is neither closer to nor farther from "};
145 for (
int n = 0; n < 3; ++ n)
147 const cubsettype &cubes = distCubes [3 * s + n];
150 countCubes += cubes. size ();
151 std::ostringstream filename;
152 filename <<
"_" << number <<
"_" << s <<
153 changeFile [n] <<
".cub";
154 std::ofstream f (filename. str (). c_str ());
155 chomp::homology::sbug <<
"* Saving " <<
156 cubes. size () <<
" cubes to " <<
157 filename. str () <<
"... ";
158 f <<
"; Cubes whose image " << changeDesc [n] <<
159 " the subspace no. " << s <<
"\n"
160 "; in comparison to the distance of the "
161 " box itself from that subspace.\n";
163 chomp::homology::sbug <<
"Done.\n";
171template <
class cubetype,
class cubsettype>
177 int subspaces = (1 << dim) - dim - 1;
186template <
class cubetype,
class cubsettype>
188 const IntervalType *box,
int dim,
double &distMin,
double &distMax)
191 if ((subspace == 0) && (dim == 2))
197 xLeft = box [1]. leftBound ();
198 xRight = box [1]. rightBound ();
203 xLeft = boxDist. leftBound ();
204 xRight = boxDist. rightBound ();
206 double xLeftAbs = std::abs (xLeft);
207 double xRightAbs = std::abs (xRight);
208 distMax = std::max (xLeftAbs, xRightAbs);
209 if ((xLeft <= 0) && (xRight >= 0))
212 distMin = std::min (xLeftAbs, xRightAbs);
215 else if ((subspace == 3) && (dim == 3))
228 sqr (x - 2 * y + z) + sqr (x + y - 2 * z);
229 distMin = dist. leftBound ();
232 distMax = dist. rightBound ();
235 else if ((subspace == 4) && (dim == 3))
237 for (
int sub = 0; sub < dim; ++ sub)
241 distance (sub, box, dim, subMin, subMax);
242 if (!sub || (distMin > subMin))
244 if (!sub || (distMax < subMax))
252 int coord0 = (subspace > 0) ? 0 : 1;
253 int coord1 = (subspace < 2) ? 2 : 1;
255 double xLeft = boxDist. leftBound ();
256 double xRight = boxDist. rightBound ();
257 double xLeftAbs = std::abs (xLeft);
258 double xRightAbs = std::abs (xRight);
259 distMax = std::max (xLeftAbs, xRightAbs);
260 if ((xLeft <= 0) && (xRight >= 0))
263 distMin = std::min (xLeftAbs, xRightAbs);
268 throw "Distance measuring not implemented for the "
270 "Please, set 'checkDistanceChanges' in 'mapdist.h' "
271 "to 'false'\nand re-compile your program.";
278template <
class cubetype,
class cubsettype>
280 (
const typename cubetype::CoordType *coord,
int dim,
283 if (!checkDistanceChanges)
291 int nSubspaces = countSubspaces (dim);
292 for (
int s = 0; s < nSubspaces; ++ s)
297 distance (s, x, dim, xDistMin, xDistMax);
302 distance (s, y, dim, yDistMin, yDistMax);
305 if (xDistMin >= yDistMax)
307 distCubes [3 * s + 0]. add (cubetype (coord, dim));
310 else if (xDistMax <= yDistMin)
312 distCubes [3 * s + 1]. add (cubetype (coord, dim));
317 distCubes [3 * s + 2]. add (cubetype (coord, dim));
The map distance change tracker.
static const bool rotatedXY
Are the X and Y coordinates rotated? If so then the distance in this direction will be measured verti...
static const bool checkDistanceChanges
Should the distances be really checked? Please, set this to 'true' only if you know what you are doin...
void operator()(const typename cubetype::CoordType *coord, int dim, const IntervalType *x, const IntervalType *y) const
The operator for gathering the information on a given cube.
chomp::homology::multitable< cubsettype > distCubes
The sets of boxes with the distance checked: closer, farther, undetermined, for each hyperplane separ...
static int countSubspaces(int dim)
Computes the number of subspaces, depending on the dimension.
MapDistance()
The default constructor.
~MapDistance()
The destructor that saves all the collected information to files.
static void distance(int subspace, const IntervalType *box, int dim, double &distMin, double &distMax)
Computes the lower and upper bounds for the distance of the interval box from the given subspace.
int dim
The dimension of the phase space.
static int number
The consecutive number of sets for file naming purposes.
Choice of configuration settings.
Customizable data types for the Conley-Morse graphs computation program.
Data types for interval arithmetic.
void resetRounding()
This function resets rounding switches of the processor and sets rounding to the nearest.
capd::DInterval IntervalType
The type of an interval (from the CAPD library 2.9/3.0 beta).