00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <exception>
00042 #include <sstream>
00043 #include <fstream>
00044 #include <algorithm>
00045 #include <new>
00046
00047
00048 #include "chomp/system/config.h"
00049 #include "chomp/system/textfile.h"
00050 #include "chomp/system/timeused.h"
00051 #include "chomp/system/arg.h"
00052
00053
00054 #include "config.h"
00055 #include "confinfo.h"
00056 #include "typedefs.h"
00057 #include "utils.h"
00058 #include "compmdec.h"
00059 #include "plotmdec.h"
00060 #include "eigenval.h"
00061 #include "dotgraph.h"
00062
00063
00064
00065
00066
00067
00068
00069
00070 const char *title = "\
00071 This is a program which computes a single Conley-Morse graph.\n\
00072 Ver. 0.01, April 19, 2008. Copyright (C) 2005-2008 by Pawel Pilarczyk.\n\
00073 This is free software. No warranty. Consult 'license.txt' for details.";
00074
00075
00076
00077
00078 const char *helpinfo = "\
00079 This is the front-end program for the computation of a Conley-Morse graph\n\
00080 for a single parameter box. It is a supplementary program to 'cmgraphs',\n\
00081 and it capable of saving the results of all its computations to files.\n\
00082 The parameter box is identified by the integer coordinates of its minimal\n\
00083 vertex and corresponds to a box in the subdivision of the parameter area,\n\
00084 for example, if the entire parameter range [-1,1]x[-1,1] is divided into\n\
00085 20x20 boxes then '-b 0,19' corresponds to [-1.0,-0.9]x[0.9,1.0].\n\
00086 Command line arguments (the argument '-b' is mandatory):\n\
00087 -b x1,x2,...,xN - the integer coordinates of a parameter box to process,\n\
00088 -g file.txt - file name to save the text code for the Conley-Morse graph,\n\
00089 -s file.ind - file name to save/load cached Conley index information,\n\
00090 -p file.png - file name to save a PNG picture of the Morse decomposition,\n\
00091 -c prefix - prefix for file names to save Morse sets to as lists of boxes,\n\
00092 --conn - compute connecting orbits between Morse sets (memory-consuming),\n\
00093 --full - use the full range of the phase space to plot Morse sets,\n\
00094 --log filename - file name to save all the text output of the program to,\n\
00095 --quiet - suppress any output written to the terminal,\n\
00096 --debug - display additional information useful for debugging,\n\
00097 --help - make the program show this brief help information and exit.\n\
00098 For more information ask the author at http://www.pawelpilarczyk.com/.";
00099
00100
00101
00102
00103
00104
00105 int runSingeComp (const char *boxCoordinates,
00106 const char *graphName, const char *shareName,
00107 const char *phaseSpaceName, bool fullPhaseSpace,
00108 const char *cubesName, bool connOrbits, int skipIndices)
00109 {
00110 using chomp::homology::sout;
00111
00112
00113 std::ostringstream info;
00114 showConfigInfo (info, 0, 0);
00115 sout << "\n" << info. str () << "\n";
00116
00117
00118 theCubMapType::maxImgDiam = 0;
00119 theCubMapType::maxImgVol = 0;
00120
00121
00122 parCube paramBox;
00123 std::string boxCoordStr ("(" + std::string (boxCoordinates) + ")");
00124 std::istringstream boxCoordStream (boxCoordStr);
00125 boxCoordStream >> paramBox;
00126 sout << "Computing Morse decomposition for " << paramBox << ".\n";
00127
00128
00129 double offset [spaceDim];
00130 for (int i = 0; i < spaceDim; ++ i)
00131 offset [i] = spaceOffset [i];
00132 double width [spaceDim];
00133 for (int i = 0; i < spaceDim; ++ i)
00134 width [i] = spaceWidth [i];
00135
00136
00137 parCoord curCoord [paramDim];
00138 paramBox. coord (curCoord);
00139
00140
00141 double leftMapParam [paramCount];
00142 double rightMapParam [paramCount];
00143 computeParam (curCoord, leftMapParam, rightMapParam);
00144 sout << "Parameter values:";
00145 for (int i = 0; i < paramCount; ++ i)
00146 {
00147 sout << " [" << leftMapParam [i] << "," <<
00148 rightMapParam [i] << "]";
00149 }
00150 sout << "\n";
00151
00152
00153 theMapType theMap;
00154 theMap. setParam (leftMapParam, rightMapParam, paramCount);
00155
00156
00157
00158
00159 theCubMapType theCubMap0 (offset, width, 1 << finalDepth, theMap);
00160 theCubMap0. cache = true;
00161 theCubMapType theCubMap1 (offset, width, 1 << (finalDepth + 1),
00162 theMap);
00163 theCubMap1. cache = true;
00164
00165
00166
00167
00168 bool morseDecComputed (false);
00169
00170
00171 std::vector<int> wrongIndices;
00172
00173
00174 std::vector<int> skippedIndices;
00175
00176
00177 std::vector<int> attractors;
00178
00179
00180 theMorseDecompositionType *morseDec = computeMorseDecomposition
00181 (theMap, theCubMap0, theCubMap1, offset, width, skipIndices,
00182 shareName ? shareName : "", morseDecComputed, wrongIndices,
00183 skippedIndices, attractors, connOrbits,
00184 leftMapParam, rightMapParam, paramCount);
00185
00186
00187 sout << "Max img diam = " << theCubMapType::maxImgDiam <<
00188 ", max img vol = " << theCubMapType::maxImgVol << ".\n";
00189
00190
00191 spcCoord coordLeftMin [spaceDim];
00192 spcCoord coordRightMax [spaceDim];
00193 for (int i = 0; i < spaceDim; ++ i)
00194 {
00195 coordLeftMin [i] = 1 << finalDepth;
00196 coordRightMax [i] = 0;
00197 }
00198 coordMinMax (*morseDec, coordLeftMin, coordRightMax);
00199
00200
00201 if ((spaceDim == 2) && phaseSpaceName && *phaseSpaceName)
00202 {
00203 sout << "Saving a picture of Morse sets to '" <<
00204 phaseSpaceName << "'...\n";
00205 plotMorseDecompositionPNG (*morseDec, phaseSpaceName,
00206 fullPhaseSpace ? (1 << finalDepth) : 0);
00207 }
00208
00209
00210 if (graphName && *graphName)
00211 {
00212
00213 chomp::homology::diGraph<> connGraph;
00214 morseDec -> makegraph (connGraph);
00215 chomp::homology::diGraph<> morseGraph;
00216 transitiveReduction (connGraph, morseGraph);
00217
00218
00219 int nSets = morseGraph. countVertices ();
00220 std::vector<int> sizes (nSets);
00221 for (int n = 0; n < nSets; ++ n)
00222 sizes [n] = (*morseDec) [n]. size ();
00223
00224
00225 std::vector<theConleyIndexType> indices (nSets);
00226 std::vector<IndexEigenValues> eigenValues (nSets);
00227 for (int n = 0; n < nSets; ++ n)
00228 {
00229 indices [n] = morseDec -> index (n);
00230 eigenValues [n] = IndexEigenValues (indices [n]);
00231 }
00232
00233 sout << "Saving the Conley-Morse graph to '" <<
00234 graphName << "'...\n";
00235 std::ofstream graphFile (graphName);
00236 writeDotGraph (graphFile, morseGraph, sizes,
00237 indices, eigenValues,
00238 wrongIndices, skippedIndices, attractors);
00239 graphFile << "\n";
00240 }
00241
00242
00243 if (cubesName && *cubesName)
00244 {
00245 sout << "Saving the Morse decomposition to '" <<
00246 cubesName << "*'...\n";
00247 morseDec -> savetofiles (cubesName);
00248 }
00249
00250 delete morseDec;
00251 return 0;
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261 int main (int argc, char *argv [])
00262 {
00263 using namespace chomp::homology;
00264
00265
00266 int skipIndices = 0;
00267 char *boxCoordinates = 0;
00268 char *graphName = 0;
00269 char *shareName = 0;
00270 char *phaseSpaceName = 0;
00271 char *cubesName = 0;
00272 bool fullPhaseSpace = false;
00273 bool connOrbits = false;
00274
00275
00276 arguments a;
00277 arg (a, "b", boxCoordinates);
00278 arg (a, "g", graphName);
00279 arg (a, "s", shareName);
00280 arg (a, "p", phaseSpaceName);
00281 arg (a, "c", cubesName);
00282 arg (a, "-skip-indices", skipIndices, 1);
00283 argswitch (a, "-full", fullPhaseSpace, true);
00284 argswitch (a, "-conn", connOrbits, true);
00285 arghelp (a);
00286
00287 argstreamprepare (a);
00288 int argresult = a. analyze (argc, argv);
00289 argstreamset ();
00290
00291
00292 if (!boxCoordinates)
00293 argresult = 1;
00294
00295
00296 if (argresult >= 0)
00297 sout << title << '\n';
00298
00299
00300 if (argresult < 0)
00301 {
00302 sout << "Call with '--help' for help.\n";
00303 return 2;
00304 }
00305
00306
00307 if (argresult > 0)
00308 {
00309 sout << helpinfo << '\n';
00310 return 1;
00311 }
00312
00313
00314 try
00315 {
00316
00317 program_time = "Aborted after:";
00318 program_time = 1;
00319
00320
00321 runSingeComp (boxCoordinates, graphName, shareName,
00322 phaseSpaceName, fullPhaseSpace, cubesName,
00323 connOrbits, skipIndices);
00324
00325
00326 program_time = "Total time used:";
00327
00328
00329 return 0;
00330 }
00331 catch (const char *msg)
00332 {
00333 sout << "ERROR: " << msg << '\n';
00334 return -1;
00335 }
00336 catch (const std::exception &e)
00337 {
00338 sout << "ERROR: " << e. what () << '\n';
00339 return -1;
00340 }
00341 catch (...)
00342 {
00343 sout << "ABORT: An unknown error occurred.\n";
00344 return -1;
00345 }
00346 }
00347