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

awdiagsim.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// \file
00004 ///
00005 /// A program for the computation of the Alexander-Whitney diagonal
00006 /// for simplicial complexes.
00007 ///
00008 /////////////////////////////////////////////////////////////////////////////
00009 
00010 // Copyright (C) 2009-2011 by Pawel Pilarczyk.
00011 //
00012 // This file is part of my research software package. This is free software:
00013 // you can redistribute it and/or modify it under the terms of the GNU
00014 // General Public License as published by the Free Software Foundation,
00015 // either version 3 of the License, or (at your option) any later version.
00016 //
00017 // This software is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this software; see the file "license.txt". If not,
00024 // please, see <http://www.gnu.org/licenses/>.
00025 
00026 // Started on March 24, 2009. Last revision: April 4, 2011.
00027 
00028 
00029 // include some standard C++ header files
00030 #include <istream>
00031 #include <ostream>
00032 
00033 // include selected header files from the CHomP library
00034 #include "chomp/system/config.h"
00035 #include "chomp/system/textfile.h"
00036 #include "chomp/system/timeused.h"
00037 #include "chomp/system/arg.h"
00038 #include "chomp/struct/hashsets.h"
00039 
00040 // include relevant local header files
00041 #include "chaincon/simplex.h"
00042 #include "chaincon/awdiagsim.h"
00043 #include "comphom.h"
00044 #include "awdiag2d.h"
00045 
00046 
00047 // --------------------------------------------------
00048 // -------------------- OVERTURE --------------------
00049 // --------------------------------------------------
00050 
00051 /// The title of the program and licensing information.
00052 const char *title = "\
00053 Alexander-Whitney diagonal for simplicial complexes.\n\
00054 Version 0.01 (Apr 4, 2011). Copyright (C) 1997-2011 by Pawel Pilarczyk.\n\
00055 This is free software. No warranty. Consult 'license.txt' for details.";
00056 
00057 /// Brief help information on the program's usage.
00058 const char *helpinfo = "\
00059 This program computes the Alexander-Whitney diagonal for 2-dimensional\n\
00060 homology generators, and represents the result in terms of 1-dimensional\n\
00061 homology genrators. In other words, this program decomposes cavities\n\
00062 into products of cycles.\n\
00063 The ring of coefficients is set to Z_2, the integers modulo 2.\n\
00064 Call with:\n\
00065 filename - the name of a file that contains a list of simplices,\n\
00066 Switches and additional arguments:\n\
00067 -ddiag - display the A-W diagonal of each 2D homology generator,\n\
00068 -aN - homology algorithm: 0 = old (very slow), 1 = new without additional\n\
00069 optimization (relatively fast), 2 = new (default), 3 = using the SNF.\n\
00070 --verify - do additional verification of the computed A-W diagonal,\n\
00071 --log filename - save the output to a file (without progress indicators),\n\
00072 --quiet - suppress data output to the screen (whcih can be still logged),\n\
00073 --help - display this brief help information only and exit.\n\
00074 For more information please consult the accompanying documentation\n\
00075 or ask the program's author at http://www.PawelPilarczyk.com/.";
00076 
00077 
00078 // --------------------------------------------------
00079 // ---------------------- main ----------------------
00080 // --------------------------------------------------
00081 
00082 /// The main procedure of the program.
00083 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
00084 int main (int argc, char *argv [])
00085 {
00086         using namespace chomp::homology;
00087 
00088         // turn on a message that will appear if the program does not finish
00089         program_time = "Aborted after";
00090 
00091         // prepare user-configurable data
00092         char *filename = 0;
00093         bool displayDiag = false;
00094         bool verify = false;
00095         int algorithmVersion = 2;
00096 
00097         // analyze the command line
00098         arguments a;
00099         arg (a, NULL, filename);
00100         arg (a, "a", algorithmVersion);
00101         argswitch (a, "ddiag", displayDiag, true);
00102         argswitch (a, "-verify", verify, true);
00103         arghelp (a);
00104 
00105         argstreamprepare (a);
00106         int argresult = a. analyze (argc, argv);
00107         argstreamset ();
00108 
00109         // show the program's title
00110         if (argresult >= 0)
00111                 sout << title << '\n';
00112 
00113         // if something was incorrect, show an additional message and exit
00114         if (argresult < 0)
00115         {
00116                 sout << "Call with '--help' for help.\n";
00117                 return 2;
00118         }
00119 
00120         // if help requested or no filename present, show help information
00121         if ((argresult > 0) || !filename)
00122         {
00123                 sout << helpinfo << '\n';
00124                 return 1;
00125         }
00126 
00127         // try running the main function and catch an error message if thrown
00128         try
00129         {
00130                 // prepare the data for storing the result of computation
00131                 typedef tSimplex<int_t> CellT;
00132                 chomp::homology::hashedset<CellT> H;
00133                 tCombLinMap<CellT, CellT> pi, incl, phi;
00134 
00135                 // compute the homology groups and generators
00136                 bool displayPi = false;
00137                 bool displayIncl = false;
00138                 bool displayPhi = false;
00139                 computeHomology<CellT> (filename, H, pi, incl, phi,
00140                         displayPi, displayIncl, displayPhi,
00141                         verify, algorithmVersion);
00142 
00143                 // compute the A-W diagonal
00144                 computeAWdiagonal<CellT> (H, pi, incl, displayDiag, verify);
00145 
00146                 program_time = "Total time used:";
00147                 program_time = 1;
00148                 return 0;
00149         }
00150         catch (const char *msg)
00151         {
00152                 sout << "ERROR: " << msg << '\n';
00153                 return -1;
00154         }
00155         catch (const std::exception &e)
00156         {
00157                 sout << "ERROR: " << e. what () << '\n';
00158                 return -1;
00159         }
00160         catch (...)
00161         {
00162                 sout << "ABORT: An unknown error occurred.\n";
00163                 return -1;
00164         }
00165 } /* main */
00166 

Generated on Tue Apr 5 2011 00:06:32 for Chain Contraction Software by  doxygen 1.7.2