Before preparing to do Hiho, on-line search about the largest independent set of graphs;
See a paper, said to be able to "the general graph of the minimum vertex cover set problem" of the hybrid greedy algorithm;
I look like a very good ah, ran to study the majority of days of this paper, found that the actual is a very general approximation algorithm, in special cases, the deviation is great;
After the implementation of the actual to do the problem, found that even samples are not, I thought the process where write down,
In a closer look, the graph produced by the sample is a very unfriendly case to this algorithm,
It seems to be in the algorithmic problem when used is not realistic, but at least a study of a paper, but also manually implemented;
Of course, this algorithm in the case of large-scale diagram, should have a good approximation, you can consider the use of certain scenarios;
Thesis connection clickhere;
Specific implementation:
1#include <cstdio>2#include <cstring>3#include <vector>4#include <queue>5#include <algorithm>6 #defineMAX 207 using namespacestd;8 intn,m;9 structedge{Ten intu,v; One }; A structpoint{ - intID; - intDegree,adj_degree; the }point[max]; -Vector<edge>E; -vector<int>G[max]; - intDegree[max],adj_degree[max];//degrees and adjacency degrees for each point + BOOLDel[max],vis[max]; - intv_cnt,vv_cnt,e_cnt; + voidInit_edge () A { at e.clear (); - for(intI=1; i<=n;i++) g[i].clear (); - } - voidAdd_edge (intUintv) - { - E.push_back (Edge) {u,v}); in E.push_back (Edge) {v,u}); - int_size=e.size (); toG[u].push_back (_size-2); +G[v].push_back (_size-1); - } the BOOLCMP (point A,point b) {returnA.adj_degree>B.adj_degree;} * intpretreat () $ {Panax Notoginseng for(intI=1; i<=n;i++) - { thePoint[i].degree=0; + if(Del[i])Continue; A for(intj=0, _size=g[i].size (); j<_size;j++) the { +edge& e=E[g[i][j]]; - if(!DEL[E.V]) point[i].degree++; $ } $ if(point[i].degree==0) del[i]=1; - } - for(intI=1; i<=n;i++) the { - if(Del[i])Wuyi { thePoint[i].adj_degree=0; - Continue; Wu } -Point[i].adj_degree=Point[i].degree; About for(intj=0, _size=g[i].size (); j<_size;j++) point[i].adj_degree+=Point[e[g[i][j]].v].degree; $printf"adj_degree[%d] =%d\n", i,point[i].adj_degree); - } -Sort (point+1, point+n+1, CMP); - } A voidMINVC_MGA (BOOLans[]) + { theMemset (Del,0,sizeof(del)); - for(intI=1; i<=n;i++) point[i].id=i; $E_cnt=0; the while(E_cnt <m) the { thememset (Vis,0,sizeof(Vis)); the pretreat (); -V_cnt=0; inVv_cnt=0; the for(intI=1; i<=n;i++)if(!del[i]) vv_cnt++; the for(intI=1; i<=n;i++) About { theprintf"del[%d]=%d vis[%d]\n", Point[i].id,del[point[i].id],point[i].id,vis[point[i].id]); the if(Del[point[i].id])Continue; the if(Vis[point[i].id])Continue; +printf"Now ans add:%d\n", point[i].id); -ans[point[i].id]=1;//add to the minimum vertex overlay set thedel[point[i].id]=1, vv_cnt--;Bayi for(intj=0, _size=g[point[i].id].size (); j<_size;j++) the { theedge& e=E[g[point[i].id][j]]; - if(DEL[E.V])Continue; -e_cnt++; the if(!VIS[E.V]) the { thevis[e.v]=1; thev_cnt++; - } the } the if(v_cnt>=vv_cnt) Break; the }94 } the } the the intMain ()98 { About while(SCANF ("%d%d\n", &n,&m)! =EOF) - {101 Init_edge ();102 for(intI=1, u,v;i<=m;i++)103 {104scanf"%d%d",&u,&v); the Add_edge (u,v);106 }107 BOOLans[n+5];108memset (ans,0,sizeof(ans));109 minvc_mga (ans); the for(intI=1; i<=n;i++) printf ("%d:%s\n", I,ans[i]?"YES":"NO");111 } the }113 /* the About the 1 Ten the 1 2117 1 7118 Ten119 7 - 7 3121 7 8122 8123 3 4124 4 9 the 8 9126 8127 9 - 5 9129 the the 5 6131 6 the */
A hybrid greedy algorithm (approximate algorithm) for solving the problem of minimum vertex cover set in general graphs