int main(int argc, char* argv[]) { int topK; if (argc != 5 || sscanf(argv[4], "%d", &topK) != 1) { cerr << argc << endl; for (int i = 1; i < argc; ++ i) { cerr << argv[i] << endl; } fprintf(stderr, "[usage] <training/testing data, csv format> <selected rules> <new training/testing data, csv format> <top-K>\n"); return -1; } //cerr << "top-K = " << topK << endl; int dimension = loadFeatureMatrix(argv[1]); Rules rules; rules.load(argv[2]); rules.resize(topK); FILE* out = tryOpen(argv[3], "w"); fprintf(out, "label"); for (int i = 0; i < rules.size(); ++ i) { fprintf(out, ",rule_%s", rules[i].showup().c_str()); } fprintf(out, "\n"); vector<int> sum(rules.size(), 0); for (int i = 0; i < train.size(); ++ i) { fprintf(out, "%d", (int)trainY[i]); for (int j = 0; j < rules.size(); ++ j) { int sat = rules[j].isSatisfiedBy(train[i]); fprintf(out, ",%d", sat); sum[j] += sat; } fprintf(out, "\n"); } fclose(out); string filename = argv[1]; if (filename.find("train") != -1) { bool flag = false; for (int i = 0; i < rules.size(); ++ i) { if (rules[i].satisfiedTrainings.size() != sum[i]) { fprintf(stderr, "[Warning] rule %d, %d v.s. %d\n", i, rules[i].satisfiedTrainings.size(), sum[i]); flag = true; } } if (!flag) { //fprintf(stderr, "Self-check passed!\n"); ; } else { fprintf(stderr, "Oooooooooooooooooops! You found some troubles!\n"); } } return 0; }
void RulesList::load() { foreach(const QString filename, m_filenames.split(',') ) { qDebug() << "Loading rules from:" << filename; Rules *rules = new Rules(filename); m_rules.append(rules); rules->load(); m_allrepositories.append(rules->repositories()); QList<Rules::Match> matchRules = rules->matchRules(); m_allMatchRules.append( QList<Rules::Match>(matchRules)); } }
int Rules::loadAllRules() { vector<string> rulesFiles = JFileSystem::GetInstance()->scanfolder("rules"); for (size_t i = 0; i < rulesFiles.size(); ++i) { Rules * rules = NEW Rules(); if (rules->load(rulesFiles[i])) { RulesList.push_back(rules); } else { SAFE_DELETE(rules); } } //Kind of a hack here, we sort Rules alphabetically because it turns out to be matching // The historical order of Game modes: Classic, Momir Basic, Random 1, Random 2, Story std::sort(RulesList.begin(),RulesList.end(),RulesMenuCmp_); return 1; }