00001 ///////////////////////////////////////////////////////////////////////////// 00002 /// 00003 /// @file attractor.h 00004 /// 00005 /// Construction of a cover of an attractor. 00006 /// This file contains the definition of a function that constructs 00007 /// a cover of an attractor for a given dynamical system, and computes 00008 /// a directed graph representation of the dynamics on this cover. 00009 /// 00010 /// @author Pawel Pilarczyk 00011 /// 00012 ///////////////////////////////////////////////////////////////////////////// 00013 00014 // Copyright (C) 1997-2010 by Pawel Pilarczyk. 00015 // 00016 // This file is part of my research software package. This is free software; 00017 // you can redistribute it and/or modify it under the terms of the GNU 00018 // General Public License as published by the Free Software Foundation; 00019 // either version 2 of the License, or (at your option) any later version. 00020 // 00021 // This software is distributed in the hope that it will be useful, 00022 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 // GNU General Public License for more details. 00025 // 00026 // You should have received a copy of the GNU General Public License along 00027 // with this software; see the file "license.txt". If not, write to the 00028 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00029 // MA 02111-1307, USA. 00030 00031 // Started on March 13, 2009. Last revision: June 18, 2009. 00032 00033 00034 #ifndef _FINRESDYN_ATTRACTOR_H_ 00035 #define _FINRESDYN_ATTRACTOR_H_ 00036 00037 00038 // include some standard C++ header files 00039 #include <iostream> 00040 #include <memory> 00041 #include <cmath> 00042 00043 // include local header files 00044 #include "graph.h" 00045 #include "streams.h" 00046 #include "rounding.h" 00047 00048 00049 // -------------------------------------------------- 00050 // ------------------- edge adder ------------------- 00051 // -------------------------------------------------- 00052 00053 /// Auxiliary class for adding edges to a graph. 00054 template <class GraphType> 00055 class EdgeAdder 00056 { 00057 public: 00058 /// The only allowed constructor of an edge adder object. 00059 EdgeAdder (GraphType &graph): g (graph) {} 00060 00061 /// Adds an edge to the graph. 00062 void add (int edge) {g. addEdge (edge); return;} 00063 00064 private: 00065 /// A reference to the graph to which the vertices 00066 /// are to be added. 00067 GraphType &g; 00068 00069 }; /* class EdgeAdder */ 00070 00071 00072 // -------------------------------------------------- 00073 // ------------------- diameter2 -------------------- 00074 // -------------------------------------------------- 00075 00076 /// Computes an upper bound for the square of the diameter of a given box. 00077 template <class NumType> 00078 inline NumType diameter2 (const int dim, 00079 const NumType *leftBounds, const NumType *rightBounds) 00080 { 00081 NumType squares = 0; 00082 for (int i = 0; i < dim; ++ i) 00083 { 00084 NumType diff = tRounding<NumType>::sub_up 00085 (rightBounds [i], leftBounds [i]); 00086 NumType diff2 = tRounding<NumType>::mul_up (diff, diff); 00087 squares = tRounding<NumType>::add_up (squares, diff2); 00088 } 00089 return squares; 00090 } /* diameter2 */ 00091 00092 00093 // -------------------------------------------------- 00094 // ------------------- attractor -------------------- 00095 // -------------------------------------------------- 00096 00097 /// Constructs a cover of an attractor for a given dynamical system. 00098 /// Returns an upper bound for the square of the diameter of map images. 00099 /// Throws an exception in case of failure. 00100 template <class MapType, class CoverType, class GraphType, class NumArray> 00101 inline double constructAttractor (const MapType &function, CoverType &cover, 00102 GraphType &graph, NumArray initialPoint, int iterCount, 00103 int maxCoverSize) 00104 { 00105 // determine the type of numbers and the space dimension 00106 typedef typename CoverType::NumberType NumType; 00107 int dim = cover. dim (); 00108 00109 // create an initial point close to the attractor and cover it 00110 std::auto_ptr<NumType> xPtr (new NumType [dim]); 00111 NumType *x = xPtr. get (); 00112 for (int i = 0; i < dim; ++ i) 00113 x [i] = initialPoint [i]; 00114 function. initialPoint (x, iterCount); 00115 cover. cover (x); 00116 00117 // prepare various objects to be used during the computations 00118 EdgeAdder <GraphType> edgeAdder (graph); 00119 std::auto_ptr<NumType> yPtr (new NumType [dim << 1]); 00120 NumType *leftBounds = yPtr. get (); 00121 NumType *rightBounds = leftBounds + dim; 00122 NumType *leftImage = leftBounds; 00123 NumType *rightImage = rightBounds; 00124 NumType maxDiameter2 = 0; 00125 00126 // compute the images of the points until the entire attractor 00127 // has been covered 00128 int current = 0; 00129 while (current < cover. size ()) 00130 { 00131 // add a vertex corresponding to this cover element 00132 graph. addVertex (); 00133 00134 // get a box which covers the given element of the cover 00135 cover. get (current, leftBounds, rightBounds); 00136 00137 // compute a rectangular cover of the image of this box 00138 function. image (leftBounds, rightBounds, 00139 leftImage, rightImage); 00140 00141 // cover the computed box with elements of the cover 00142 NumType diam2; 00143 cover. cover (leftImage, rightImage, edgeAdder, &diam2); 00144 00145 // update the maximal square of the diameter of images 00146 if (maxDiameter2 < diam2) 00147 maxDiameter2 = diam2; 00148 00149 // interrupt if the cover has become too large 00150 if ((maxCoverSize > 0) && (cover. size () > maxCoverSize)) 00151 throw "Maximal allowed cover size exceeded."; 00152 00153 // take the next element of the cover into consideration 00154 ++ current; 00155 00156 // show progress indicator 00157 if (!(current % 1371)) 00158 { 00159 scon << std::setw (10) << cover. size () << 00160 "\b\b\b\b\b\b\b\b\b\b"; 00161 } 00162 } 00163 00164 return static_cast<double> (maxDiameter2); 00165 } /* constructAttractor */ 00166 00167 00168 #endif // _FINRESDYN_ATTRACTOR_H_ 00169
1.5.3