00001 #ifndef kellett_machine_storage_header
00002 #define kellett_machine_storage_header
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
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
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
00062 static const std::string names[];
00063 static const std::string bestNames[];
00064 private:
00065
00066 static const int num_reasons=18;
00067 public:
00068
00069
00070 machineStorage(std::string d, bool o)
00071 :counts(num_reasons, 0), directory(d), onlyStoreHoldouts(o), championCounts(2,0)
00072 {}
00073
00074
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