• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

unifexp.cpp

Go to the documentation of this file.
00001 /// @addtogroup unifexp
00002 /// @{
00003 
00004 /////////////////////////////////////////////////////////////////////////////
00005 ///
00006 /// @file unifexp.cpp
00007 ///
00008 /// This file contains the main program which processes the command-line
00009 /// arguments and runs the computations.
00010 ///
00011 /// @author Pawel Pilarczyk
00012 ///
00013 ///
00014 /// @namespace unifexp
00015 ///
00016 /// This namespace contains all the classes and functions defined in the
00017 /// Uniform Expansion project files.
00018 ///
00019 ///
00020 /// @namespace chomp
00021 ///
00022 /// This is the top-level namespace of the CHomP library interface;
00023 /// most classes and functions are contained in its sub-namespaces.
00024 ///
00025 ///
00026 /// @namespace chomp::homology
00027 ///
00028 /// This is the main namespace that contains most of the CHomP library
00029 /// classes and functions, some of which are used in the Uniform Expansion
00030 /// project.
00031 ///
00032 ///
00033 /// @mainpage The Uniform Expansion Software
00034 ///
00035 /// \section intro Introduction
00036 ///
00037 /// This website contains the documentation of software designed and
00038 /// programmed by Pawel Pilarczyk which accompanies the paper
00039 /// <em>Quantitative hyperbolicity estimates in one-dimensional
00040 /// dynamics</em> by S. Day, H. Kokubu, S. Luzzatto, K. Mischaikow, H. Oka,
00041 /// and P. Pilarczyk.
00042 ///
00043 /// \section License
00044 ///
00045 /// In order to make this software freely available for wide audience,
00046 /// it is provided here under the terms of the GNU General Public License,
00047 /// version 2 or any later version. Please, see the
00048 /// <a href="http://www.gnu.org/copyleft/gpl.html">GNU website</a>
00049 /// for details.
00050 ///
00051 /// \section modules Modules
00052 ///
00053 /// The documentation covers two major modules. The first one, called
00054 /// <em>unifexp</em>, contains the part of software written specifically
00055 /// for the Uniform Expansion project. This classes and functions
00056 /// in this module are all gathered in the <em>unifexp</em> namespace.
00057 ///
00058 /// The second module, called
00059 /// <em>struct</em>, contains an extract from the Computational Homology
00060 /// Project software, or CHomP for short, which was used in this project.
00061 /// The data structures defined in that portion of the code are gathered
00062 /// in the CHomP namespace called <em>chomp::homology</em>.
00063 ///
00064 /// Note that the development of some portions of the CHomP software,
00065 /// in particular the graph algorithms included in the header file
00066 /// <em>digraph.h</em>, was motivated by the Uniform Expansion project.
00067 /// Moreover, it is necessary to know their features in order to be able
00068 /// to understand the Uniform Expansion software.
00069 /// Therefore, it is fully justified to include them in this documentation.
00070 ///
00071 /// \section browsing Browsing
00072 ///
00073 /// Although a lot of effort was put into making this software as transparent
00074 /// and clear as possible, and this documentation complete, I am sure that
00075 /// there is a lot of important information that might have been included
00076 /// here but was not. Therefore, this documentation was generated in such
00077 /// a way that it contains the source code which can be browsed and checked
00078 /// in case of any doubt.
00079 ///
00080 /// So, what are you waiting for? I wish you
00081 /// a happy browsing!
00082 ///
00083 /// Pawel Pilarczyk
00084 ///
00085 /////////////////////////////////////////////////////////////////////////////
00086 
00087 // Copyright (C) 2007 by Pawel Pilarczyk.
00088 //
00089 // This file is part of my research program package.  This is free software;
00090 // you can redistribute it and/or modify it under the terms of the GNU
00091 // General Public License as published by the Free Software Foundation;
00092 // either version 2 of the License, or (at your option) any later version.
00093 //
00094 // This software is distributed in the hope that it will be useful,
00095 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00096 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00097 // GNU General Public License for more details.
00098 //
00099 // You should have received a copy of the GNU General Public License along
00100 // with this software; see the file "license.txt".  If not, write to the
00101 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00102 // MA 02111-1307, USA.
00103 
00104 // Started on March 8, 2007. Last revision: August 22, 2007.
00105 
00106 // NOTE: This program uses the BOOST, CAPD and CHomP libraries.
00107 
00108 
00109 // the first local header file
00110 #include "rounding.h" // (this header must be included first - BOOST)
00111 
00112 // other local header files
00113 #include "coord.h"
00114 #include "worker.h"
00115 #include "maptypes.h"
00116 #include "parttypes.h"
00117 
00118 // standard library headers
00119 #include <string>
00120 #include <vector>
00121 #include <exception>
00122 
00123 // selected files from the CHomP library
00124 #include "chomp/system/config.h"
00125 #include "chomp/system/textfile.h"
00126 #include "chomp/system/timeused.h"
00127 #include "chomp/multiwork/mw.h"
00128 #include "chomp/system/arg.h"
00129 
00130 
00131 // --------------------------------------------------
00132 // -------------------- OVERTURE --------------------
00133 // --------------------------------------------------
00134 
00135 /// The title of the main program.
00136 const char *title = "\
00137 UniformExpansion, ver. 0.01, 11/14/2007. (C) 2007 by Pawel Pilarczyk.\n\
00138 This is free software. No warranty. Consult 'license.txt' for details.";
00139 
00140 /// The help information about the main program.
00141 const char *helpinfo = "\
00142 This is a computer program for the rigorous analysis of the uniform\n\
00143 expansion condition as described in the paper by S. Day, H. Kokubu,\n\
00144 S. Luzzatto, K. Mischaikow, H. Oka, and P. Pilarczyk. See the paper\n\
00145 for details, and the attached documentation for directions.\n\
00146 Command line arguments:\n\
00147 -a N - set the value of the map's parameter (an obligatory argument!),\n\
00148 -m name - use the map with the given name (default: quadratic),\n\
00149 -p name - use partition with the given name (default: uniform),\n\
00150 -k N - set the number of intervals, including crit. nbhd (default: 1001),\n\
00151 -d N - fix delta (the radius of the critical neighborhood; default: 0.01),\n\
00152 -f name - save results of computations to this file,\n\
00153 -s N - use algorithms for sparse graphs: 0=no, 1=yes, -1=auto (default),\n\
00154 --rigorous - run rigorous computations (with controlled rounding),\n\
00155 --flush - flush the data written to the results file (slow),\n\
00156 --help - show this brief help information and exit.\n\
00157 Arguments that define what to compute (default: lambda, C, and lambda0):\n\
00158 --lambda - compute lambda for (1) in the paper,\n\
00159 --C - compute C for (1) in the paper (implies the computation of lambda),\n\
00160 --lambda0 - compute lambda for (2) in the paper (implies --lambda),\n\
00161 --delta - compute min delta s.t. lambda > 0 (does not imply --lambda),\n\
00162 --delta0 - compute min delta s.t. lambda0 > 0 (does not imply --lambda),\n\
00163 -l N - fix a lambda or lambda0 for --delta or --delta0 (default: 0),\n\
00164 -r N - relative resolution for computing log delta (default: 0.01).\n\
00165 If one of the arguments '-a', '-d', '-k', '-l' is repeated, then the\n\
00166 computations are run for all the parameters from the given interval.\n\
00167 -i - use full intervals of parameters (applies only for '-a'),\n\
00168 -L N - level of initial subdivisions (default: 4); 2^n are made at start,\n\
00169 -L N - level of final subdivisions (def: 10); 2^n subdivisions are made.\n\
00170 Arguments for running distributed computing:\n\
00171 -w computer:port - run a worker and connect to the given coordinator,\n\
00172 -c [port] - run the coordinator and listen at the given port (def: 4721).";
00173 
00174 /// Information on where to find more information about the program.
00175 const char *helpmore = "\
00176 For more information ask the author at http://www.pawelpilarczyk.com/.";
00177 
00178 /// The control number for network communication. Change this number
00179 /// whenever an incompatible version of this program is created.
00180 const int controlNumber = 42342;
00181 
00182 
00183 // --------------------------------------------------
00184 // ---------------------- MAIN ----------------------
00185 // --------------------------------------------------
00186 
00187 /// The main function of the program.
00188 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
00189 int main (int argc, char *argv [])
00190 {
00191         using namespace chomp::homology;
00192         using namespace chomp::multiwork;
00193         using namespace unifexp;
00194 
00195         // prepare user-configurable data
00196         const double infinity = 1.7e308;
00197         double paramMin = -infinity;
00198         double paramMax = -infinity;
00199         double deltaMin = 0;
00200         double deltaMax = -infinity;
00201         double resolution = 0.01;
00202         double lambdaMin = 0;
00203         double lambdaMax = -infinity;
00204         int partCountMin = 1001;
00205         int partCountMax = -1;
00206         char *mapName = 0;
00207         char *defMapName = const_cast<char *> ("quadratic");
00208         char *defMapNameRigorous = const_cast<char *> ("quadratic-intv");
00209         char *partName = const_cast<char *> ("uniform");
00210         int port = 0;
00211         char *work = 0;
00212         bool test = false;
00213         bool flushfile = false;
00214         char *filename = 0;
00215         bool intervals = false;
00216         int startLevel = 4;
00217         int finalLevel = 6;
00218         int computeDelta = 0;
00219         int computeDelta0 = 0;
00220         int computeLambda = 0;
00221         int computeC = 0;
00222         int computeLambda0 = 0;
00223         int rigorous = 0;
00224         int sparseGraph = -1;
00225 
00226         // interprete the command-line arguments
00227         arguments a;
00228         arg (a, "a", paramMin);
00229         arg (a, "a", paramMax);
00230         arg (a, "d", deltaMin);
00231         arg (a, "d", deltaMax);
00232         arg (a, "r", resolution);
00233         arg (a, "k", partCountMin);
00234         arg (a, "k", partCountMax);
00235         arg (a, "m", mapName);
00236         arg (a, "p", partName);
00237         arg (a, "f", filename);
00238         arg (a, "c", port, 4721);
00239         arg (a, "w", work);
00240         arg (a, "L", startLevel);
00241         arg (a, "L", finalLevel);
00242         arg (a, "l", lambdaMin);
00243         arg (a, "l", lambdaMax);
00244         arg (a, "s", sparseGraph);
00245         argswitch (a, "i", intervals, true);
00246         argswitch (a, "t", test, true);
00247         argswitch (a, "-test", test, true);
00248         argswitch (a, "-flush", flushfile, true);
00249         argswitch (a, "-delta0", computeDelta0, 1);
00250         argswitch (a, "-delta", computeDelta, 1);
00251         argswitch (a, "-lambda0", computeLambda0, 1);
00252         argswitch (a, "-lambda", computeLambda, 1);
00253         argswitch (a, "-C", computeC, 1);
00254         argswitch (a, "-rigorous", rigorous, 1);
00255         arghelp (a);
00256 
00257         argstreamprepare (a);
00258         int argresult = a. analyze (argc, argv);
00259         argstreamset ();
00260 
00261         // show the program's main title
00262         if (argresult >= 0)
00263                 sout << title << '\n';
00264 
00265         // if something was incorrect, show an additional message and exit
00266         if (argresult < 0)
00267         {
00268                 sout << "Call with '--help' for help.\n";
00269                 return 2;
00270         }
00271 
00272         // if help requested, show help information
00273         if (((paramMin == -infinity) && !work && !test) || (argresult > 0))
00274         {
00275                 sout << helpinfo << '\n';
00276                 typedef std::vector<std::string> strings;
00277 
00278                 // show available partition types
00279                 strings partNames;
00280                 partTypes<double> partitions;
00281                 partitions. getNames (partNames);
00282                 sout << "Available partitions:";
00283                 int pos = 14;
00284                 for (strings::iterator it = partNames. begin ();
00285                         it != partNames. end (); ++ it)
00286                 {
00287                         if (pos + (*it). length () > 70)
00288                         {
00289                                 sout << "\n\t";
00290                                 pos = 0;
00291                         }
00292                         else if (pos > 0)
00293                                 sout << " ";
00294                         sout << (*it);
00295                         pos += (*it). length () + 1;
00296                 }
00297                 sout << ".\n";
00298 
00299                 // show available map types
00300                 strings mapNames;
00301                 mapTypes<double> maps;
00302                 maps. getNames (mapNames);
00303                 sout << "Available maps:";
00304                 pos = 8;
00305                 for (strings::iterator it = mapNames. begin ();
00306                         it != mapNames. end (); ++ it)
00307                 {
00308                         if (pos + (*it). length () > 70)
00309                         {
00310                                 sout << "\n\t";
00311                                 pos = 0;
00312                         }
00313                         else if (pos > 0)
00314                                 sout << " ";
00315                         sout << (*it);
00316                         pos += (*it). length () + 1;
00317                 }
00318                 sout << ".\n";
00319 
00320                 sout << helpmore << '\n';
00321                 return 1;
00322         }
00323 
00324         // make sure delta is positive unless it is to be computed
00325         if (!computeDelta && !computeDelta0 && (deltaMin <= 0))
00326                 deltaMin = deltaMax = 0.01;
00327 
00328         // determine which variable is to be iterated
00329         if (paramMax < paramMin)
00330                 paramMax = paramMin;
00331         if (deltaMax < deltaMin)
00332                 deltaMax = deltaMin;
00333         if (lambdaMax < lambdaMin)
00334                 lambdaMax = lambdaMin;
00335         if (partCountMax < partCountMin)
00336                 partCountMax = partCountMin;
00337 
00338         // set the default map name if necessary
00339         if (!mapName)
00340                 mapName = rigorous ? defMapNameRigorous : defMapName;
00341 
00342         // if nothing was requested to be computed, set the defaults
00343         if (!computeDelta && !computeDelta0 && !computeLambda &&
00344                 !computeC && !computeLambda0)
00345         {
00346                 computeLambda = 1;
00347                 computeC = 1;
00348                 computeLambda0 = 1;
00349         }
00350 
00351         // if the starting level exceeds the final level, make them equal
00352         if (finalLevel < startLevel)
00353                 finalLevel = startLevel;
00354 
00355         // try running the main function and catch an error message if thrown
00356         try
00357         {
00358                 // set an appropriate program time message
00359                 program_time = "Aborted after:";
00360                 program_time = 1;
00361 
00362                 // run a test if this option was selected
00363                 if (test)
00364                 {
00365                 }
00366 
00367                 // run as a worker if requested to
00368                 else if (work)
00369                 {
00370                         Worker w (controlNumber, false);
00371                         w. Add (work);
00372                         sout << "Running as a worker...\n";
00373                         int result = w. Work ();
00374                         if (result == mwOk)
00375                                 sout << "Work completed successfully.\n";
00376                         else
00377                                 sout << "Could not work - probably "
00378                                         "an error occurred.\n";
00379                 }
00380 
00381                 // run as a coordinator or run the work locally otherwise
00382                 else
00383                 {
00384                         // create a coordinator
00385                         Coordinator c (controlNumber, filename, flushfile,
00386                                 paramMin, paramMax, intervals,
00387                                 deltaMin, deltaMax, resolution,
00388                                 lambdaMin, lambdaMax, mapName,
00389                                 partName, partCountMin, partCountMax,
00390                                 startLevel, finalLevel,
00391                                 computeDelta, computeDelta0,
00392                                 computeLambda, computeC, computeLambda0,
00393                                 rigorous, sparseGraph);
00394                         c. Port (port);
00395 
00396                         // run as a listening coordinator if requested to
00397                         if (port)
00398                         {
00399                                 sout << "Running as a coordinator...\n";
00400                                 int result = c. Coordinate ();
00401                                 if (result == mwOk)
00402                                         sout << "Completed successfully.\n";
00403                                 else
00404                                         sout << "Could not coordinate - "
00405                                                 "an error occurred.\n";
00406                         }
00407 
00408                         // run the computations locally, otherwise
00409                         else
00410                         {
00411                                 Worker w (controlNumber, true);
00412                                 sout << "Running the computations...\n";
00413                                 int result = c. Coordinate (&w);
00414                                 if (result == mwOk)
00415                                         sout << "Completed successfully.\n";
00416                                 else
00417                                         sout << "Could not work - probably "
00418                                                 "an error occurred.\n";
00419                         }
00420                 }
00421 
00422                 // set an appropriate program time message
00423                 program_time = "Total time used:";
00424 
00425                 // finalize
00426                 return 0;
00427         }
00428         catch (const char *msg)
00429         {
00430                 sout << "ERROR: " << msg << '\n';
00431                 return -1;
00432         }
00433         catch (const std::exception &e)
00434         {
00435                 sout << "ERROR: " << e. what () << '\n';
00436                 return -1;
00437         }
00438         catch (...)
00439         {
00440                 sout << "ABORT: An unknown error occurred.\n";
00441                 return -1;
00442         }
00443 } /* main */
00444 
00445 /// @}
00446 

Generated on Sun Feb 3 2013 12:40:32 for The Uniform Expansion Software by  doxygen 1.7.2