基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx

上传人:b****9 文档编号:26024759 上传时间:2023-06-17 格式:DOCX 页数:36 大小:19.84KB
下载 相关 举报
基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx_第1页
第1页 / 共36页
基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx_第2页
第2页 / 共36页
基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx_第3页
第3页 / 共36页
基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx_第4页
第4页 / 共36页
基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx_第5页
第5页 / 共36页
点击查看更多>>
下载资源
资源描述

基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx

《基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx》由会员分享,可在线阅读,更多相关《基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx(36页珍藏版)》请在冰豆网上搜索。

基于pawlak属性重要度的属性约简算法源码代码本科学位论文.docx

基于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;

vectorg_attr_set;

vectorg_mask;

vectorg_obj_set;

vectorg_core_set;

vectorg_b_set;

vector*>g_ind_c_set;

vector*>g_ind_b_set;

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&str_set)

{

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:

vectorattr_val;

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<obj_name<<"";

for(j=0;j

{

cout<

:

left)<attr_val[j];

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*>&ind_set)

{

vector*tmp=NULL;

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*>&ind_set,object*p_obj)

{

vector*vec_tmp=NULL;

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&l_obj_set,vector&r_obj_set)

{

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*>&l_ind_set,vector*>&r_ind_set)

{

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*>ind_set_tmp;

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&l_attr_set,vector&r_attr_set)

{

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&l_attr_set,vector&r_attr_set,vector&res_set)

{

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&mask_set,vector*>&res_ind_set)

{

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&dst_attr_set,vector&src_attr_set)

{

inti=0;

dst_attr_set.clear();

for(i=0;i

{

dst_attr_set.push_back(src_attr_set[i]);

}

}

voidreduction()

{

vectorb_set_tmp;

vectorc_sub_b;

vectormax_sig;

vector*>ind_set_tmp;

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<obj_name<<"";

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 商业计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1