基于Pawlak属性重要度的属性约简算法源码代码.docx
- 文档编号:29533340
- 上传时间:2023-07-24
- 格式:DOCX
- 页数:36
- 大小:19.82KB
基于Pawlak属性重要度的属性约简算法源码代码.docx
《基于Pawlak属性重要度的属性约简算法源码代码.docx》由会员分享,可在线阅读,更多相关《基于Pawlak属性重要度的属性约简算法源码代码.docx(36页珍藏版)》请在冰豆网上搜索。
基于Pawlak属性重要度的属性约简算法源码代码
大概一年前写代码实现了这个算法,今天有人问我要,在这里贴出来好了。
具体算法思路我也忘了,但是代码应该还算清晰。
只需要事先了解下STL。
viewplaincopytoclipboardprint?
/*测试数据
21/10X1X2X3X4X5X6X7X8X9y
U1c6yEmhhamm
U2c6nEmmhmamm
U3c6nEmhhmamm
U4c4yEmhhmalh
U5c6nEmmmmamm
U6c6nBmmmahelo
U7c6nEmmhmahelo
U8s4nBsmhlomalh
U9c4nBsmhlomamm
U10c4nBsmhmamm
U11s4nEsmhlomalh
U12s4nEmmmmamh
U13c4nBmmmmamm
U14s4yEsmhhmamh
U15s4nBsmmlomamh
U16c4yEmmhmamm
U17c6nEmmhamm
U18c4nEmmhamm
U19s4nEsmhmmamh
U20c4nEsmhmmamh
U21c4nBsmhmmamm
*/
#include
#include
#include
#include
#include
#include
usingnamespacestd;
#defineDATA_FILE_NAME"../data.txt"
#defineDEF_ATTR_CNT10
#defineDEF_OBJ_CNT21
intg_attr_cnt=0;
intg_obj_cnt=0;
classobject;
vector
vector
vector
vector
vector
vector
vector
voidclr_mask(conststring&attr)
{
inti=0;
for(i=0;i { if(attr==g_attr_set[i]) g_mask[i]=false; else g_mask[i]=true; } } voidset_mask() { inti=0; for(i=0;i { g_mask[i]=true; } } voidset_mask_set(vector { inti=0,j=0; boolfound=false; for(i=0;i { found=false; for(j=0;j { if(g_attr_set[i]==str_set[j]) { found=true; break; } } if(found) g_mask[i]=true; else g_mask[i]=false; } } classobject{ public: vector stringobj_name; public: object(conststring&name): obj_name(name) { attr_val.reserve(DEF_ATTR_CNT); } ~object() {} booloperator==(constobject&r_obj)const { boolres=true; inti=0; for(i=0;i { if(g_mask[i]) res&=(attr_val[i]==r_obj.attr_val[i]); if(false==res) break; } returnres; } }; voidread_data() { stringstrTmp; ifstreamdata_in(DATA_FILE_NAME,ifstream: : in); inti=0,j=0; object*p_obj=NULL; g_attr_set.reserve(DEF_ATTR_CNT); g_mask.reserve(DEF_ATTR_CNT); g_obj_set.reserve(DEF_OBJ_CNT); //readobjectcount,andattrcount data_in>>strTmp; g_obj_cnt=atoi(strTmp.substr(0,strTmp.find("/")).c_str()); g_attr_cnt=atoi(strTmp.substr(strTmp.find("/")+1,strTmp.length()).c_str()); for(i=0;i { data_in>>strTmp; g_attr_set.push_back(strTmp); g_mask.push_back(true); } for(i=0;i { data_in>>strTmp; p_obj=newobject(strTmp); for(j=0;j { data_in>>strTmp; p_obj->attr_val.push_back(strTmp); } //addobject g_obj_set.push_back(p_obj); } //closefile data_in.close(); } voidprint_data() { inti=0,j=0; cout< for(i=0;i { cout< : left)< if(i cout<<""; } cout< cout<<"-------------------------------------------------------------------------"< for(i=0;i { cout< for(j=0;j { cout< : left)< if(j cout< } cout< } } voidclear_data() { inti=0; for(i=0;i { deleteg_obj_set[i]; g_obj_set[i]=NULL; } } voidclear_ind_set(vector { vector while(! ind_set.empty()) { tmp=ind_set.back(); deletetmp; tmp=NULL; ind_set.pop_back(); } } voidapp_exit() { clear_ind_set(g_ind_c_set); clear_ind_set(g_ind_b_set); } voidadd_obj_to_ind_set(vector { vector inti=0; boolfound=false; for(i=0;i { if((*p_obj)==*((*ind_set[i])[0])) { found=true; ind_set[i]->push_back(p_obj); break; } } if(! found) { vec_tmp=newvector vec_tmp->push_back(p_obj); ind_set.push_back(vec_tmp); } } boolobj_set_equal(vector { if(l_obj_set.size()! =r_obj_set.size()) returnfalse; boolfound=false; inti=0,j=0; for(i=0;i { found=false; for(j=0;j { if(l_obj_set[i]==r_obj_set[j]) { found=true; break; } } if(! found) returnfalse; } returntrue; } boolind_set_equal(vector { if(l_ind_set.size()! =r_ind_set.size()) returnfalse; boolfound=false; inti=0,j=0; for(i=0;i { found=false; for(j=0;j { if(obj_set_equal(*l_ind_set[i],*r_ind_set[j])) { found=true; break; } } if(! found) returnfalse; } returntrue; } voidcore() { //getIND(C) inti=0; vector set_mask(); for(i=0;i { add_obj_to_ind_set(g_ind_c_set,g_obj_set[i]); } intj=0; for(i=0;i { clear_ind_set(ind_set_tmp); clr_mask(g_attr_set[i]); //getIND(C-{xi}) for(j=0;j { add_obj_to_ind_set(ind_set_tmp,g_obj_set[j]); } if(! ind_set_equal(g_ind_c_set,ind_set_tmp)) g_core_set.push_back(g_attr_set[i]); } clear_ind_set(ind_set_tmp); //alreadygetcore cout<<"-------------------------------------------------------------------------"< cout<<"core: \n{"; for(i=0;i { //copytoB g_b_set.push_back(g_core_set[i]); cout< if(i cout<<","; } cout<<"}\n"; } boolattr_set_equal(vector { if(l_attr_set.size()! =r_attr_set.size()) returnfalse; inti=0,j=0; boolfound=false; for(i=0;i { found=false; for(j=0;j { if(l_attr_set[i]==r_attr_set[j]) { found=true; break; } } if(! found) returnfalse; } returntrue; } voidattr_set_sub(vector { inti=0,j=0; boolfound=false; for(i=0;i { found=false; for(j=0;j { if(l_attr_set[i]==r_attr_set[j]) { found=true; break; } } if(! found) res_set.push_back(l_attr_set[i]); } } voidget_ind_set(vector { inti=0; //getINDset set_mask_set(mask_set); for(i=0;i { add_obj_to_ind_set(res_ind_set,g_obj_set[i]); } } voidattr_set_copy(vector { inti=0; dst_attr_set.clear(); for(i=0;i { dst_attr_set.push_back(src_attr_set[i]); } } voidreduction() { vector vector vector vector intmax=0,max_idx=0,max_cnt=0; inti=0,j=0; //getIND(B) get_ind_set(g_b_set,g_ind_b_set); while(! ind_set_equal(g_ind_c_set,g_ind_b_set)) { if(attr_set_equal(g_b_set,g_attr_set)) break; c_sub_b.clear(); attr_set_sub(g_attr_set,g_b_set,c_sub_b); max_sig.clear(); for(i=0;i { attr_set_copy(b_set_tmp,g_b_set); b_set_tmp.push_back(c_sub_b[i]); clear_ind_set(ind_set_tmp); get_ind_set(b_set_tmp,ind_set_tmp); max_sig.push_back(ind_set_tmp.size()-g_ind_b_set.size()); } //now,processmax_sig max=max_sig[0]; max_idx=0; max_cnt=0; for(j=1;j { if(max_sig[j]>max) { max=max_sig[j]; max_idx=j; max_cnt=1; } elseif(max==max_sig[j]) { max_cnt++; } } g_b_set.push_back(c_sub_b[max_idx]); if(attr_set_equal(g_b_set,g_attr_set)) break; //getIND(B) clear_ind_set(g_ind_b_set); get_ind_set(g_b_set,g_ind_b_set); } clear_ind_set(ind_set_tmp); //getreductionnow cout<<"-------------------------------------------------------------------------"< cout<<"reductionset: \n{"; for(i=0;i { cout< if(i cout<<","; } cout<<"}\n"; } voidprint_red_data() { inti=0,j=0; set_mask_set(g_b_set); cout<<"-------------------------------------------------------------------------"< cout<<""; for(i=0;i { if(g_mask[i]) { cout< : left)< if(i cout<<""; } } cout< cout<<"-------------------------------------------------------------------------"< for(i=0;i { cout< fo
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 Pawlak 属性 重要 算法 源码 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)