32#ifndef _CMGRAPHS_WORKER_H_
33#define _CMGRAPHS_WORKER_H_
44#include "chomp/system/config.h"
45#include "chomp/system/textfile.h"
46#include "chomp/system/timeused.h"
47#include "chomp/cubes/cube.h"
48#include "chomp/multiwork/mw.h"
49#include "chomp/struct/digraph.h"
72class Worker:
public chomp::multiwork::mwWorker
76 Worker (
bool _local =
false);
83 int Initialize (chomp::multiwork::mwData &data);
86 int Process (chomp::multiwork::mwData &data);
121 using namespace chomp::homology;
127 " to decide to quit.\n";
137 return chomp::multiwork::mwOk;
142 using namespace chomp::homology;
143 using namespace chomp::multiwork;
149 " to receive data.\n";
154 timeused processingTime;
170 sout <<
"! Wrong parameter space dimension (" << dim <<
171 "). Rejecting the data.\n";
183 parLeft [i] =
static_cast<parCoord> (n);
185 parRight [i] =
static_cast<parCoord> (n);
193 std::string mapOptPrefix;
194 data >> mapOptPrefix;
197 std::string sharePrefix;
202 std::string phaseSpacePrefix;
203 data >> phaseSpacePrefix;
206 std::string cubesPrefix;
210 std::string morseDecPrefix;
211 data >> morseDecPrefix;
214 std::string graphsPrefix;
215 data >> graphsPrefix;
218 std::string procPrefix;
222 bool fullPhaseSpace (
false);
223 data >> fullPhaseSpace;
226 std::vector<std::vector<std::string> > mapOptHints;
235 sout <<
"! Data incomplete. Rejecting it.\n";
243 int prevVolume = volume;
244 volume *= parRight [i] - parLeft [i];
245 if (volume < prevVolume)
246 throw "Too many boxes for processing by a worker.";
252 sout <<
"Processing " << dataNumber <<
": " << volume <<
256 sout << (i ?
"x" :
"") <<
"[" << parLeft [i] <<
257 "," << parRight [i] <<
"]";
264 sout <<
"Processing " << dataNumber <<
": the box " <<
284 std::vector<theMapType *> theMap (volume);
285 std::vector<theCubMapType *> theCubMap0 (volume);
286 std::vector<theCubMapType *> theCubMap1 (volume);
287 std::vector<theMorseDecompositionType *> morseDec (volume);
288 std::vector<bool> morseDecComputed (volume,
false);
289 std::vector<double> timeUsed (volume, 0);
290 std::vector<std::vector<int> > wrongIndices (volume);
291 std::vector<std::vector<int> > skippedIndices (volume);
292 std::vector<std::vector<int> > attractors (volume);
296 int countWritten = 0;
297 int countComputed = 0;
300 while ((curCoord = rect. get ()) != 0)
303 chomp::homology::timeused stopwatch;
310 intBoundaryPoint =
true;
314 std::string pictureFileName = phaseSpacePrefix +
316 std::string morseDecFileName = morseDecPrefix. empty () ?
317 "" : (morseDecPrefix +
319 std::string graphFileName = graphsPrefix. empty () ?
322 std::string cacheFileName ((intBoundaryPoint &&
323 !sharePrefix. empty ()) ? (sharePrefix +
325 std::string cubesFilePrefix = cubesPrefix. empty () ?
"" :
328 std::string procFilePrefix = procPrefix. empty () ?
"" :
330 std::string mapOptFileName = mapOptPrefix. empty () ?
"" :
336 (cacheFileName. empty () ||
338 (phaseSpacePrefix. empty () ||
340 (morseDecPrefix. empty () ||
342 (graphsPrefix. empty () ||
346 if (cacheFileName. empty ())
347 sout <<
"No Conley index cache to compute. ";
348 else if (
fileExists (cacheFileName. c_str ()))
350 sout <<
"Conley index cache already exists. ";
353 if (phaseSpacePrefix. empty ())
354 sout <<
"No phase space picture to save. ";
355 else if (
fileExists (pictureFileName. c_str ()))
357 sout <<
"Phase space picture already exists. ";
360 if (morseDecPrefix. empty ())
361 sout <<
"No Morse decomp cache to save. ";
362 else if (
fileExists (morseDecFileName. c_str ()))
364 sout <<
"Morse decomp cache already exists. ";
367 else if (
fileExists (graphFileName. c_str ()))
369 sout <<
"C-M graph txt file already exists. ";
372#ifndef CONFIG_ONLYPREPROCESSING
374 sout <<
"Skipping the box, "
375 "because at least one file exists.\n";
377 sout <<
"Skipping the box, "
378 "because the result would be lost.\n";
383 sout <<
"Skipping the box.\n";
386 sout <<
"Processing the box anyway.\n";
391 int curNumber = paramBoxes. size ();
393 paramBoxes. add (paramBox);
394 if (paramBoxes. size () == curNumber)
395 throw "A repeated box found in the iterations.";
401 sbug <<
"Box " << paramBox <<
":";
404 sbug <<
" [" << leftMapParam [i] <<
"," <<
405 rightMapParam [i] <<
"]";
411 theMap [curNumber] -> setParam (leftMapParam, rightMapParam,
415 if (!mapOptHints [curNumber]. empty ())
418 mapOptHints [curNumber]. size () <<
419 " map optimization hints.\n";
420 for (std::vector<std::string>::const_iterator it =
421 mapOptHints [curNumber]. begin ();
422 it != mapOptHints [curNumber]. end (); ++ it)
424 theMap [curNumber] -> useOptInfo (*it);
433 theCubMap0 [curNumber] -> cache =
true;
436 *(theMap [curNumber]));
437 theCubMap1 [curNumber] -> cache =
true;
440 sbug <<
"Computing Morse decomposition for " <<
442 bool computed =
false;
444 (*(theMap [curNumber]),
445 *(theCubMap0 [curNumber]), *(theCubMap1 [curNumber]),
446 offset, width, skipIndices,
447 cacheFileName, pictureFileName, cubesFilePrefix,
448 morseDecFileName, graphFileName,
449 procFilePrefix, mapOptFileName,
450 computed, wrongIndices [curNumber],
451 skippedIndices [curNumber], attractors [curNumber],
452 false, leftMapParam, rightMapParam,
paramCount);
453 morseDecComputed [curNumber] = computed;
459 if (intBoundaryPoint)
466 int_t nMorseSets = morseDec [curNumber] -> count ();
467 for (int_t nSet = 0; nSet < nMorseSets; ++ nSet)
468 coordMinMax ((*(morseDec [curNumber])) [nSet]);
475 !phaseSpacePrefix. empty () &&
478 sbug <<
"Saving '" << pictureFileName <<
"'...\n";
482 const int xCoord (0);
487 const int yCoord (1);
490 pictureFileName. c_str (), xCoord, yCoord,
495 timeUsed [curNumber] = stopwatch;
498 sbug << timeUsed [curNumber] <<
" sec, " <<
499 ((curNumber + 1) * 100 / volume) <<
"% done.\n";
500 sbug <<
"--------------------------------\n";
506 sout << countRead <<
" sets of Conley indices read, " <<
507 countComputed <<
" computed (" <<
508 countWritten <<
" written).\n";
513 std::vector<std::vector<parCube> > matchClasses;
516 sbug <<
"Matching " << volume <<
517 " Morse decompositions...\n";
518 std::vector<std::vector<int> > noWrongIndices (volume);
523 wrongIndices, parLeft, parRight, matchClasses);
526 int nClasses = matchClasses. size ();
528 sbug <<
"There is only one nontrivial class";
531 sbug <<
"There are " << nClasses <<
532 " nontrivial classes";
534 sbug <<
" of equivalent Morse decompositions:\n";
537 for (
int n = 0; n < nClasses; ++ n)
538 sbug << (n ?
"+" :
"") << matchClasses [n]. size ();
539 sbug <<
" elements.\n";
551 data << static_cast<double> (processingTime);
554 data << wrongIndices;
557 data << skippedIndices;
567 int countBoxes = paramBoxes. size ();
571 for (
int curNumber = 0; curNumber < countBoxes; ++ curNumber)
574 data << paramBoxes [curNumber];
577 data << timeUsed [curNumber];
581 data << morseDecComputed [curNumber];
585 morseDec [curNumber] -> makegraph (connGraph);
586 diGraph<> morseGraph;
587 transitiveReduction (connGraph, morseGraph);
591 int nSets = morseDec [curNumber] -> count ();
592 for (
int n = 0; n < nSets; ++ n)
593 data << (*(morseDec [curNumber])) [n]. size ();
597 if (
static_cast<int_t
> (nSets) !=
598 morseGraph. countVertices ())
600 throw "Wrong number of Morse sets encountered.";
602 for (
int n = 0; n < nSets; ++ n)
605 morseDec [curNumber] -> index (n);
613 data << matchClasses;
620 std::vector<std::string> mapOptFinal;
621 for (
int i = 0; i < countBoxes; ++ i)
623 std::string line = theMap [i] -> getOptInfo ();
625 mapOptFinal. push_back (line);
630 for (
int i = 0; i < countBoxes; ++ i)
632 sbug <<
"Deleting the map for " << paramBoxes [i] <<
"...\n";
634 delete theCubMap1 [i];
635 delete theCubMap0 [i];
643 sbug <<
"(Resetting the pointset data.)\n";
644 parCube::PointBase::reset ();
645 spcCube::PointBase::reset ();
646 Cube::PointBase::reset ();
650 sout <<
"================================\n";
const int controlNumber
The control number that is used to confirm the compatibility between the coordinator and workers.
MapDifference theMapType
Defines the type of the map to be used for the computations.
The class that computes and returns properties of the Conley index.
A class whose objects store, update and show coordinate ranges.
Eigenvalues of the Conley index map gathered by levels.
static int maxImgDiam
The maximal image diameter encountered so far.
static int maxImgVol
The maximal image volume encountered so far.
The worker class that processes single chunks of data which contain the definition of a selected rect...
Worker & operator=(const Worker &)
The assignment operator is not allowed.
bool waiting
Is the worker waiting for anything?
int Process(chomp::multiwork::mwData &data)
A function for processing a piece of data by a worker.
Worker(bool _local=false)
The default constructor.
Worker(const Worker &)
The copy constructor is not allowed.
~Worker()
Destructor part for the worker specialization.
bool local
Is the work being done locally? That is, in the same process as the coordinator? If so,...
chomp::homology::timeused waitingTime
Waiting time measurement between consecutive pieces.
int Initialize(chomp::multiwork::mwData &data)
A function for the initialization of a worker.
Computation of Morse decompositions.
theMorseDecompositionType * computeMorseDecomposition(theMapType &theMap, const theCubMapType theCubMap0, const theCubMapType theCubMap1, const double *offset, const double *width, int_t skipIndices, const std::string &cacheFileName, const std::string &pictureFileName, const std::string &cubesFilePrefix, const std::string &morseDecFileName, const std::string &graphFileName, const std::string &procFilePrefix, const std::string &mapOptFileName, bool &morseDecComputed, std::vector< int > &wrongIndices, std::vector< int > &skippedIndices, std::vector< int > &attractors, bool connOrbits, const double *leftMapParam, const double *rightMapParam, int paramCount)
Computes the Morse decomposition using all the pre- and postprocessing.
Choice of configuration settings.
Data conversion for sending/receiving.
Data conversion for sending/receiving: std::vectors and hashed sets of any objects.
Eigenvalues of the Conley index map.
Map optimization data saving, retrieving, and sending.
Matching Morse decompositions.
void matchMorseDecompositions(const parCubes ¶mBoxes, const std::vector< theMorseDecompositionType * > &morseDec, const std::vector< theCubMapType * > &theCubMap1, const std::vector< std::vector< int > > &wrongIndices, const parCoord *parLeft, const parCoord *parRight, std::vector< std::vector< parCube > > &matchClasses)
Matches Morse decompositions corresponding to parameter cubes in the entire range.
const SpaceOffsetType spaceOffset
An imitation of an array which returns the offset of the rectangular area in the phase space which co...
const int paramDim
The dimension of the parameter space to iterate.
const int spaceDim
The dimension of the phase space.
const bool ignoreIsolationForContinuation
Ignoring the isolation problem while matching Morse decompositions.
const int paramCount
The number of all the parameters, both varying and fixed.
const SpaceWidthType spaceWidth
An imitation of an array which returns the width of the rectangular area in the phase space which con...
const int finalDepth
The final depth of subdivisions in the phase space.
const short int paramSubdiv[paramDim]
The numbers of subintervals in each direction of the parameter space.
Plotting a Morse decomposition in a PNG picture.
void plotMorseDecompositionPNG(const MorseDecType &m, const char *filename, int xCoord, int yCoord, int size=0, bool colorBar=true)
Saves all the Morse sets in the provided Morse decomposition to a PNG file.
Customizable data types for the Conley-Morse graphs computation program.
Data types for the dynamical systems data structures.
MapComputation< theMapType, spcCube, spcCubes > theCubMapType
Combinatorial cubical multivalued map type.
chomp::homology::tCubeFix< paramDim, parCoord > parCube
The type of a cube in the set of parameters.
short int parCoord
The type of coordinates of cubes in the set of parameters.
chomp::homology::tRectangle< parCoord > parRect
The type of a rectangle used to iterate sets of cubes of parameters.
chomp::homology::hashedset< parCube > parCubes
The type of a set of cubes in the set of parameters.
chomp::homology::tCubeBase< spcCoord > spcCube
The type of a cube in the phase space.
Utilites and helper functions.
bool internalBoundaryPoint(const intType1 *coord, const intType2 *left, const intType2 *right, const intType3 *limit, int dim)
Verifies whether the given box is located at the boundary of the small region which is either not at ...
bool fileExists(const char *filename)
Returns 'true' iff the given file exists and it is allowed to read it.
std::string coord2str(const intType1 *coords, const intType2 *maxCoords, int dim)
Generates an underscore-separated list of non-negative coordinates padded with zeros to the same widt...
void computeParam(const intType *curCoord, double *leftMapParam, double *rightMapParam)
Computes the real coordinates of the parameter cube which corresponds to the given box.