engines.h

Go to the documentation of this file.
00001 
00002 
00003 
00014 
00015 // This file copyright (C) 1997-2010 by Pawel Pilarczyk.
00016 //
00017 // This file is part of the "chomp" program. It is free software;
00018 // you can redistribute it and/or modify it under the terms of the GNU
00019 // General Public License as published by the Free Software Foundation;
00020 // either version 2 of the License, or (at your option) any later version.
00021 //
00022 // This library is distributed in the hope that it will be useful,
00023 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 // GNU General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License along
00028 // with this software; see the file "license.txt".  If not, write to the
00029 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00030 // MA 02111-1307, USA.
00031 
00032 // Started in March 2006. Last revision: April 14, 2006.
00033 
00034 
00035 #ifndef _CAPD_HOMENGIN_ENGINES_H_ 
00036 #define _CAPD_HOMENGIN_ENGINES_H_ 
00037 
00038 #include "chomp/system/config.h"
00039 #include "chomp/system/textfile.h"
00040 #include "chomp/system/timeused.h"
00041 #include "chomp/system/arg.h"
00042 #include "chomp/homology/homology.h"
00043 #include "chomp/homology/homtools.h"
00044 
00045 #include "capd/homologicalAlgebra/embeddingDim.h"
00046 #include "capd/chom/dim.hpp"
00047 #include "capd/auxil/ofstreamcout.h"
00049 extern ofstreamcout fcout;
00050 
00051 #include "capd/homengin/cubfiles.h"
00052 #include "capd/homengin/algstruct.h"
00053 
00054 #include <cstdlib>
00055 #include <ctime>
00056 #include <cstring>
00057 #include <new>
00058 #include <exception>
00059 #include <iostream>
00060 #include <fstream>
00061 #include <iomanip>
00062 #include <vector>
00063 #include <sstream>
00064 
00065 
00066 namespace chomp {
00067 
00072 namespace homengin {
00073 
00074 // --------------------------------------------------
00075 // ---------------- ABSTRACT ENGINE -----------------
00076 // --------------------------------------------------
00077 
00079 class engine
00080 {
00081 public:
00083         typedef std::vector<const engine *> enginelist;
00084 
00086         static enginelist engines;
00087 
00088 protected:
00090         engine ()
00091         {
00092                 engines. push_back (this);
00093                 return;
00094         }
00095 
00097         virtual ~engine ()
00098         {
00099                 enginelist::iterator it = std::find (engines. begin (),
00100                         engines. end (), this);
00101                 if (it != engines. end ())
00102                         engines. erase (it);
00103                 return;
00104         }
00105 
00106 public:
00108         virtual int speed () const
00109         {
00110                 return 0;
00111         }
00112 
00114         virtual bool dimsupported (int dim) const
00115         {
00116                 return false;
00117         }
00118 
00121         virtual int memory (const cubfile &X) const
00122         {
00123                 return 0;
00124         }
00125 
00127         virtual bool relative () const
00128         {
00129                 return false;
00130         }
00131 
00133         virtual bool elementary () const
00134         {
00135                 return false;
00136         }
00137 
00139         virtual bool spacewrapping () const
00140         {
00141                 return false;
00142         }
00143 
00145         virtual void homology (const cubfile &x,
00146                 algstruct<chomp::homology::integer> &h) const
00147         {
00148                 throw "Homology computation not supported.";
00149         }
00150 
00152         virtual void homology (const cubfile &x, const cubfile &y,
00153                 algstruct<chomp::homology::integer> &h) const
00154         {
00155                 throw "Relative homology computation not supported.";
00156         }
00157 
00159         virtual const char *name () const
00160         {
00161                 return "";
00162         }
00163 
00165         virtual std::ostream &describe (std::ostream &out) const
00166         {
00167                 out << "This is an unknown homology engine.\n";
00168                 return out;
00169         }
00170 
00172         static std::ostream &showlist (std::ostream &out,
00173                 const engine::enginelist &elist = engine::engines);
00174 
00177         static const engine *find (const cubfile *X, const cubfile *Y,
00178                 const engine::enginelist &elist = engine::engines);
00179 
00182         static const engine *find (const cubfile *X,
00183                 const engine::enginelist &elist = engine::engines)
00184         {
00185                 return find (X, 0, elist);
00186         }
00187 
00190         static const engine *find (const char *name,
00191                 const engine::enginelist &elist = engine::engines);
00192 
00193 private:
00194 }; /* class engine */
00195 
00196 
00197 // --------------------------------------------------
00198 // ------------------- PP ENGINE --------------------
00199 // --------------------------------------------------
00200 
00202 class PPengine: public engine
00203 {
00204 protected:
00206         PPengine ()
00207         {
00208                 return;
00209         }
00210 
00212         ~PPengine ()
00213         {
00214                 return;
00215         }
00216 
00217 public:
00219         int speed () const
00220         {
00221                 return 100;
00222         }
00223 
00225         bool dimsupported (int dim) const
00226         {
00227                 return (dim > 0) && (dim <= chomp::homology::Cube::MaxDim);
00228         }
00229 
00232         int memory (const cubfile &X) const;
00233 
00235         bool relative () const
00236         {
00237                 return true;
00238         }
00239 
00241         bool elementary () const
00242         {
00243                 return true;
00244         }
00245 
00247         bool spacewrapping () const
00248         {
00249                 return true;
00250         }
00251 
00253         void homology (const cubfile &x,
00254                 algstruct<chomp::homology::integer> &h) const;
00255 
00257         void homology (const cubfile &x, const cubfile &y,
00258                 algstruct<chomp::homology::integer> &h) const;
00259 
00261         const char *name () const
00262         {
00263                 return "PP";
00264         }
00265 
00267         std::ostream &describe (std::ostream &out) const;
00268 
00270         static PPengine eng;
00271 
00272 }; /* class PPengine */
00273 
00274 
00275 // --------------------------------------------------
00276 // ------------------- BK ENGINE --------------------
00277 // --------------------------------------------------
00278 
00280 class BKengine: public engine
00281 {
00282 protected:
00284         BKengine (): useLookupTable (false)
00285         {
00286                 return;
00287         }
00288 
00290         ~BKengine ()
00291         {
00292                 return;
00293         }
00294 
00295 public:
00297         int speed () const
00298         {
00299                 return 250;
00300         }
00301 
00303         bool dimsupported (int dim) const
00304         {
00305                 return (dim == DIM);
00306         }
00307 
00310         int memory (const cubfile &X) const;
00311 
00313         bool relative () const
00314         {
00315                 return false;
00316         }
00317 
00319         bool elementary () const
00320         {
00321                 return false;
00322         }
00323 
00325         bool spacewrapping () const
00326         {
00327                 return false;
00328         }
00329 
00331         void homology (const cubfile &x,
00332                 algstruct<chomp::homology::integer> &h) const;
00333 
00335         void homology (const cubfile &x, const cubfile &y,
00336                 algstruct<chomp::homology::integer> &h) const
00337         {
00338                 throw "The BK engine cannot compute relative homology.";
00339         }
00340 
00342         const char *name () const
00343         {
00344                 return "BK";
00345         }
00346 
00348         std::ostream &describe (std::ostream &out) const;
00349 
00351         static BKengine eng;
00352 
00353 protected:
00355         bool useLookupTable;
00356 
00357 }; /* class BKengine */
00358 
00359 
00360 // --------------------------------------------------
00361 // ------------------ BK_LT ENGINE ------------------
00362 // --------------------------------------------------
00363 
00366 class BK_LTengine: public BKengine
00367 {
00368 protected:
00370         BK_LTengine ()
00371         {
00372                 useLookupTable = true;
00373                 return;
00374         }
00375 
00377         ~BK_LTengine ()
00378         {
00379                 return;
00380         }
00381 
00382 public:
00384         int speed () const
00385         {
00386                 return 260;
00387         }
00388 
00390         const char *name () const
00391         {
00392                 return "BK_LT";
00393         }
00394 
00396         std::ostream &describe (std::ostream &out) const;
00397 
00399         static BK_LTengine eng;
00400 
00401 }; /* class BK_LTengine */
00402 
00403 
00404 // --------------------------------------------------
00405 // -------------- A GENERAL MM ENGINE ---------------
00406 // --------------------------------------------------
00407 
00409 class MMengine: public engine
00410 {
00411 protected:
00413         MMengine ()
00414         {
00415                 return;
00416         }
00417 
00419         ~MMengine ()
00420         {
00421                 return;
00422         }
00423 
00424 public:
00426         virtual int speed () const = 0;
00427 
00429         bool dimsupported (int dim) const
00430         {
00431                 return (dim == embeddingDim);
00432         }
00433 
00436         int memory (const cubfile &X) const;
00437 
00439         bool relative () const
00440         {
00441                 return false;
00442         }
00443 
00445         bool elementary () const
00446         {
00447                 return false;
00448         }
00449 
00451         bool spacewrapping () const
00452         {
00453                 return false;
00454         }
00455 
00457         virtual void homology (const cubfile &x,
00458                 algstruct<chomp::homology::integer> &h) const = 0;
00459 
00461         void homology (const cubfile &x, const cubfile &y,
00462                 algstruct<chomp::homology::integer> &h) const
00463         {
00464                 throw "The MM* engines do not support relative homology.";
00465         }
00466 
00468         virtual const char *name () const = 0;
00469 
00471         virtual std::ostream &describe (std::ostream &out) const = 0;
00472 
00473 protected:
00474 }; /* class MMengine */
00475 
00476 
00477 // --------------------------------------------------
00478 // ------------------ MM_CR ENGINE ------------------
00479 // --------------------------------------------------
00480 
00482 class MM_CRengine: public MMengine
00483 {
00484 protected:
00486         MM_CRengine ()
00487         {
00488                 return;
00489         }
00490 
00492         ~MM_CRengine ()
00493         {
00494                 return;
00495         }
00496 
00497 public:
00499         int speed () const
00500         {
00501                 return 5000;
00502         }
00503 
00505         bool dimsupported (int dim) const
00506         {
00507                 return ((dim == embeddingDim) || ((dim >= 2) && (dim <= 4)));
00508         }
00509 
00511         void homology (const cubfile &x,
00512                 algstruct<chomp::homology::integer> &h) const;
00513 
00515         const char *name () const
00516         {
00517                 return "MM_CR";
00518         }
00519 
00521         std::ostream &describe (std::ostream &out) const;
00522 
00524         static MM_CRengine eng;
00525 
00526 }; /* class MM_CRengine */
00527 
00528 
00529 // --------------------------------------------------
00530 // ------------------ MM_AR ENGINE ------------------
00531 // --------------------------------------------------
00532 
00534 class MM_ARengine: public MMengine
00535 {
00536 protected:
00538         MM_ARengine ()
00539         {
00540                 return;
00541         }
00542 
00544         ~MM_ARengine ()
00545         {
00546                 return;
00547         }
00548 
00549 public:
00551         int speed () const
00552         {
00553                 return 70;
00554         }
00555 
00557         bool dimsupported (int dim) const
00558         {
00559                 return ((dim == embeddingDim) || ((dim >= 2) && (dim <= 4)));
00560         }
00561 
00563         void homology (const cubfile &x,
00564                 algstruct<chomp::homology::integer> &h) const;
00565 
00567         const char *name () const
00568         {
00569                 return "MM_AR";
00570         }
00571 
00573         std::ostream &describe (std::ostream &out) const;
00574 
00576         static MM_ARengine eng;
00577 
00578 }; /* class MM_ARengine */
00579 
00580 
00581 // --------------------------------------------------
00582 // ----------------- MM_ASLT ENGINE -----------------
00583 // --------------------------------------------------
00584 
00586 class MM_ASLTengine: public MMengine
00587 {
00588 protected:
00590         MM_ASLTengine ()
00591         {
00592                 return;
00593         }
00594 
00596         ~MM_ASLTengine ()
00597         {
00598                 return;
00599         }
00600 
00601 public:
00603         int speed () const
00604         {
00605                 return 1000;
00606         }
00607 
00609         void homology (const cubfile &x,
00610                 algstruct<chomp::homology::integer> &h) const;
00611 
00613         const char *name () const
00614         {
00615                 return "MM_ASLT";
00616         }
00617 
00619         std::ostream &describe (std::ostream &out) const;
00620 
00622         static MM_ASLTengine eng;
00623 
00624 }; /* class MM_ASLTengine */
00625 
00626 
00627 } // namespace homengin
00628 } // namespace chomp
00629 
00630 #endif // _CAPD_HOMENGIN_ENGINES_H_ 
00631 
00633