The Finite Resolution Dynamics Software
attractor.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// @file attractor.h
4 ///
5 /// Construction of a cover of an attractor.
6 /// This file contains the definition of a function that constructs
7 /// a cover of an attractor for a given dynamical system, and computes
8 /// a directed graph representation of the dynamics on this cover.
9 ///
10 /// @author Pawel Pilarczyk
11 ///
12 /////////////////////////////////////////////////////////////////////////////
13 
14 // Copyright (C) 1997-2010 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 2 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 along
27 // with this software; see the file "license.txt". If not, write to the
28 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 // MA 02111-1307, USA.
30 
31 // Started on March 13, 2009. Last revision: June 18, 2009.
32 
33 
34 #ifndef _FINRESDYN_ATTRACTOR_H_
35 #define _FINRESDYN_ATTRACTOR_H_
36 
37 
38 // include some standard C++ header files
39 #include <iostream>
40 #include <memory>
41 #include <cmath>
42 
43 // include local header files
44 #include "graph.h"
45 #include "streams.h"
46 #include "rounding.h"
47 
48 
49 // --------------------------------------------------
50 // ------------------- edge adder -------------------
51 // --------------------------------------------------
52 
53 /// Auxiliary class for adding edges to a graph.
54 template <class GraphType>
55 class EdgeAdder
56 {
57 public:
58  /// The only allowed constructor of an edge adder object.
59  EdgeAdder (GraphType &graph): g (graph) {}
60 
61  /// Adds an edge to the graph.
62  void add (int edge) {g. addEdge (edge); return;}
63 
64 private:
65  /// A reference to the graph to which the vertices
66  /// are to be added.
67  GraphType &g;
68 
69 }; /* class EdgeAdder */
70 
71 
72 // --------------------------------------------------
73 // ------------------- diameter2 --------------------
74 // --------------------------------------------------
75 
76 /// Computes an upper bound for the square of the diameter of a given box.
77 template <class NumType>
78 inline NumType diameter2 (const int dim,
79  const NumType *leftBounds, const NumType *rightBounds)
80 {
81  NumType squares = 0;
82  for (int i = 0; i < dim; ++ i)
83  {
84  NumType diff = tRounding<NumType>::sub_up
85  (rightBounds [i], leftBounds [i]);
86  NumType diff2 = tRounding<NumType>::mul_up (diff, diff);
87  squares = tRounding<NumType>::add_up (squares, diff2);
88  }
89  return squares;
90 } /* diameter2 */
91 
92 
93 // --------------------------------------------------
94 // ------------------- attractor --------------------
95 // --------------------------------------------------
96 
97 /// Constructs a cover of an attractor for a given dynamical system.
98 /// Returns an upper bound for the square of the diameter of map images.
99 /// Throws an exception in case of failure.
100 template <class MapType, class CoverType, class GraphType, class NumArray>
101 inline double constructAttractor (const MapType &function, CoverType &cover,
102  GraphType &graph, NumArray initialPoint, int iterCount,
103  int maxCoverSize)
104 {
105  // determine the type of numbers and the space dimension
106  typedef typename CoverType::NumberType NumType;
107  int dim = cover. dim ();
108 
109  // create an initial point close to the attractor and cover it
110  std::auto_ptr<NumType> xPtr (new NumType [dim]);
111  NumType *x = xPtr. get ();
112  for (int i = 0; i < dim; ++ i)
113  x [i] = initialPoint [i];
114  function. initialPoint (x, iterCount);
115  cover. cover (x);
116 
117  // prepare various objects to be used during the computations
118  EdgeAdder <GraphType> edgeAdder (graph);
119  std::auto_ptr<NumType> yPtr (new NumType [dim << 1]);
120  NumType *leftBounds = yPtr. get ();
121  NumType *rightBounds = leftBounds + dim;
122  NumType *leftImage = leftBounds;
123  NumType *rightImage = rightBounds;
124  NumType maxDiameter2 = 0;
125 
126  // compute the images of the points until the entire attractor
127  // has been covered
128  int current = 0;
129  while (current < cover. size ())
130  {
131  // add a vertex corresponding to this cover element
132  graph. addVertex ();
133 
134  // get a box which covers the given element of the cover
135  cover. get (current, leftBounds, rightBounds);
136 
137  // compute a rectangular cover of the image of this box
138  function. image (leftBounds, rightBounds,
139  leftImage, rightImage);
140 
141  // cover the computed box with elements of the cover
142  NumType diam2;
143  cover. cover (leftImage, rightImage, edgeAdder, &diam2);
144 
145  // update the maximal square of the diameter of images
146  if (maxDiameter2 < diam2)
147  maxDiameter2 = diam2;
148 
149  // interrupt if the cover has become too large
150  if ((maxCoverSize > 0) && (cover. size () > maxCoverSize))
151  throw "Maximal allowed cover size exceeded.";
152 
153  // take the next element of the cover into consideration
154  ++ current;
155 
156  // show progress indicator
157  if (!(current % 1371))
158  {
159  scon << std::setw (10) << cover. size () <<
160  "\b\b\b\b\b\b\b\b\b\b";
161  }
162  }
163 
164  return static_cast<double> (maxDiameter2);
165 } /* constructAttractor */
166 
167 
168 #endif // _FINRESDYN_ATTRACTOR_H_
169 
Various output streams for the program.
Rigorous rounding of arithmetic operations.
A class for rounding operations which uses the BOOST library.
Definition: rounding.h:48
NumType diameter2(const int dim, const NumType *leftBounds, const NumType *rightBounds)
Computes an upper bound for the square of the diameter of a given box.
Definition: attractor.h:78
void add(int edge)
Adds an edge to the graph.
Definition: attractor.h:62
EdgeAdder(GraphType &graph)
The only allowed constructor of an edge adder object.
Definition: attractor.h:59
A directed graph class and some algorithms.
GraphType & g
A reference to the graph to which the vertices are to be added.
Definition: attractor.h:67
Auxiliary class for adding edges to a graph.
Definition: attractor.h:55
double constructAttractor(const MapType &function, CoverType &cover, GraphType &graph, NumArray initialPoint, int iterCount, int maxCoverSize)
Constructs a cover of an attractor for a given dynamical system.
Definition: attractor.h:101