32#ifndef _CMGRAPHS_MAPCOMP_H_
33#define _CMGRAPHS_MAPCOMP_H_
44#include "chomp/system/textfile.h"
45#include "chomp/system/timeused.h"
46#include "chomp/struct/autoarray.h"
47#include "chomp/struct/digraph.h"
66template <
class mapcomp,
class cubetype,
67 class cubsettype = chomp::homology::hashedset<cubetype> >
88 int _intwidth,
int _subdivdepth,
102 chomp::homology::diGraph<> *g,
const cubsettype *codomain,
103 const cubsettype *
disjoint,
bool throwIfCropped)
const;
132 template <
class IntervalArray>
134 typename cubetype::CoordType *left,
135 typename cubetype::CoordType *right);
163 int compute (
const typename cubetype::CoordType *coord,
int dim,
164 typename cubetype::CoordType *left,
165 typename cubetype::CoordType *right,
182 mutable chomp::homology::multitable<cubetype>
leftcache;
188 mutable chomp::homology::multitable<IntervalType *>
imagecache;
202template <
class mapcomp,
class cubetype,
class cubsettype>
205template <
class mapcomp,
class cubetype,
class cubsettype>
208template <
class mapcomp,
class cubetype,
class cubsettype>
212template <
class mapcomp,
class cubetype,
class cubsettype>
218template <
class mapcomp,
class cubetype,
class cubsettype>
220 (
const double *_offset,
const double *_width,
221 int _intwidth,
int _subdivdepth,
const mapcomp &_M):
222 M (_M), cache (false), cropping (false), cropped (false),
223 offset (_offset), width (_width),
224 intwidth (_intwidth), subdivdepth (_subdivdepth),
225 cacheused (0), leftcache (8192), rightcache (8192)
231template <
class mapcomp,
class cubetype,
class cubsettype>
242 std::ofstream f (
"f.map");
243 for (int_t i = 0; i < computed. size (); ++ i)
245 typename cubetype::CoordType c [cubetype::MaxDim];
246 f <<
"[" << computed [i];
247 computed [i]. coord (c);
248 for (
int j = 0; j < computed [i]. dim (); ++ j)
250 f << cubetype (c, computed [i]. dim ()) <<
"] ";
251 f <<
"[" << leftcache [i] << rightcache [i] <<
"]\n";
256#ifdef CONFIG_IFRACTION
257 for (int_t i = 0; i < computed. size (); ++ i)
258 delete [] (imagecache [i]);
266template <
class mapcomp,
class cubetype,
class cubsettype>
267template <
class IntervalArray>
269 (
const IntervalArray &box,
int dim,
270 typename cubetype::CoordType *left,
271 typename cubetype::CoordType *right)
273 typedef typename cubetype::CoordType CoordType;
277 for (
int i = 0; i < dim; ++ i)
279 double left_b = box [i]. leftBound ();
280 left [i] =
static_cast<CoordType
> (left_b);
281 for (
int j = 0; (j < 4) && (left [i] >= left_b); ++ j)
283 if ((left [i] >= left_b) || (left_b - left [i] > 2))
285 throw "Interval enclosure: Left bound out of range.";
288 double right_b = box [i]. rightBound ();
289 right [i] =
static_cast<CoordType
> (right_b);
290 for (
int j = 0; (j < 4) && (right [i] <= right_b); ++ j)
292 if ((right [i] <= right_b) || (right [i] - right_b > 2))
294 throw "Interval enclosure: "
295 "Right bound out of range.";
301template <
class mapcomp,
class cubetype,
class cubsettype>
303 (
const typename cubetype::CoordType *coord,
int dim,
304 typename cubetype::CoordType *left,
305 typename cubetype::CoordType *right,
308 using chomp::homology::auto_array;
313 for (
int i = 0; i < dim; ++ i)
324 auto_array<IntervalType> yPtr
326 IntervalType *y = scaledImage ? scaledImage : yPtr. get ();
327 M (x, y, dim, coord, subdivdepth);
328 checkDistance (coord, dim, x, y);
334 using chomp::homology::slog;
335 slog <<
"Exp " << cubetype (coord, dim) <<
": (";
336 for (
int i = 0; i < dim; ++ i)
338 double expansion = (y [i]. rightBound () -
339 y [i]. leftBound ()) /
340 (x [i]. rightBound () - x [i]. leftBound ());
341 slog << (i ?
"," :
"") << expansion;
347 for (
int i = 0; i < dim; ++ i)
356 encloseIntervalInt (y, dim, left, right);
361template <
class mapcomp,
class cubetype,
class cubsettype>
363 (
const cubetype &q, cubsettype *img,
364 chomp::homology::diGraph<> *g,
const cubsettype *codomain,
365 const cubsettype *
disjoint,
bool throwIfCropped)
const
367 using chomp::homology::auto_array;
369 typedef typename cubetype::CoordType coordType;
373 auto_array<coordType> leftPtr (
new coordType [dim]);
374 coordType *left = leftPtr. get ();
375 auto_array<coordType> rightPtr (
new coordType [dim]);
376 coordType *right = rightPtr. get ();
379 int_t number = cache ? computed. getnumber (q) :
380 static_cast<int_t
> (-1);
383#ifdef CONFIG_IFRACTION
384 auto_array<IntervalType> scaledImagePtr (
new IntervalType [dim]);
397 compute (left, dim, left, right, scaledImage);
402 leftcache [computed. size ()] = cubetype (left, dim);
403 rightcache [computed. size ()] =
404 cubetype (right, dim);
405#ifdef CONFIG_IFRACTION
406 imagecache [computed. size ()] =
407 scaledImagePtr. release ();
417 leftcache [number]. coord (left);
418 rightcache [number]. coord (right);
419#ifdef CONFIG_IFRACTION
420 scaledImage = imagecache [number];
424 for (
int i = 0; i < dim; ++ i)
426 if (right [i] <= left [i])
427 right [i] += intwidth;
438 intwidth, throwIfCropped, cropped);
443 maxImgDiam, maxImgVol, maxImgDiamAllowed, maxImgVolAllowed);
451 if (codomain && (codomain -> size () < volume + 8))
454 auto_array<coordType> coordPtr (
new coordType [dim]);
455 coordType *c = coordPtr. get ();
456 int_t codomSize = codomain -> size ();
459 for (int_t i = 0; i < codomSize; ++ i)
462 const cubetype &q = (*codomain) [i];
467#ifdef CONFIG_IFRACTION
470 dim) < CONFIG_IFRACTION)
477 for (
int j = 0; j < dim; ++ j)
479 if ((c [j] < left [j]) ||
480 (c [j] >= right [j]))
500 chomp::homology::tRectangle<
typename
501 cubetype::CoordType> r (left, right, dim);
502 const typename cubetype::CoordType *c;
503 while ((c = r. get ()) != 0)
509 codomain -> getnumber (q) : -1;
512#ifdef CONFIG_IFRACTION
515 dim) < CONFIG_IFRACTION)
531 chomp::homology::tRectangle<typename cubetype::CoordType>
532 r (left, right, dim);
533 const typename cubetype::CoordType *c;
534 while ((c = r. get ()) != 0)
539#ifdef CONFIG_IFRACTION
542 dim) < CONFIG_IFRACTION)
554template <
class mapcomp,
class cubetype,
class cubsettype>
561template <
class mapcomp,
class cubetype,
class cubsettype>
568template <
class mapcomp,
class cubetype,
class cubsettype>
576template <
class mapcomp,
class cubetype,
class cubsettype>
578 (
int diameter,
int volume)
582 maxImgDiamAllowed = diameter;
583 maxImgVolAllowed = volume;
A generic map computation routine that computes a rigorous cubical multivalued map based on a functio...
static void setAllowedImgSize(int diameter, int volume)
Sets new (more or less restrictive) limits for the maximal allowed image diameter and volume.
bool cache
Using cache for the map.
bool cropping
Is cropping of images to the designated box in effect?
int_t cacheused
The number of times the cache was used successfully.
int subdivdepth
The binary subdivision depth.
const mapcomp & M
The map used to compute an interval enclosure of the image of an interval box.
int subdivDepth() const
Returns the subdivision depth at which the computations are done.
static void encloseIntervalInt(const IntervalArray &box, int dim, typename cubetype::CoordType *left, typename cubetype::CoordType *right)
A helper function that encloses an interval box in the interior of a box with integer coordinates.
MapDistance< cubetype, cubsettype > checkDistance
Map distance measuring object.
~MapComputation()
The destructor.
MapComputation(const double *_offset, const double *_width, int _intwidth, int _subdivdepth, const mapcomp &_M)
The default constructor.
chomp::homology::multitable< cubetype > leftcache
The cache left vertex.
const double * width
The width of the rectangle in each direction.
const double * offset
The offset of the cubical rectangle.
chomp::homology::multitable< IntervalType * > imagecache
The cached interval vectors for images.
chomp::homology::multitable< cubetype > rightcache
The cache right vertex.
void cleanCache() const
Cleans the cache of the cubical map, e.g., if the underlying interval map has changed.
static int maxImgDiam
The maximal image diameter encountered so far.
int intWidth() const
Returns the width of the phase space in terms of the number of boxes.
static int maxImgDiamAllowed
The maximal allowed image diameter.
mapcomp MapCompType
The type of the underlying interval map.
chomp::homology::diGraph GraphType
The type of the graph used in the computation of the image.
int intwidth
The width of the rectangle in terms of the number of cubes.
int compute(const typename cubetype::CoordType *coord, int dim, typename cubetype::CoordType *left, typename cubetype::CoordType *right, IntervalType *scaledImage) const
Use interval arithmetic to compute the coordinate scope.
static int maxImgVol
The maximal image volume encountered so far.
int operator()(const cubetype &q, cubsettype *img, chomp::homology::diGraph<> *g, const cubsettype *codomain, const cubsettype *disjoint, bool throwIfCropped) const
The operator for computing the image of a box as a set of boxes, as it is in a combinatorial cubical ...
bool cropped
Was the image cropped at least once? Reset this variable to "false" in order to detect image cropping...
static int maxImgVolAllowed
The maximal allowed image volume.
cubsettype computed
The cache domain.
The map distance change tracker.
Choice of configuration settings.
bool disjoint(const pointset &p, const pointset &q)
Map computation distance checker.
const int maxImageVolume
The maximal allowed volume of the cubical image of a single box.
const int maxImageDiameter
The maximal allowed diameter of the cubical image of a signle box.
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.
bool testIntervals(bool throwException=false)
Testing interval arithmetic.
capd::DInterval IntervalType
The type of an interval (from the CAPD library 2.9/3.0 beta).
Utilites and helper functions.
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 gi...
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.
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 vol...