Main Page | Modules | Alphabetical List | Compound List | File List | Compound Members | Related Pages

machine_storage.hpp

00001 #ifndef kellett_machine_storage_header
00002 #define kellett_machine_storage_header
00003 
00004 /*Authored 2003    by Owen Kellett, Undergraduate Research
00005 (Advisor: Professor Bram van Heuveln)
00006 
00007 
00008 This  file is part of the   "Generic Turing Machine Implementation for
00009 Use in the Exploration of the Busy Beaver Problem".
00010 
00011 The "Generic Turing Machine Implementation for  Use in the Exploration
00012 of the Busy Beaver Problem" is free  software; you can redistribute it
00013 and/or modify it under the terms of the  GNU General Public License as
00014 published   by the Free Software Foundation;   either version 2 of the
00015 License, or (at your option) any later version.
00016 
00017 This programme is distributed in the hope that it  will be useful, but
00018 WITHOUT    ANY  WARRANTY;  without   even  the    implied warranty  of
00019 MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PURPOSE.  See  the  GNU
00020 General Public License for more details.
00021 
00022 You should have received   a copy of  the  GNU General Public  License
00023 along  with  this   programme; if  not,  write   to the Free  Software
00024 Foundation, Inc., 59  Temple Place, Suite  330, Boston, MA  02111-1307
00025 USA (or visit http://www.fsf.org/licenses/licenses.html)
00026 
00027 Created as part of the Busy Beaver Project:
00028 Bram van Heuveln <heuveb@rpi.edu>
00029 Boleshaw Szymanski <szymansk@cs.rpi.edu>
00030 Selmer Bringsjord <selmer@rpi.edu>
00031 Carlos Varela <cvarela@cs.rpi.edu>
00032 Owen Kellett <kelleo@rpi.edu>
00033 Shailesh Kelkar <kelkas@rpi.edu>
00034 Kyle Ross <rossk2@rpi.edu>
00035 Rensselaer Reasoning Group
00036 Department of Cognitive Science
00037 Department of Computer Science
00038 Rensselaer Polytechnic Institute
00039 Troy, New York 12180
00040 U.S.A.
00041 */
00042 //implements a simple class for tracking statistics of turing machines during runs
00043 
00044 #include <fstream>
00045 #include <iostream>
00046 #include <string>
00047 #include <sys/stat.h>
00048 #include <sys/types.h>
00049 
00050 #include "turing_machine.hpp"
00051 #include "long_int.hpp"
00052 
00053 template <typename T>
00054 class machineStorage
00055 {
00056 public:
00057         //the reasons for elimination of machines
00058         enum reason{candidate=0, not_in_standard_position, holdout, simple_nonproductive, complex_nonproductive, empty_tape, first_write_1, first_move_right, backTracker, simpleLoop, subsetLoop, christmasTree, alternateChristmasTree, leaningChristmasTree, tripleSweepChristmasTree, quadrupleSweepChristmasTree, quintupleSweepChristmasTree, counter};
00059         enum machine_type{implicit_halt, explicit_halt};
00060         enum bestType{ones=0, transitions};
00061         //names of reasons for display ... this must be the same length as the enumerated reasons
00062         static const std::string names[];
00063         static const std::string bestNames[];
00064         private:
00065                 //this must match the length of the enumerated reasons
00066                 static const int num_reasons=18;
00067         public:
00068 
00069         //initialise all counts to 0
00070         machineStorage(std::string d, bool o)
00071         :counts(num_reasons, 0), directory(d), onlyStoreHoldouts(o), championCounts(2,0)
00072         {}
00073 
00074         //print out the stats
00075         void print(const turing_machine<T> &machine, reason why)
00076         {
00077                 if(!onlyStoreHoldouts || why == holdout)
00078                 {
00079                         std::string fileName = directory + names[why] + counts[why].toString() + ".tmo";
00080                         std::ofstream file(fileName.c_str());
00081                         machine.printTMO(file);
00082                         file.close();
00083                         counts[why]+=1;
00084                 }
00085         }
00086         void printChampion(const turing_machine<T> &machine, bestType why, long_int value)
00087         {
00088                 std::string fileName = directory + bestNames[why] + ".tmo";
00089                 std::ofstream file(fileName.c_str());
00090                 machine.printTMO(file);
00091                 file.close();
00092 
00093                 std::string fileName2 = directory + bestNames[why] + "Progression/" + value.toString() + "-championFound" + championCounts[why].toString() + ".tmo";
00094                 std::ofstream file2(fileName2.c_str());
00095                 machine.printTMO(file2);
00096                 file2.close();
00097                 championCounts[why]+=1;
00098         }
00099 private:
00100         std::string directory;
00101         std::vector<long_int> counts;
00102         std::vector<long_int> championCounts;
00103         bool onlyStoreHoldouts;
00104 };
00105 
00106 template <typename T>
00107 const std::string machineStorage<T>::names[]={"halterCandidate/", "nonStandardHalt/", "holdout/", "ssTransition/", "ssPrimeTransition/", "emptyTape/", "firstWrite1/", "firstMoveR/", "backTracker/", "simpleLoop/", "subsetLoop/", "christmasTree/", "alternateChristmasTree/", "leaningChristmasTree/", "tripleSweepChristmasTree/", "quadrupleSweepChristmasTree/", "quintupleSweepChristmasTree/", "counter/"};
00108 template <typename T>
00109 const std::string machineStorage<T>::bestNames[]={"champion", "transitionsChampion"};
00110 
00111 template <typename T>
00112 class championLog
00113 {
00114 public:
00115         enum bestType{ones=0, transitions};
00116         static const std::string bestNames[];
00117 
00118         championLog(std::string d)
00119         :directory(d), counts(2,0)
00120         {
00121                 for(int j = 0; j < 2; j++)
00122                 {
00123                         std::string dirName1 = directory + bestNames[j] + "Progression";
00124                         if(mkdir(dirName1.c_str(), 0744) == -1)
00125                                 std::cerr << "problem creating progression directory" << std::endl;
00126                 }
00127         }
00128 
00129         void printChampion(const turing_machine<T> &machine, bestType why, long_int value)
00130         {
00131                 std::string fileName = directory + bestNames[why] + ".tmo";
00132                 std::ofstream file(fileName.c_str());
00133                 machine.printTMO(file);
00134                 file.close();
00135 
00136                 std::string fileName2 = directory + bestNames[why] + "Progression/" + value.toString() + "-championFound" + counts[why].toString() + ".tmo";
00137                 std::ofstream file2(fileName2.c_str());
00138                 machine.printTMO(file2);
00139                 file2.close();
00140                 counts[why]+=1;
00141         }
00142 
00143 private:
00144         std::string directory;
00145         std::vector<long_int> counts;
00146 };
00147 
00148 template <typename T>
00149 const std::string championLog<T>::bestNames[]={"champion", "transitionsChampion"};
00150 
00151 template <typename T>
00152 class outputLog
00153 {
00154 public:
00155         outputLog(std::string d)
00156         :directory(d), counts(0)
00157         {}
00158 
00159         void print(const turing_machine<T> &machine)
00160         {
00161                 std::string fileName = directory + counts.toString() + ".tmo";
00162                 std::ofstream file(fileName.c_str());
00163                 machine.printTMO(file);
00164                 file.close();
00165                 counts+=1;
00166         }
00167 
00168 private:
00169         std::string directory;
00170         long_int counts;
00171 };
00172 
00173 
00174 #endif

Generated on Thu Nov 20 00:17:31 2003 for BusyBeaver by doxygen 1.3.3