本文整理汇总了C++中graph_t::add_vertex方法的典型用法代码示例。如果您正苦于以下问题:C++ graph_t::add_vertex方法的具体用法?C++ graph_t::add_vertex怎么用?C++ graph_t::add_vertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_t
的用法示例。
在下文中一共展示了graph_t::add_vertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: randomgraph_construction
void randomgraph_construction(graph_t &g, size_t vertex_num, size_t edge_num, gBenchPerf_event & perf, int perf_group)
{
vector<pair<size_t,size_t> > edges;
for (size_t i=0;i<edge_num;i++)
{
edges.push_back(make_pair(rand()%vertex_num, rand()%vertex_num));
}
perf.open(perf_group);
perf.start(perf_group);
for (size_t i=0;i<vertex_num;i++)
{
vertex_iterator vit = g.add_vertex();
vit->set_property(vertex_property(i));
}
#ifdef SIM
SIM_BEGIN(true);
#endif
for (size_t i=0;i<edge_num;i++)
{
edge_iterator eit;
g.add_edge(edges[i].first, edges[i].second, eit);
#ifndef SIM
eit->set_property(edge_property(i));
#endif
}
#ifdef SIM
SIM_END(true);
#endif
perf.stop(perf_group);
}
示例2: parallel_randomgraph_construction
void parallel_randomgraph_construction(graph_t &g, size_t vertex_num, size_t edge_num)
{
vector<pair<size_t,size_t> > edges;
for (size_t i=0;i<edge_num;i++)
{
edges.push_back(make_pair(rand()%vertex_num, rand()%vertex_num));
}
for (size_t i=0;i<vertex_num;i++)
{
vertex_iterator vit = g.add_vertex();
vit->set_property(vertex_property(i));
}
uint64_t chunk = (unsigned)ceil(edge_num/(double)threadnum);
#pragma omp parallel num_threads(threadnum)
{
unsigned tid = omp_get_thread_num();
unsigned start = tid*chunk;
unsigned end = start + chunk;
if (end > edge_num) end = edge_num;
#ifdef SIM
SIM_BEGIN(true);
#endif
for (size_t i=start;i<end;i++)
{
edge_iterator eit;
g.add_edge(edges[i].first, edges[i].second, eit);
#ifndef SIM
eit->set_property(edge_property(i));
#endif
}
#ifdef SIM
SIM_END(true);
#endif
}
}