The Conley-Morse Graphs Software
mapgraph.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file mapgraph.h
4///
5/// Computation of the graph representation of a combinatorial map.
6/// This file contains the definition of a function for the computation
7/// of a directed graph which represents a combinatorial map
8/// restricted to a given set of cubes.
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 February 12, 2007. Last revision: October 9, 2022.
31
32
33#ifndef _CMGRAPHS_MAPGRAPH_H_
34#define _CMGRAPHS_MAPGRAPH_H_
35
36
37// include selected header files from the CHomP library
38#include "chomp/system/textfile.h"
39#include "chomp/cubes/pointset.h"
40#include "chomp/cubes/cube.h"
41
42// include local header files
43#include "config.h"
44#include "typedefs.h"
45#include "typedyns.h"
46#include "utils.h"
47#include "spacewrap.h"
48
49
50// --------------------------------------------------
51// -------------- compute cubical map ---------------
52// --------------------------------------------------
53
54/// Computes the cubical map on 'X' and fills out the graph 'g'.
55template <class typeCubes, class typeGraph, class typeCubMap>
56inline void computeMapGraph (const typeCubes &X, typeGraph &g,
57 const typeCubMap &theCubMap, bool cropping = true)
58{
59 // set space wrapping if necessary
60 localSpaceWrapping wrapping (theCubMap. intWidth ());
61
62 // remember the previous cropping settings and set the new ones
63 local_value<bool> local_cropping (theCubMap. cropping,
64 cropping ? true : theCubMap. cropping);
65 local_value<bool> local_cropped (theCubMap. cropped,
66 theCubMap. cropped);
67
68 // compute the images of all the cubes
69 int_t nX = X. size ();
70 for (int_t cur = 0; cur < nX; ++ cur)
71 {
72 // add a vertex to the graph that corresponds to the cube
73 g. addVertex ();
74
75 // compute the image of the cube
76 theCubMap (X [cur], 0, &g, &X, 0, false);
77
78 // show progress indicator if necessary
79 if (cur && !(cur % ((spaceDim >= 3) ? 1000 : 10000)))
80 {
81 chomp::homology::scon << std::setw (8) <<
82 (cur / 1000) << "k\b\b\b\b\b\b\b\b\b";
83 }
84 }
85
86 return;
87} /* computeMapGraph */
88
89#ifdef CONFIG_ODEVART
90/// Computes the cubical map on 'X' and fills out the graph 'g'.
91/// Increases 'X' to an isolating neighborhood as much as possible
92/// within the phase space.
93/// A positive upper bound on the number of elements that can be added
94/// must be given, and should not be extremely large (e.g. 10000 might be
95/// a good choice).
96template <class typeCubes, class typeGraph, class typeCubMap>
97inline void computeMapGraphIsol (const typeCubes &X, typeGraph &g,
98 const typeCubMap &theCubMap, typeCubes &Xadd, int_t maxAdd)
99{
100 using chomp::homology::sbug;
101
102 // make sure that the max add limit is non-negative
103 if (maxAdd < Xadd. size ())
104 maxAdd = Xadd. size ();
105
106 // set space wrapping if necessary
107 localSpaceWrapping wrapping (theCubMap. intWidth ());
108
109 // remember the previous cropping settings and set the new ones
110 local_value<bool> local_cropping (theCubMap. cropping, true);
111 local_value<bool> local_cropped (theCubMap. cropped, false);
112
113 // compute the images of all the cubes in X and construct Xexit
114 spcCubes Xexit;
115 int_t nX = X. size ();
116 for (int_t cur = 0; cur < nX; ++ cur)
117 {
118 // add a vertex to the graph that corresponds to the cube
119 g. addVertex ();
120
121 // compute the image of the cube (without restrictions,
122 // with just cropping to the phase space)
123 spcCubes img;
124 theCubMap (X [cur], &img, 0, 0, 0, false);
125
126 // add cubes to Xexit if necessary
127 // and add corresponding edges to the graph
128 int_t nImg (img. size ());
129 for (int_t i = 0; i < nImg; ++ i)
130 {
131 const spcCube &q (img [i]);
132 int_t n (X. getnumber (q));
133 if (n >= 0)
134 {
135 g. addEdge (n);
136 }
137 else
138 {
139 n = Xexit. add (q);
140 g. addEdge (nX + maxAdd + n);
141 }
142 }
143
144 // show progress indicator if necessary
145 if (cur && !(cur % ((spaceDim >= 3) ? 1000 : 10000)))
146 {
147 chomp::homology::scon << std::setw (8) <<
148 (cur / 1000) << "k\b\b\b\b\b\b\b\b\b";
149 }
150 }
151 if (theCubMap. cropped)
152 {
153 sbug << "(cropped) ";
154 theCubMap. cropped = false;
155 }
156 sbug << "(XexitBegin " << Xexit. size () << ") ";
157
158 // compute the images of all the cubes in Xexit and move those cubes
159 // to X whose images intersect X
160 chomp::homology::hashedset<int_t> addNumbers;
161 bool modified = false;
162 int_t processed = nX;
163 do
164 {
165 modified = false;
166 for (int_t cur = 0; cur < Xexit. size (); ++ cur)
167 {
168 // skip the cube if it is already in Xadd
169 if (addNumbers. check (nX + maxAdd + cur))
170 continue;
171
172 // show progress indicator if necessary
173 ++ processed;
174 if ((spaceDim >= 3) && !(processed % 1000))
175 {
176 chomp::homology::scon << std::setw (8) <<
177 (processed / 1000) <<
178 "k\b\b\b\b\b\b\b\b\b";
179 }
180
181 // compute the image of the cube
182 // (cropped to the phase space)
183 spcCubes img;
184 theCubMap (Xexit [cur], &img, 0, 0, 0, false);
185
186 // check if the image intersects X or Xadd
187 bool intersects = false;
188 int_t nImg (img. size ());
189 for (int_t i = 0; i < nImg; ++ i)
190 {
191 const spcCube &q (img [i]);
192 if (X. check (q) || Xadd. check (q))
193 {
194 intersects = true;
195 break;
196 }
197 }
198
199 // if the image does not intersect X nor Xadd
200 // then nothing more needs to be done
201 if (!intersects)
202 continue;
203
204 // if intersets then schedule the cube to be
205 // added to X, add the cubes in its image to Xexit,
206 // and add the corresponding edges to the graph
207 if (Xadd. size () >= maxAdd)
208 throw "Too many cubes must be added to X.";
209 modified = true;
210 Xadd. add (Xexit [cur]);
211 addNumbers. add (nX + maxAdd + cur);
212 g. addVertex ();
213 for (int_t i = 0; i < nImg; ++ i)
214 {
215 const spcCube &q (img [i]);
216 int_t n (X. getnumber (q));
217 if (n >= 0)
218 {
219 g. addEdge (n);
220 continue;
221 }
222 n = Xadd. getnumber (q);
223 if (n >= 0)
224 {
225 g. addEdge (nX + n);
226 continue;
227 }
228 n = Xexit. add (q);
229 g. addEdge (nX + maxAdd + n);
230 }
231 }
232 } while (modified);
233
234 sbug << "(XexitEnd " << Xexit. size () << ") ";
235 sbug << "(" << g. countVertices () << "v," <<
236 g. countEdges () << "e) ";
237 if (!Xadd. empty ())
238 sbug << "(Xadd " << Xadd. size () << ") ";
239
240 // correct the outgoing edges in the graph 'g':
241 // change the numbers corresponding to Xadd and eliminate
242 // those corresponding to the remainder of Xexit
243 typeGraph h;
244 int_t XsizeNew (X. size () + Xadd. size ());
245 for (int_t v = 0; v < XsizeNew; ++ v)
246 {
247 h. addVertex ();
248 for (int_t e = 0; e < g. countEdges (v); ++ e)
249 {
250 int_t w (g. getEdge (v, e));
251 if (w < XsizeNew)
252 {
253 h. addEdge (w);
254 }
255 else
256 {
257 int_t pos (addNumbers. getnumber (w));
258 if (pos >= 0)
259 h. addEdge (nX + pos);
260 }
261 }
262 }
263 g. swap (h);
264
265 sbug << "(" << g. countVertices () << "v," <<
266 g. countEdges () << "e) ";
267
268 return;
269} /* computeMapGraphIsol */
270#endif // CONFIG_ODEVART
271
272
273#endif // _CMGRAPHS_MAPGRAPH_H_
274
275
Initializes the given variable with the value provided and restores the previous value at the end of ...
Definition: utils.h:109
Sets space wrapping locally.
Definition: spacewrap.h:82
Choice of configuration settings.
void computeMapGraph(const typeCubes &X, typeGraph &g, const typeCubMap &theCubMap, bool cropping=true)
Computes the cubical map on 'X' and fills out the graph 'g'.
Definition: mapgraph.h:56
const int spaceDim
The dimension of the phase space.
Definition: p_differ.h:48
Helper functions and an auxiliary class for space wrapping.
Customizable data types for the Conley-Morse graphs computation program.
Data types for the dynamical systems data structures.
chomp::homology::hashedset< spcCube > spcCubes
The type of a set of cubes in the phase space.
Definition: typespace.h:58
chomp::homology::tCubeBase< spcCoord > spcCube
The type of a cube in the phase space.
Definition: typespace.h:55
Utilites and helper functions.