00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00031 #ifndef MINER_H
00032 #define MINER_H
00033
00034 #include<cstring>
00035 #include<ctime>
00036 using namespace std;
00037
00038
00039
00040 #include "cnull.h"
00041 #include "Monitorable.h"
00042 #include "BinaryMatrix.h"
00043
00050 class Miner: public Monitorable
00051 {
00052 protected:
00053
00054 BinaryMatrix* bm;
00055
00056
00057 vector<ofstream*> pborder_out;
00058
00059
00060
00061
00062
00063
00064 ofstream time_out;
00065
00066
00067 ofstream level_out;
00068
00069
00070 double starttime;
00071
00072
00073 char errmsg[512];
00074
00075
00076
00078
00079
00080
00081
00082
00083
00084
00085
00086
00088 virtual ofstream& pborder(unsigned int level)
00089 {
00090
00091
00092 while (pborder_out.size() <= level)
00093 {
00094 char filename[512];
00095 sprintf(filename, "%s_pborders_%d.dat",
00096 bm->getFilename().c_str(), pborder_out.size() + 1);
00097 pborder_out.push_back(new ofstream(filename, ofstream::out));
00098 }
00099
00100
00101 return *pborder_out[level];
00102 }
00103
00105
00106
00107
00108
00109
00110
00111
00113 virtual void print(const Itemset& is, ostream& out) const
00114 {
00115 if (is.isEmpty())
00116 {
00117 return;
00118 }
00119
00120 out << is[0] << ':' << bm->getColname(is[0]);
00121 for (unsigned int i = 1; i < is.getSize(); i++)
00122 {
00123 out << ", " << is[i] << ':' << bm->getColname(is[i]);
00124 }
00125 }
00126
00128
00129
00130
00131
00132
00133
00134
00136 virtual void print(const Itemset* is, ostream& out) const
00137 {
00138 print(*is, out);
00139 }
00140
00141 virtual void analyzeHelper() = 0;
00142
00143 public:
00145
00146
00147
00148
00149
00151 Miner(BinaryMatrix* bm = NULL): Monitorable()
00152 {
00153 this->bm = bm;
00154 errmsg[0] = '\0';
00155 }
00156
00158
00159
00160
00161
00162
00164 Miner(const Miner& src)
00165 {
00166
00167 }
00168
00170
00172 virtual ~Miner()
00173 {
00174
00175 }
00176
00178
00179
00180
00181
00182
00183
00184
00185
00187 virtual Miner& operator =(const Miner& rhs)
00188 {
00189 bm = rhs.bm;
00190 status_out = rhs.status_out;
00191 Monitorable::operator =(rhs);
00192 strcpy(errmsg, rhs.errmsg);
00193 starttime = rhs.starttime;
00194 return *this;
00195 }
00196
00198
00199
00200
00201
00203 virtual const char* analyze()
00204 {
00205
00206 if (!bm)
00207 {
00208 sprintf(errmsg, "blah!");
00209 return errmsg;
00210 }
00211 if (!bm || !bm->isOpen())
00212 {
00213 sprintf(errmsg, "No file is open for reading");
00214 return errmsg;
00215 }
00216
00217
00218
00219
00220 time_out.open((bm->getFilename() + "_time.dat").c_str(),
00221 ofstream::out);
00222 level_out.open((bm->getFilename() + "_level.dat").c_str(),
00223 ofstream::out);
00224 *status_out << "There are " << bm->getHeight() <<
00225 " rows of data." << endl;
00226 *status_out << "There are " << bm->getWidth() <<
00227 " columns of data." << endl;
00228 starttime = clock();
00229
00230
00231
00232 analyzeHelper();
00233
00234
00235 double totaltime = (clock() - starttime)/CLOCKS_PER_SEC;
00236 time_out << totaltime << endl;
00237 *status_out << "Finished in " << totaltime << " miliseconds." <<
00238 endl;
00239
00240
00241 for (unsigned int i = 0; i < pborder_out.size(); i++)
00242 {
00243 pborder_out[i]->close();
00244 delete pborder_out[i];
00245 }
00246 pborder_out.clear();
00247
00248 time_out.close();
00249 level_out.close();
00250 if (strlen(errmsg))
00251 {
00252 return errmsg;
00253 }
00254 return NULL;
00255 }
00256
00258
00259
00260
00261
00262
00264 virtual void setBinaryMatrix(BinaryMatrix* bm)
00265 {
00266 this->bm = bm;
00267 }
00268
00270
00271
00272
00273
00274
00275
00277 virtual void transpose(const char* coltype)
00278 {
00279 bm->transpose(coltype);
00280 }
00281 };
00282
00283 #endif