本文整理汇总了C++中graph_t::local_to_global方法的典型用法代码示例。如果您正苦于以下问题:C++ graph_t::local_to_global方法的具体用法?C++ graph_t::local_to_global怎么用?C++ graph_t::local_to_global使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_t
的用法示例。
在下文中一共展示了graph_t::local_to_global方法的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: StarDecomp
//#undef __FUNCT__
//#define __FUNCT__ "LowStretchSpanningTreeHelper"
int StarDecomp(graph_t g,const int root,const float delta,const float epsilon,
int& k,std::vector<int>& size,std::vector<std::vector<int> >& idx,
std::vector<int>& x,std::vector<int>& y)
{
int n,m,edgesLeft;
//PetscErrorCode ierr;
//ShortestPathPriorityQueue pq;
// float radius;
std::vector<int> centerIdx;
//PQNode node;
// PetscFunctionBegin;
//printf("going to into ball cut segment\n");
graph_t& root_graph = g.is_root() ? g : g.root();
weight_map_t edge_weight_g = get(edge_weight,root_graph); // actually all property maps are same! so don't worry!
f_edges_t f_edges_g = get(edge_index, g);
vert_dist_t root_dist = get(vertex_distance, g);
n = num_vertices(g);
m = num_edges(g);
edgesLeft = m;
// std::vector<int>
// std::vector<int> pred(n,-1);
//std::vector<int> succ[n];
std::vector<int>::iterator i;
// float dist[n];
// std::vector<bool> taken(n,false);
// running dijkstra
float radius;
std::vector<vertex_descriptor> ordered_nodes(n);
int cntr = 0;
//std::vector<float> root_dist(n);
std::vector<int> pred(n, -1);
std::vector<int> color_map(n, WHITE);
//int num_root_edges = g.is_root() ? num_edges(g) : num_edges(g.root());
//printf("num_root_edges: %d\n", num_root_edges);
//std::vector<bool> fedges(num_root_edges);// turns out edge_index not local fedges(m, false);
p_comp_min_class comp(&root_dist);
identity_property_map ident;
PropertyMinQueue pq(n, comp, ident);
root_dist[root] = 0.0;
pred[root] = root;
pq.push(root);
//printf("about to go to dijkstra while loop\n");
while(!pq.empty())
{
//printf("top of while\n");
vertex_descriptor u = pq.top();
pq.pop();
color_map[u] = BLACK;
// put the edge that got us to u into fedges
vertex_descriptor pred_u = pred[u];
//radius = root_dist[u];
ordered_nodes[cntr++] = u;
if (pred_u != u)
{
edge_descriptor e = edge(pred_u, u, g).first;
put(f_edges_g, e, true);
}
//printf("after fedges\n");
adjacency_it i, i_end;
for (tie(i, i_end) = adjacent_vertices(u, g); i != i_end; i++)
{
vertex_descriptor v = *i;
if (color_map[v] == WHITE)
{
//printf("before pred[v]\n");
pred[v] = u;
//printf("before edge_weight_g; pred_u: %d, u: %d\n", pred_u, u);
root_dist[v] = root_dist[u] + 1.0/get(edge_weight_g, g.local_to_global(edge(u,v, g).first));
//printf("before color_map\n");
color_map[v] = GREY;
pq.push(v);
}
else if (color_map[v] == GREY)
{
float new_dist = root_dist[u] + 1.0/get(edge_weight_g, g.local_to_global(edge(u, v, g).first));
if (new_dist < root_dist[v])
{
root_dist[v] = new_dist;
pred[v] = u;
pq.update(v);
}
}
}
}
//printf("did dijkstra\n");
radius = root_dist[ordered_nodes.back()];
float min_radius = delta*radius;
//.........这里部分代码省略.........