The ChainCon Software (Release 0.03)
ammodmain.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// The main function of a program for computing the minimal model
6 /// of a cellular complex of a given type.
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 13, 2013.
27 
28 
29 #ifndef _AMMODMAIN_H_
30 #define _AMMODMAIN_H_
31 
32 
33 // include some standard C++ header files
34 #include <istream>
35 #include <ostream>
36 #include <vector>
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/ringzp.h"
48 #include "chaincon/cellnames.h"
49 #ifdef SPACE_WRAPPING
50 #include "chaincon/wrapping.h"
51 #endif
52 #include "ammodcomp.h"
53 
54 
55 // --------------------------------------------------
56 // ---------------------- main ----------------------
57 // --------------------------------------------------
58 
59 /// The main procedure of a program for the computation of a minimal model.
60 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
61 template <class CellT>
62 inline int algMinModelMain (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  int p = 0;
74  bool reduced = false;
75  bool addBoundariesX = true;
76  bool addBoundariesA = true;
77  bool addNoBoundaries = false;
78  bool displayPi = false;
79  bool displayIncl = false;
80  bool displayPhi = false;
81  bool displayD = false;
82  bool verify = false;
83 #ifdef SPACE_WRAPPING
84  const int maxWrapping = 100;
85  char *wrapping [maxWrapping];
86  int nWrapping = 0;
87 #endif
88 
89  // analyze the command line
90  arguments a;
91  arg (a, NULL, Xname);
92  arg (a, NULL, Aname);
93  arg (a, "p", p);
94 #ifdef SPACE_WRAPPING
95  arg (a, "w", wrapping, nWrapping, maxWrapping);
96 #endif
97  argswitch (a, "r", reduced, true);
98  argswitch (a, "bx", addBoundariesX, false);
99  argswitch (a, "ba", addBoundariesA, false);
100  argswitch (a, "b", addNoBoundaries, true);
101  argswitch (a, "dpi", displayPi, true);
102  argswitch (a, "dincl", displayIncl, true);
103  argswitch (a, "dphi", displayPhi, true);
104  argswitch (a, "dd", displayD, true);
105  argswitch (a, "-verify", verify, true);
106  arghelp (a);
107 
108  argstreamprepare (a);
109  int argresult = a. analyze (argc, argv);
110  argstreamset ();
111 
112  // show the program's title
113  if (argresult >= 0)
114  sout << title << '\n';
115 
116  // if something was incorrect, show an additional message and exit
117  if (argresult < 0)
118  {
119  sout << "Call with '--help' for help.\n";
120  return 2;
121  }
122 
123  // if help requested or no filename present, show help information
124  if ((argresult > 0) || !Xname || (p < 0))
125  {
126  sout << helpinfo << '\n';
127  return 1;
128  }
129 
130  // try running the main function and catch an error message if thrown
131  try
132  {
133  // set the existence of the empty cell if desired
134  if (reduced)
135  CellT::EmptyType::setExistence (true);
136 
137 #ifdef SPACE_WRAPPING
138  // set wrapping as desired
139  for (int i = 0; i < nWrapping; ++ i)
140  {
141  setWrapping<typename CellT::WrapType>
142  (std::string (wrapping [i]));
143  }
144 #endif
145 
146  // prepare the ring of coefficients
147  typedef tZp<short> CoefT;
148  CoefT::setp (p);
149  p = CoefT::getp ();
150 
151  // prepare the data for storing the result of computations
152  chomp::homology::hashedset<CellT> H, A, B;
153  std::vector<CoefT> Q;
154 
155  // read the filtered cell complexes
158  readFilteredComplexes (Xname, Aname, K, L,
159  addBoundariesX && !addNoBoundaries,
160  addBoundariesA && !addNoBoundaries);
161  bool relativeComplex = !L. empty ();
162 
163  // compute the homology groups and generators
164  sout << "Carrying out computations in the ring " <<
165  CoefT::ringsymbol () << ".\n";
166  tLinMap<CellT,CellT,CoefT> pi, incl, phi;
167  tCellNames<CellT> homCellNames;
168  tCellNames<CellT> cohomCellNames;
169  // cellNames. setPrefix ("g");
170  computeAlgMinModel (K, relativeComplex, H, A, B, Q,
171  pi, incl, phi, homCellNames, cohomCellNames,
172  displayPi, displayIncl, displayPhi, displayD,
173  verify);
174 
175  program_time = "Total time used:";
176  program_time = 1;
177  return 0;
178  }
179  catch (const char *msg)
180  {
181  sout << "ERROR: " << msg << '\n';
182  return -1;
183  }
184  catch (const std::exception &e)
185  {
186  sout << "ERROR: " << e. what () << '\n';
187  return -1;
188  }
189  catch (...)
190  {
191  sout << "ABORT: An unknown error occurred.\n";
192  return -1;
193  }
194 } /* algMinModelMain */
195 
196 
197 #endif // _AMMODMAIN_H_
198 
int algMinModelMain(int argc, char *argv [], const char *title, const char *helpinfo)
The main procedure of a program for the computation of a minimal model.
Definition: ammodmain.h:62
Elements of the ring Z_p.
A generic procedure for the computation of an algebraic minimal model of a filtered cell complex stor...
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
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
void computeAlgMinModel(const tFilteredComplex< CellT > &K, bool relativeComplex, CellArray1 &H, CellArray2 &A, CellArray3 &B, CoefArray &Q, tLinMap< CellT, CellT, CoefT > &pi, tLinMap< CellT, CellT, CoefT > &incl, tLinMap< CellT, CellT, CoefT > &phi, CellNames &homCellNames, CellNames &cohomCellNames, bool displayPi, bool displayIncl, bool displayPhi, bool displayD, bool verify)
Computes the homology of a cellular complex.
Definition: ammodcomp.h:68
An element of the ring Z_p, where p is globally set.
Definition: ringzp.h:179