本文整理汇总了C++中graph_t::create_subgraph方法的典型用法代码示例。如果您正苦于以下问题:C++ graph_t::create_subgraph方法的具体用法?C++ graph_t::create_subgraph怎么用?C++ graph_t::create_subgraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_t
的用法示例。
在下文中一共展示了graph_t::create_subgraph方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LowStretchSpanningTreeHelper
//#undef __FUNCT__
//#define __FUNCT__ "LowStretchSpanningTreeHelper"
void LowStretchSpanningTreeHelper(graph_t& g,const int root,const float alpha,
graph_t& h)//,int perm[])
{
int n,i,j,k;
std::vector<int> size,x,y;
std::vector<std::vector<int> > idx;
int ierr;
// PetscFunctionBegin;
weight_map_t edge_weight_g = get(edge_weight_t(),g);
// VertexWeight vertex_weight_h = get(vertex_weight_t(),h);
n = num_vertices(g);
if (n > 2) {
ierr = StarDecomp(g,root,1.0/3.0,alpha,k,size,idx,x,y);
j = 0;
for (i=1;i<=k;i++) {
graph_t& g1 = g.create_subgraph(idx[i].begin(),idx[i].end());
graph_t& h1 = h.create_subgraph(idx[i].begin(),idx[i].end());
LowStretchSpanningTreeHelper(g1,g1.global_to_local(g.local_to_global(x[i-1])),alpha,h1);//,perm+j);
j += size[i];
}
graph_t& g1 = g.create_subgraph(idx[0].begin(),idx[0].end());
graph_t& h1 = h.create_subgraph(idx[0].begin(),idx[0].end());
LowStretchSpanningTreeHelper(g1,g1.global_to_local(g.local_to_global(root)),alpha,h1);//,perm+j);
for (i=0;i<k;i++) {
float w = get(edge_weight_g,edge(x[i],y[i],g).first);
add_edge(x[i],y[i],w,h);
// put(vertex_weight_h,x[i],get(vertex_weight_h,x[i])+w);
// put(vertex_weight_h,y[i],get(vertex_weight_h,y[i])+w);
}
} else if (n == 2) {
graph_traits<graph_t>::edge_descriptor e = *(out_edges(root,g).first);
int t = target(e,g);
float w = get(edge_weight_g,e);
add_edge(root,t,w,h);
// put(vertex_weight_h,root,get(vertex_weight_h,root)+w);
// put(vertex_weight_h,t,get(vertex_weight_h,t)+w);
// perm[0] = g.local_to_global(t);
// perm[1] = g.local_to_global(root);
} else /* n == 1 */ {
// perm[0] = g.local_to_global(root);
}
//return 0;
}
示例2: biconnected_components
size_t biconnected_components(graph_t& g, vector<graph_t*>& bicomponents) {
map< edge_descriptor_t, unsigned > bicomponent_edges;
vector<vertex_discripter_t> articulation_points;
articulation_points.reserve(num_vertices(g));
int n = biconnected_components(g,
make_assoc_property_map(bicomponent_edges),
back_inserter(articulation_points) ).first;
int o = bicomponents.size();
for (int i=0; i<n; i++)
bicomponents.push_back( &(g.create_subgraph()) );
graph_traits<graph_t>::edge_iterator e, e_end;
for (tie(e, e_end) = edges(g); e != e_end; ++e) {
add_vertex_once( source(*e,g), *bicomponents[o+bicomponent_edges[*e]] );
add_vertex_once( target(*e,g), *bicomponents[o+bicomponent_edges[*e]] );
}
// cout << "Graph #" << ... << " : " << get(graph_name, g);
// cout << " |V|=" << num_vertices(g) << endl;
// cout << " |Component|=" << bicomponents.size() << endl;
vector<vertex_discripter_t>::iterator v,v_end;
cout << "Art.pts.\tComponents\n";
// cout << articulation_points.size() << endl;
for (v=articulation_points.begin(), v_end=articulation_points.end();
v != v_end; v++) {
cout << get(&vertex_properties::id, g, *v) << "\t\t";
for (int i=0; i<n; i++)
if ((bicomponents[o+i]->find_vertex(*v)).second)
cout << ' ' << o+i << ' ';
cout << endl;
}
return n;
}