📄 ruleset.cpp
字号:
// RULESET.cpp: implementation of the RULESET class.////////////////////////////////////////////////////////////////////////#include "StdAfx.h"#include "DESCRIPTION.h"#include "TUPLE.h"#include "LITERAL.h"#include "RULE.h"#include "RULESET.h"#include "global.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////RULESET::RULESET(){}RULESET::~RULESET(){}/*bool RULESET::Satisfy(const TUPLE& tuple,double &confidence) const{ if(IsEmpty()) return false; double max_conf=-100.0; bool satisfied=false; for(POSITION pos=GetHeadPosition();pos!=NULL;GetNext(pos)) { if(GetAt(pos).Satisfy(tuple)) { if(max_conf<GetAt(pos).GetInfoGain()) max_conf=GetAt(pos).GetInfoGain(); satisfied=true; } } confidence=max_conf; return satisfied;}void RULESET::SetClass(int iClass){ m_Class=iClass; for(POSITION pos=GetHeadPosition();pos!=NULL;GetNext(pos)) { GetAt(pos).SetClass(iClass); }}void RULESET::WriteTo(FILE* stream) const{ fprintf(stream,"%d rules\n",GetCount()); fprintf(stream,"CLASS: %d\n",GetClass()); for(POSITION pos=GetHeadPosition();pos!=NULL;GetNext(pos)) { GetAt(pos).WriteTo(stream); } fprintf(stream,"END\n");}bool RULESET::ReadFrom(FILE* stream){ int nRules; if(fscanf(stream,"%d rules\n",&nRules)!=1) return false; if(fscanf(stream,"CLASS: %d\n",&m_Class)!=1) return false; for(int i=0;i<nRules;i++) { RULE rule; if(rule.ReadFrom(stream)) push_back(rule); } fscanf(stream,"END\n"); if(GetCount()!=nRules) { printf("Error: less rules than specified!"); return false; } return true; }*/void RULESET::WriteTo(CString filename) const{ FILE* fout=fopen(filename,"w"); for(const_iterator pos=begin();pos!=end();pos++) { pos->WriteTo(fout); } fclose(fout);}void RULESET::ReadFrom(CString filename){ clear(); FILE* fin=fopen(filename,"r"); int nRules=count_num_lines(fin); fclose(fin); fin=fopen(filename,"r"); for(int i=0;i<nRules;i++) { RULE rule; rule.ReadFrom(fin); push_back(rule); } fclose(fin);}void RULESET::AddRule(const RULE& rule){ bool existed=false; for(iterator pos=begin();pos!=end();pos++) { if(*pos == rule) {// rule.SetInfoGain(rule.GetInfoGain()+GetAt(pos).GetInfoGain());// SetAt(pos,rule); pos->SetInfoGain(pos->GetInfoGain()+rule.GetInfoGain()); return; } } RULE rule1=rule; if(!existed) push_back(rule1);}void RULESET::AddRuleByGain(const RULE& rule){ double gain=rule.GetInfoGain(); RULE r=rule; for(iterator pos=begin();pos!=end();pos++) { if(gain>=pos->GetInfoGain()) { insert(pos,r); return; } } push_back(r);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -