The ChainCon Software (Release 0.03)
awdiag2dmain.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// The main procedure of a generic program for the computation
6 /// of the Alexander-Whitney diagonal.
7 ///
8 /////////////////////////////////////////////////////////////////////////////
9 
10 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
11 //
12 // This file is part of my research software package. This is free software:
13 // you can redistribute it and/or modify it under the terms of the GNU
14 // General Public License as published by the Free Software Foundation,
15 // either version 3 of the License, or (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this software; see the file "license.txt". If not,
24 // please, see <http://www.gnu.org/licenses/>.
25 
26 // Started on March 24, 2009. Last revision: January 12, 2013.
27 
28 
29 #ifndef _AWDIAG2DMAIN_H_
30 #define _AWDIAG2DMAIN_H_
31 
32 
33 // include some standard C++ header files
34 #include <istream>
35 #include <ostream>
36 
37 // include selected header files from the CHomP library
38 #include "chomp/system/config.h"
39 #include "chomp/system/textfile.h"
40 #include "chomp/system/timeused.h"
41 #include "chomp/system/arg.h"
42 #include "chomp/struct/hashsets.h"
43 
44 // include relevant local header files
45 #include "chaincon/cellnames.h"
46 #include "chaincon/filtcomplex.h"
47 #ifdef SPACE_WRAPPING
48 #include "chaincon/wrapping.h"
49 #endif
50 #include "atmodcomp.h"
51 #include "awdiag2dcomp.h"
52 
53 
54 // --------------------------------------------------
55 // ---------------------- main ----------------------
56 // --------------------------------------------------
57 
58 /// The main procedure of a program for the computation
59 /// of the Alexander-Whitney diagonal.
60 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
61 template <class CellT>
62 inline int awdiag2dMain (int argc, char *argv [],
63  const char *title, const char *helpinfo)
64 {
65  using namespace chomp::homology;
66 
67  // turn on a message that will appear if the program does not finish
68  program_time = "Aborted after";
69 
70  // prepare user-configurable data
71  char *Xname = 0;
72  char *Aname = 0;
73  bool reduced = false;
74  bool addBoundariesX = true;
75  bool addBoundariesA = true;
76  bool addNoBoundaries = false;
77  bool displayDiag = false;
78  bool verify = false;
79  int algorithmVersion = 2;
80 #ifdef SPACE_WRAPPING
81  const int maxWrapping = 100;
82  char *wrapping [maxWrapping];
83  int nWrapping = 0;
84 #endif
85 
86  // analyze the command line
87  arguments a;
88  arg (a, NULL, Xname);
89  arg (a, NULL, Aname);
90  arg (a, "a", algorithmVersion);
91 #ifdef SPACE_WRAPPING
92  arg (a, "w", wrapping, nWrapping, maxWrapping);
93 #endif
94  argswitch (a, "r", reduced, true);
95  argswitch (a, "bx", addBoundariesX, false);
96  argswitch (a, "ba", addBoundariesA, false);
97  argswitch (a, "b", addNoBoundaries, true);
98  argswitch (a, "ddiag", displayDiag, true);
99  argswitch (a, "-verify", verify, true);
100  arghelp (a);
101 
102  argstreamprepare (a);
103  int argresult = a. analyze (argc, argv);
104  argstreamset ();
105 
106  // show the program's title
107  if (argresult >= 0)
108  sout << title << '\n';
109 
110  // if something was incorrect, show an additional message and exit
111  if (argresult < 0)
112  {
113  sout << "Call with '--help' for help.\n";
114  return 2;
115  }
116 
117  // if help requested or no filename present, show help information
118  if ((argresult > 0) || !Xname)
119  {
120  sout << helpinfo << '\n';
121  return 1;
122  }
123 
124  // try running the main function and catch an error message if thrown
125  try
126  {
127  // set the existence of the empty cell if desired
128  if (reduced)
129  CellT::EmptyType::setExistence (true);
130 
131 #ifdef SPACE_WRAPPING
132  // set wrapping as desired
133  for (int i = 0; i < nWrapping; ++ i)
134  {
135  setWrapping<typename CellT::WrapType>
136  (std::string (wrapping [i]));
137  }
138 #endif
139 
140  // read the filtered cell complexes
143  readFilteredComplexes (Xname, Aname, K, L,
144  addBoundariesX && !addNoBoundaries,
145  addBoundariesA && !addNoBoundaries);
146  bool relativeComplex = !L. empty ();
147 
148  // prepare the data for storing the result of computation
149  chomp::homology::hashedset<CellT> H;
150  tCombLinMap<CellT, CellT> pi, incl, phi;
151  tCellNames<CellT> cellNames;
152  // cellNames. setPrefix ("g");
153 
154  // compute the homology groups and generators
155  bool displayPi = false;
156  bool displayIncl = false;
157  bool displayPhi = false;
158  bool displayRepr = false;
159  computeAlgTopModel (K, relativeComplex, H, pi, incl, phi,
160  cellNames, displayPi, displayIncl, displayPhi,
161  displayRepr, verify, algorithmVersion);
162 
163  // compute the A-W diagonal
164  computeAWdiagonal2d (H, pi, incl, cellNames, displayDiag,
165  verify, K);
166 
167  program_time = "Total time used:";
168  program_time = 1;
169  return 0;
170  }
171  catch (const char *msg)
172  {
173  sout << "ERROR: " << msg << '\n';
174  return -1;
175  }
176  catch (const std::exception &e)
177  {
178  sout << "ERROR: " << e. what () << '\n';
179  return -1;
180  }
181  catch (...)
182  {
183  sout << "ABORT: An unknown error occurred.\n";
184  return -1;
185  }
186 } /* awdiag2dMain */
187 
188 
189 #endif // _AWDIAG2D_H_
190 
const char * helpinfo
Brief help information on the program&#39;s usage.
Definition: ammodcub.cpp:53
A class whose instances can be used to generate names of cells with subsequent numbers, in each dimension separately.
Definition: cellnames.h:61
A generic procedure for the Alexander-Whithey diagonal computation for 2-dimensional homology generat...
Tools for coordinate wrapping, a.k.a.
A filtered cell complex.
A filtered complex.
Definition: filtcomplex.h:53
void computeAWdiagonal2d(const chomp::homology::hashedset< CellT > &H, const LinMap &pi, const LinMap &incl, CellNames &cellNames, bool displayDiag, bool verify, const CellRestrT &restr)
Computes the Alexander-Whithey diagonal for 2-dimensional homology generators.
Definition: awdiag2dcomp.h:57
void readFilteredComplexes(const char *Xname, const char *Aname, tFilteredComplex< CellT > &K, tFilteredComplex< CellT > &L, bool addBoundariesX, bool addBoundariesA)
Reads a filtered cell complex or a pair of filtered cell complexes from text files.
Definition: readfcompl.h:56
A class for naming cells for nice text data output.
const char * title
The title of the program and licensing information.
Definition: ammodcub.cpp:47
void computeAlgTopModel(const tFilteredComplex< CellT > &K, bool relativeComplex, chomp::homology::hashedset< CellT > &H, LinMap &pi, LinMap &incl, LinMap &phi, CellNames &cellNames, bool displayPi, bool displayIncl, bool displayPhi, bool displayRepr, bool verify, int algorithmVersion)
Computes an AT model and the homology of a cellular complex.
Definition: atmodcomp.h:65
A combinatorial linear map.
Definition: comblinmap.h:56
int awdiag2dMain(int argc, char *argv [], const char *title, const char *helpinfo)
The main procedure of a program for the computation of the Alexander-Whitney diagonal.
Definition: awdiag2dmain.h:62
A generic procedure for the computation of chain contraction of a filtered cell complex stored in a f...