Go to the documentation of this file.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 #ifndef _worker_h_
00035 #define _worker_h_
00036
00037 #include "chomp/system/config.h"
00038 #include "chomp/system/textfile.h"
00039 #include "chomp/system/timeused.h"
00040 #include "chomp/multiwork/mw.h"
00041
00042 #include "graphs.h"
00043 #include "maptypes.h"
00044 #include "parttypes.h"
00045
00046
00047 namespace unifexp {
00048
00049
00050
00051
00052
00053
00054 class Worker: public chomp::multiwork::mwWorker
00055 {
00056 public:
00057
00058 Worker (int _controlNumber, bool _local = false);
00059
00060 private:
00061
00062 int controlNumber;
00063
00064
00065
00066
00067
00068 bool local;
00069
00070
00071 int Initialize (chomp::multiwork::mwData &data);
00072
00073
00074 int Process (chomp::multiwork::mwData &data);
00075
00076 private:
00077
00078 mapTypes<double> maps;
00079
00080
00081
00082 partTypes<double> partitions;
00083
00084 };
00085
00086
00087
00088 inline Worker::Worker (int _controlNumber, bool _local):
00089 controlNumber (_controlNumber), local (_local)
00090 {
00091 return;
00092 }
00093
00094
00095
00096 inline int Worker::Initialize (chomp::multiwork::mwData &data)
00097 {
00098
00099 return chomp::multiwork::mwOk;
00100 }
00101
00102 inline int Worker::Process (chomp::multiwork::mwData &data)
00103 {
00104 using namespace chomp::homology;
00105 using namespace chomp::multiwork;
00106
00107
00108 double timeStamp = static_cast<double> (program_time);
00109
00110
00111 int currentLevel = 0, currentItem = 0;
00112 data >> currentLevel;
00113 data >> currentItem;
00114
00115
00116 sout << "- " << currentLevel << ":" << currentItem << ".\n";
00117
00118
00119 std::string mapName;
00120 data >> mapName;
00121 mapType<double> *theMap = maps. get (mapName);
00122 if (!theMap)
00123 {
00124 sout << "! Cannot find the map '" << mapName << "'.\n";
00125 data. Reset ();
00126 return mwReject;
00127 }
00128
00129
00130 std::string partName;
00131 data >> partName;
00132 partType<double> *thePart = partitions. get (partName);
00133 if (!thePart)
00134 {
00135 sout << "! Cannot find the partition '" <<
00136 partName << "'.\n";
00137 data. Reset ();
00138 return mwReject;
00139 }
00140
00141
00142 int partCount = 0;
00143 data >> partCount;
00144
00145
00146 double paramMin = 0, paramMax = 0;
00147 data >> paramMin;
00148 data >> paramMax;
00149 theMap -> setParam (paramMin, paramMax);
00150
00151
00152 double deltaBad = 0;
00153 double delta = 0;
00154 double resolution = 0.01;
00155 double lambda = 0;
00156 data >> delta;
00157 data >> resolution;
00158 data >> lambda;
00159
00160
00161 int computeDelta = 0;
00162 int computeDelta0 = 0;
00163 int computeLambda = 0;
00164 int computeC = 0;
00165 int computeLambda0 = 0;
00166 int rigorous = 0;
00167 int sparseGraph = -1;
00168 data >> computeDelta;
00169 data >> computeDelta0;
00170 data >> computeLambda;
00171 data >> computeC;
00172 data >> computeLambda0;
00173 data >> rigorous;
00174 data >> sparseGraph;
00175
00176
00177 int loprec = 6;
00178 int hiprec = 6;
00179 data >> loprec;
00180 data >> hiprec;
00181
00182
00183 int ctrl = 0;
00184 data >> ctrl;
00185 if (ctrl != controlNumber)
00186 {
00187 sout << "! Data incomplete. Rejecting it.\n";
00188 data. Reset ();
00189 return mwReject;
00190 }
00191
00192
00193 int precision = std::cout. precision ();
00194 sbug << std::setprecision (hiprec);
00195 sout << std::setprecision (hiprec);
00196
00197
00198 double logC = 0, lambda0 = 0;
00199 int result = 0;
00200 try
00201 {
00202
00203 if (computeDelta || computeDelta0)
00204 {
00205 bool considerPaths = !!computeDelta0;
00206 findDeltaBisection (lambda, resolution,
00207 *theMap, *thePart, partCount,
00208 deltaBad, delta, considerPaths,
00209 rigorous, sparseGraph);
00210 }
00211
00212
00213 if (computeLambda || computeC || computeLambda0)
00214 {
00215 findLambdaC (delta, *theMap, *thePart, partCount,
00216 computeLambda ? &lambda : 0,
00217 computeC ? &logC : 0,
00218 computeLambda0 ? &lambda0 : 0,
00219 rigorous, sparseGraph);
00220 }
00221 }
00222 catch (const char *msg)
00223 {
00224 sout << "REJECT: " << msg << '\n';
00225 result = -1;
00226 }
00227 catch (const std::exception &e)
00228 {
00229 sout << "REJECT: " << e. what () << '\n';
00230 result = -1;
00231 }
00232 catch (...)
00233 {
00234 sout << "REJECT: An unknown error occurred.\n";
00235 result = -1;
00236 }
00237
00238
00239 sbug << std::setprecision (precision);
00240 sout << std::setprecision (precision);
00241
00242
00243 if (result < 0)
00244 {
00245 data. Reset ();
00246 return mwReject;
00247 }
00248
00249
00250 sout << "= " << currentLevel << ":" << currentItem << ".\n";
00251
00252
00253 data. Reset ();
00254 data << currentLevel;
00255 data << currentItem;
00256 data << paramMin;
00257 data << paramMax;
00258 data << partCount;
00259 data << deltaBad;
00260 data << delta;
00261 data << lambda;
00262 data << logC;
00263 data << lambda0;
00264 data << (static_cast<double> (program_time) - timeStamp);
00265 data << controlNumber;
00266
00267
00268 return mwOk;
00269 }
00270
00271
00272 }
00273
00274 #endif // _worker_h_
00275
00276
00277