The Conley-Morse Graphs Software
mapcomp_t.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file mapcomp_t.h
4///
5/// Map computation routines using tight enclosures (not necessarily
6/// products of intervals).
7/// This file contains the definition of routines for the computation
8/// of combinatorial cubical multivalued maps.
9///
10/// @author Pawel Pilarczyk
11///
12/////////////////////////////////////////////////////////////////////////////
13
14// Copyright (C) 1997-2014 by Pawel Pilarczyk.
15//
16// This file is part of my research software package. This is free software:
17// you can redistribute it and/or modify it under the terms of the GNU
18// General Public License as published by the Free Software Foundation,
19// either version 3 of the License, or (at your option) any later version.
20//
21// This software is distributed in the hope that it will be useful,
22// but WITHOUT ANY WARRANTY; without even the implied warranty of
23// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24// GNU General Public License for more details.
25//
26// You should have received a copy of the GNU General Public License
27// along with this software; see the file "license.txt". If not,
28// please, see <https://www.gnu.org/licenses/>.
29
30// Started on July 19, 2012. Last revision: May 18, 2013.
31
32
33#ifndef _CMGRAPHS_MAPCOMP_T_H_
34#define _CMGRAPHS_MAPCOMP_T_H_
35
36
37// include some standard C++ header files
38#include <iostream>
39#include <fstream>
40#include <algorithm>
41#include <memory>
42#include <new>
43
44// include selected header files from the CHomP library
45#include "chomp/system/textfile.h"
46#include "chomp/system/timeused.h"
47#include "chomp/struct/autoarray.h"
48#include "chomp/struct/digraph.h"
49
50// include local header files
51#include "config.h"
52#include "typedefs.h"
53#include "typeintv.h"
54#include "mapdist.h"
55#include "mapcomp.h"
56#include "coverrect.h"
57#include "utils.h"
58
59
60// --------------------------------------------------
61// -------------- MapComputationTight ---------------
62// --------------------------------------------------
63
64/// The generic map computation routine that computes a rigorous
65/// cubical multivalued map based on a function that computes the image
66/// of an interval vector as a rectangular set. The "mapcomp" class must
67/// have an appropriate method called "compute" which is used to compute
68/// the map in interval arithmetic.
69template <class mapcomp, class cubetype,
70 class cubsettype = chomp::homology::hashedset<cubetype> >
72 public MapComputation<mapcomp,cubetype,cubsettype>
73{
74public:
75 /// The default constructor.
76 MapComputationTight (const double *_offset, const double *_width,
77 int _intwidth, int _subdivdepth,
78 const mapcomp &_M = mapcomp ());
79
80 /// The operator for computing the image of a box as a set of boxes,
81 /// as it is in a combinatorial cubical multivalued map.
82 /// The image is restricted to the given codomain (if provided).
83 /// The integral coefficients of cubes are transformed to real
84 /// numbers according to the rectangular area defined by offset
85 /// from the origin and its width, as well as the width
86 /// of this area in terms of integral coordinates.
87 int operator () (const cubetype &q, cubsettype *img,
88 chomp::homology::diGraph<> *g, const cubsettype *codomain,
89 const cubsettype *disjoint, bool throwIfCropped) const;
90
91}; /* class MapComputationTight */
92
93// --------------------------------------------------
94
95template <class mapcomp, class cubetype, class cubsettype>
97 (const double *_offset, const double *_width,
98 int _intwidth, int _subdivdepth, const mapcomp &_M):
99 MapComputation<mapcomp,cubetype,cubsettype>
100 (_offset, _width, _intwidth, _subdivdepth, _M)
101{
102 return;
103} /* MapComputationTight::MapComputationTight */
104
105template <class mapcomp, class cubetype, class cubsettype>
107 (const cubetype &q, cubsettype *img,
108 chomp::homology::diGraph<> *g, const cubsettype *codomain,
109 const cubsettype *disjoint, bool throwIfCropped) const
110{
111 using chomp::homology::auto_array;
112
113 typedef typename cubetype::CoordType CoordType;
114
115 // prepare the coordinates of the input cube
116 auto_array<CoordType> coordPtr (new CoordType [spaceDim]);
117 CoordType *coord (coordPtr. get ());
118 q. coord (coord);
119
120 // prepare an interval vector that represents the input cube
122 for (int i = 0; i < spaceDim; ++ i)
123 {
124 x [i] = IntervalType (coord [i], coord [i] + 1);
125 x [i] /= this -> intwidth;
126 x [i] *= this -> width [i];
127 x [i] += this -> offset [i];
128 }
129 resetRounding ();
130
131 // compute the image of the cube in terms of a rectangular set
132 RectSetType rectSet (x, x); // dummy rect2set
133 this -> M. compute (x, rectSet, spaceDim, coord,
134 this -> subdivdepth);
135
136 // compute a product of intervals that bounds the rectangular set
137 IntervalVectorType boundingBox (rectSet);
138
139 // rescale the bounding box (towards the integer coordinates)
140 for (int i = 0; i < spaceDim; ++ i)
141 {
142 boundingBox [i] -= this -> offset [i];
143 boundingBox [i] /= this -> width [i];
144 boundingBox [i] *= this -> intwidth;
145 }
146 resetRounding ();
147
148 // prepare arrays for integer ranges of the image cubes
149 auto_array<CoordType> leftPtr (new CoordType [spaceDim]);
150 CoordType *left = leftPtr. get ();
151 auto_array<CoordType> rightPtr (new CoordType [spaceDim]);
152 CoordType *right = rightPtr. get ();
153
154 // compute integer ranges of the image cubes
155 this -> encloseIntervalInt (boundingBox, spaceDim, left, right);
156
157 // crop the image of this box to the given area if necessary
158 if (this -> cropping)
159 {
160 cropRanges (left, right, spaceDim, this -> intwidth,
161 throwIfCropped, this -> cropped);
162 }
163
164 // make sure that the size of the image is reasonably small
165 checkImageSize (left, right, spaceDim,
166 this -> maxImgDiam, this -> maxImgVol,
167 this -> maxImgDiamAllowed, this -> maxImgVolAllowed);
168
169 // prepare an array for integer widths of the phase space
170 auto_array<CoordType> intWidthPtr (new CoordType [spaceDim]);
171 CoordType *intWidth (intWidthPtr. get ());
172 for (int i = 0; i < spaceDim; ++ i)
173 intWidth [i] = this -> intwidth;
174
175 // prepare a variable for saving image cubes
176 bool usingImg = img && img -> empty ();
177 cubsettype localImg;
178 cubsettype &image (usingImg ? *img : localImg);
179
180 // cover the computed image in a tight way
181 coverRectSet (rectSet, this -> offset, this -> width, intWidth,
182 spaceDim, image, left, right, codomain, disjoint);
183
184 // add corresponding edges to the graph if necessary
185 if (g)
186 {
187 int_t imgSize = image. size ();
188 for (int_t i = 0; i < imgSize; ++ i)
189 {
190 const cubetype &qImg (image [i]);
191 int n = codomain -> getnumber (qImg);
192 if (n < 0)
193 throw "An edge to outside the codomain found.";
194 g -> addEdge (n);
195 }
196 }
197
198 // switch rounding mode back to the default one if necessary
199 resetRounding ();
200
201 return 0;
202} /* MapComputationTight::operator () */
203
204
205#endif // _CMGRAPHS_MAPCOMP_T_H_
206
A generic map computation routine that computes a rigorous cubical multivalued map based on a functio...
Definition: mapcomp.h:69
The generic map computation routine that computes a rigorous cubical multivalued map based on a funct...
Definition: mapcomp_t.h:73
MapComputationTight(const double *_offset, const double *_width, int _intwidth, int _subdivdepth, const mapcomp &_M=mapcomp())
The default constructor.
Definition: mapcomp_t.h:97
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 ...
Definition: mapcomp_t.h:107
Choice of configuration settings.
Covering a rotated rectangular set or a paralellepiped with cubes with respect to a fixed grid in R^n...
void coverRectSet(const RectSetType &rectSet, const DoubleArray1 &offset, const DoubleArray2 &width, const CoordType *intWidth, int dim, CubSetType &image, const CoordType *left, const CoordType *right, const CubSetType *codomain, const CubSetType *disjoint)
Covers a rectangular set by cubes with respect to a uniform subdivision of a rectangular area defined...
Definition: coverrect.h:91
bool disjoint(const pointset &p, const pointset &q)
Definition: psetjoin.cpp:139
Map computation routines.
Map computation distance checker.
const int spaceDim
The dimension of the phase space.
Definition: p_differ.h:48
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.
Definition: typeintv.h:65
capd::DInterval IntervalType
The type of an interval (from the CAPD library 2.9/3.0 beta).
Definition: typeintv.h:49
capd::C0HORect2Set RectSetType
The type of the rectangular set to use.
Definition: typerect.h:57
capd::IVector IntervalVectorType
The interval vector type for creating the rectangular set by means of its center + box.
Definition: typerect.h:63
Utilites and helper functions.
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.
Definition: utils.h:724
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...
Definition: utils.h:755