The ChainCon Software (Release 0.03)
atmodmain.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// The main procedure for a program for the computation of
6 /// an algebraic topological model.
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: October 21, 2013.
27 
28 
29 #ifndef _ATMODMAIN_H_
30 #define _ATMODMAIN_H_
31 
32 
33 // include some standard C++ header files
34 #include <istream>
35 #include <ostream>
36 #include <string>
37 
38 // include selected header files from the CHomP library
39 #include "chomp/system/config.h"
40 #include "chomp/system/textfile.h"
41 #include "chomp/system/timeused.h"
42 #include "chomp/system/arg.h"
43 #include "chomp/struct/hashsets.h"
44 
45 // include relevant local header files
46 #include "chaincon/linmap.h"
47 #include "chaincon/comblinmap.h"
48 #include "chaincon/ringzp.h"
49 #include "chaincon/cellnames.h"
50 #ifdef SPACE_WRAPPING
51 #include "chaincon/wrapping.h"
52 #endif
53 #include "atmodcomp.h"
54 
55 
56 // --------------------------------------------------
57 // ---------------------- main ----------------------
58 // --------------------------------------------------
59 
60 /// The main procedure for a program for the computation of a homology
61 /// gradient vector field.
62 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
63 template <class CellT>
64 inline int atModelMain (int argc, char *argv [],
65  const char *title, const char *helpinfo)
66 {
67  using namespace chomp::homology;
68 
69  // turn on a message that will appear if the program does not finish
70  program_time = "Aborted after";
71 
72  // prepare user-configurable data
73  char *Xname = 0;
74  char *Aname = 0;
75  int p = 1;
76  bool reduced = false;
77  bool addBoundariesX = true;
78  bool addBoundariesA = true;
79  bool addNoBoundaries = false;
80  bool displayPi = false;
81  bool displayIncl = false;
82  bool displayPhi = false;
83  bool displayRepr = false;
84  bool verify = false;
85  int algorithmVersion = 2;
86 #ifdef SPACE_WRAPPING
87  const int maxWrapping = 100;
88  char *wrapping [maxWrapping];
89  int nWrapping = 0;
90 #endif
91 
92  // analyze the command line
93  arguments a;
94  arg (a, NULL, Xname);
95  arg (a, NULL, Aname);
96  arg (a, "p", p);
97  arg (a, "a", algorithmVersion);
98 #ifdef SPACE_WRAPPING
99  arg (a, "w", wrapping, nWrapping, maxWrapping);
100 #endif
101  argswitch (a, "r", reduced, true);
102  argswitch (a, "bx", addBoundariesX, false);
103  argswitch (a, "ba", addBoundariesA, false);
104  argswitch (a, "b", addNoBoundaries, true);
105  argswitch (a, "dpi", displayPi, true);
106  argswitch (a, "dincl", displayIncl, true);
107  argswitch (a, "dphi", displayPhi, true);
108  argswitch (a, "drepr", displayRepr, true);
109  argswitch (a, "-verify", verify, true);
110  arghelp (a);
111 
112  argstreamprepare (a);
113  int argresult = a. analyze (argc, argv);
114  argstreamset ();
115 
116  // show the program's title
117  if (argresult >= 0)
118  sout << title << '\n';
119 
120  // if something was incorrect, show an additional message and exit
121  if (argresult < 0)
122  {
123  sout << "Call with '--help' for help.\n";
124  return 2;
125  }
126 
127  // if help requested or no filename present, show help information
128  if ((argresult > 0) || !Xname || (p < 0))
129  {
130  sout << helpinfo << '\n';
131  return 1;
132  }
133 
134  // try running the main function and catch an error message if thrown
135  try
136  {
137  // set the existence of the empty cell if desired
138  if (reduced)
139  CellT::EmptyType::setExistence (true);
140 
141 #ifdef SPACE_WRAPPING
142  // set wrapping as desired
143  for (int i = 0; i < nWrapping; ++ i)
144  {
145  setWrapping<typename CellT::WrapType>
146  (std::string (wrapping [i]));
147  }
148 #endif
149 
150  // prepare the data for storing the result of computation
151  chomp::homology::hashedset<CellT> H;
152 
153  // read the filtered cell complexes
156  readFilteredComplexes (Xname, Aname, K, L,
157  addBoundariesX && !addNoBoundaries,
158  addBoundariesA && !addNoBoundaries);
159  bool relativeComplex = !L. empty ();
160 
161  // compute the homology groups and generators
162  tCellNames<CellT> cellNames;
163  // cellNames. setPrefix ("g");
164  if (p == 1)
165  {
166  sout << "Carrying out computations "
167  "in a combinatorial way (ring Z_2).\n";
168  tCombLinMap<CellT,CellT> pi, incl, phi;
169  computeAlgTopModel (K, relativeComplex,
170  H, pi, incl, phi, cellNames,
171  displayPi, displayIncl, displayPhi,
172  displayRepr, verify, algorithmVersion);
173  }
174  else
175  {
176  typedef tZp<short> CoefT;
177  CoefT::setp (p);
178  p = CoefT::getp ();
179  sout << "Carrying out computations in the ring " <<
180  CoefT::ringsymbol () << ".\n";
181  tLinMap<CellT,CellT,CoefT> pi, incl, phi;
182  computeAlgTopModel (K, relativeComplex,
183  H, pi, incl, phi, cellNames,
184  displayPi, displayIncl, displayPhi,
185  displayRepr, verify, algorithmVersion);
186  }
187 
188  program_time = "Total time used:";
189  program_time = 1;
190  return 0;
191  }
192  catch (const char *msg)
193  {
194  sout << "ERROR: " << msg << '\n';
195  return -1;
196  }
197  catch (const std::exception &e)
198  {
199  sout << "ERROR: " << e. what () << '\n';
200  return -1;
201  }
202  catch (...)
203  {
204  sout << "ABORT: An unknown error occurred.\n";
205  return -1;
206  }
207 } /* atModelMain */
208 
209 
210 #endif // _ATMODMAIN_H_
211 
Elements of the ring Z_p.
A linear map for coefficients in an arbitrary commutative ring.
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 combinatorial linear map (for coefficients in Z_2).
Tools for coordinate wrapping, a.k.a.
A linear map.
Definition: linmap.h:55
A filtered complex.
Definition: filtcomplex.h:53
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
int atModelMain(int argc, char *argv [], const char *title, const char *helpinfo)
The main procedure for a program for the computation of a homology gradient vector field...
Definition: atmodmain.h:64
An element of the ring Z_p, where p is globally set.
Definition: ringzp.h:179
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
A generic procedure for the computation of chain contraction of a filtered cell complex stored in a f...