📄 main.cpp
字号:
#include <iostream>
#include <time.h>
#include "Preprocessor.h"
#include "Compressor.h"
#include "AssRule.h"
#include "Config.h"
#include "StatsAnalyzer.h"
#include "Predictor.h"
using namespace std;
int main(int argc, char** argv) {
time_t startTime = time(NULL);
//cout << "Started" << endl;
try {
/*
Preprocessor* processor = new Preprocessor();
vector<Record>* fatalList = processor->getFatalList();
//vector<Record>* nonFatalList = processor->getNonFatalList();
Compressor* compressor = new Compressor();
compressor->compressList(fatalList);
//compressor->compressList(nonFatalList);
delete compressor;
delete processor;
/*/
/*
//this->dataFileName = "..\\logs\\ar.txt";
//this->dataFileName = "..\\logs\\retail1.dat";
//this->dataFileName = "..\\logs\\failure.dat";
//cout << "argv1: " << argv[1] << "; argv2: " << argv[2] << " argv3: " << argv[3] << endl;
int minSupport = 65;
float confidence = 0.4;
int numFolds = 5;
const char* dataFileName = "..\\logs\\sdsc_compress5\fail1200.dat";
const char* testFileName = dataFileName;
if (argv[1] != 0) {
dataFileName = argv[1];
}
if (atoi(argv[2]) > 0) {
minSupport = atoi(argv[2]);
}
if (atof(argv[3]) > 0) {
confidence = atof(argv[3]);
}
if (atoi(argv[4]) >= 1) {
numFolds = atoi(argv[4]);
}
if (argv[5] != 0) {
testFileName = argv[5];
}
Config::getInstance()->setParameters(minSupport, confidence);
cout << "starting ARules for learn: " << dataFileName << endl;
cout << "Support Confidence Tp Fp TotRec Single Precision Recall" << endl;
cout << "------- ---------- ---- ---- ------ ------ --------- ------" << endl;
int recNum = 0;
string line;
try {
ifstream inFile(dataFileName, ios::in);
if (inFile.is_open()) {
while (!inFile.eof()) {
getline(inFile, line);
recNum++;
}
inFile.close();
} else {
throw AppException(9, "unable to open Input file", __FILE__, __LINE__);
}
} catch (exception &e) {
throw AppException(9, string("abnormal error in processing Input file - ") + string(e.what()), __FILE__, __LINE__);
}
int recPerFold = recNum/numFolds;
int currFold, fromRec, toRec;
for (currFold = 0; currFold < numFolds; currFold++) {
fromRec = (currFold * recPerFold) + 1;
if ((currFold + 1) == numFolds) {
toRec = recNum;
} else {
toRec = (currFold + 1) * recPerFold;
}
//cout << currChunk << " chunk for testing. fromRec: " << fromRec << " toRec: " << toRec << endl;
AssRule* ar = new AssRule(dataFileName, fromRec, toRec);
//AssRule* ar = new AssRule(dataFileName, testFileName, fromRec, toRec);
ar->runEngine();
delete ar;
}
*/
/*
StatsAnalyzer* statsAnalyzer = new StatsAnalyzer();
delete statsAnalyzer;
*/
int minSupport = 2;
float confidence = 0.6;
int numFolds = 5;
float probThreshold = 0.85;
const char* dataFileName = "..\\logs\\anl_compress5\\fail900.dat";
const char* testFileName = "..\\logs\\anl_compress5\\fail900_test.dat";
const char* sortedEventsFileName = "..\\logs\\anl_compress5\\sortedEvents.dat";
if (argc > 1) {
if (argv[1] != 0) {
dataFileName = argv[1];
}
if (atoi(argv[2]) > 0) {
minSupport = atoi(argv[2]);
}
if (atof(argv[3]) > 0) {
confidence = atof(argv[3]);
}
if (argv[4] != 0) {
testFileName = argv[4];
}
if (atof(argv[5]) > 0) {
probThreshold = atof(argv[5]);
}
}
//cout << "before config" << endl;
Config::getInstance()->setParameters(minSupport, confidence, probThreshold);
//cout << "before predictor" << endl;
Predictor* p = new Predictor(dataFileName);
//cout << "initialized predictor" << endl;
//p->streamEvents(sortedEventsFileName);
//cout << "streamed events" << endl;
p->streamFailures(testFileName);
//cout << "streamed failures" << endl;
delete p;
} catch (AppException& e) {
cout << e.what() << endl;
return 1;
} catch (exception &e) {
cout << "Unknown Exception. Beyond me...Time to debug !!" << e.what() << endl;
return 2;
}
//cout << "Finished" << endl;
time_t finishTime = time(NULL);
cout << "Execution Time: " << (finishTime - startTime) << endl;
return 0;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -