本文整理汇总了C++中graph_t类的典型用法代码示例。如果您正苦于以下问题:C++ graph_t类的具体用法?C++ graph_t怎么用?C++ graph_t使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了graph_t类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parallel_dc
void parallel_dc(graph_t& g, unsigned threadnum, gBenchPerf_multi & perf, int perf_group)
{
uint64_t chunk = (unsigned)ceil(g.num_vertices()/(double)threadnum);
#pragma omp parallel num_threads(threadnum)
{
unsigned tid = omp_get_thread_num();
perf.open(tid, perf_group);
perf.start(tid, perf_group);
unsigned start = tid*chunk;
unsigned end = start + chunk;
if (end > g.num_vertices()) end = g.num_vertices();
for (unsigned vid=start;vid<end;vid++)
{
vertex_iterator vit = g.find_vertex(vid);
// out degree
vit->property().outdegree = vit->edges_size();
// in degree
edge_iterator eit;
for (eit=vit->edges_begin(); eit!=vit->edges_end(); eit++)
{
vertex_iterator targ = g.find_vertex(eit->target());
__sync_fetch_and_add(&(targ->property().indegree), 1);
}
}
perf.stop(tid, perf_group);
}
}
示例2: 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);
}
示例3: dc
//==============================================================//
void dc(graph_t& g, gBenchPerf_event & perf, int perf_group)
{
perf.open(perf_group);
perf.start(perf_group);
#ifdef SIM
SIM_BEGIN(true);
#endif
vertex_iterator vit;
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
// out degree
vit->property().outdegree = vit->edges_size();
// in degree
edge_iterator eit;
for (eit=vit->edges_begin(); eit!=vit->edges_end(); eit++)
{
vertex_iterator targ = g.find_vertex(eit->target());
(targ->property().indegree)++;
}
}
#ifdef SIM
SIM_END(true);
#endif
perf.stop(perf_group);
}// end dc
示例4: degree_analyze
void degree_analyze(graph_t& g,
uint64_t& indegree_max, uint64_t& indegree_min,
uint64_t& outdegree_max, uint64_t& outdegree_min)
{
vertex_iterator vit;
indegree_max=outdegree_max=0;
indegree_min=outdegree_min=numeric_limits<uint64_t>::max();
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
if (indegree_max < vit->property().indegree)
indegree_max = vit->property().indegree;
if (outdegree_max < vit->property().outdegree)
outdegree_max = vit->property().outdegree;
if (indegree_min > vit->property().indegree)
indegree_min = vit->property().indegree;
if (outdegree_min > vit->property().outdegree)
outdegree_min = vit->property().outdegree;
}
return;
}
示例5: learn_with_hint
// ヒントを与えた上でgreedy探索を行う
// graph: 元となったグラフ構造
// parent_nodes, child_nodes: parent_nodesに含まれるnodeからchild_nodeに含まれるnodeにしか辺を張らない
double learn_with_hint(graph_t& graph, std::vector<vertex_type> parent_nodes, std::vector<vertex_type> child_nodes)
{
// 子ノードの出現順序をランダムに
std::shuffle(std::begin(child_nodes), std::end(child_nodes), engine_);
// 最高評価値を保存しておく
sampling_.make_cpt(graph);
double eval_now = eval_(graph);
// 親候補と子候補を全部回して様子見る
for(auto const& child : child_nodes)
{
// 親ノードの出現順序をランダムに
std::shuffle(std::begin(parent_nodes), std::end(parent_nodes), engine_);
for(auto const& parent : parent_nodes)
{
if(auto edge = graph.add_edge(parent, child))
{
// 辺が張れたならば,評価をする
sampling_.make_cpt(graph);
auto const eval_next = eval_(graph);
if(eval_next < eval_now)
// 良くなってるscore
eval_now = eval_next;
else
// 変わらない or 悪い -> 元に戻す
graph.erase_edge(edge);
}
}
}
return eval_now;
}
示例6: output
void output(graph_t& g)
{
cout<<"Results: \n";
vertex_iterator vit;
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
cout<<"== vertex "<<vit->id()<<": edge#-"<<vit->edges_size()<<"\n";
}
}
示例7: reset_graph
void reset_graph(graph_t & g)
{
vertex_iterator vit;
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
vit->property().indegree = 0;
vit->property().outdegree = 0;
}
}
示例8: output
//==============================================================//
void output(graph_t& g)
{
cout<<"Betweenness Centrality Results: \n";
vertex_iterator vit;
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
cout<<"== vertex "<<vit->id()<<": "<<vit->property().BC<<"\n";
}
}
示例9: reset_graph
void reset_graph(graph_t & g)
{
vertex_iterator vit;
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
vit->property().root = vit->id();
}
}
示例10: output
void output(graph_t& g)
{
cout<<"WCC Results: \n";
vertex_iterator vit;
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
cout << vit->id() << " " << vit->property().root << "\n";
}
}
示例11: graph_update
void graph_update(graph_t &g, vector<uint64_t> IDs)
{
for (size_t i=0;i<IDs.size();i++)
{
if (g.num_vertices()==0) break;
g.delete_vertex(IDs[i]);
}
}
示例12: output
void output(graph_t& g)
{
cout<<"Degree Centrality Results: \n";
vertex_iterator vit;
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
cout<<"== vertex "<<vit->id()<<": in-"<<vit->property().indegree
<<" out-"<<vit->property().outdegree<<"\n";
}
}
示例13: reset_graph
void reset_graph(graph_t & g)
{
vertex_iterator vit;
for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
vit->property().degree = 0;
vit->property().removed = false;
}
}
示例14: prepareGraphIncrementaly
void prepareGraphIncrementaly(graph_t &graph)
{
obj_t obj;
P::Pose p;
P::InformMatrix inform;
graph.addNode(node_t(p, obj));
for (size_t i = 0; i < 19; ++i) {
graph.addNode(node_t(p, obj));
graph.addEdge(edge_t(&graph.getNode(i), &graph.getNode(i + 1), p, inform));
}
}
示例15: parallel_init
void parallel_init(graph_t& g, unsigned threadnum,
vector<vector<uint64_t> >& global_input_tasks)
{
global_input_tasks.resize(threadnum);
for (vertex_iterator vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
{
vit->property().root = vit->id();
global_input_tasks[vertex_distributor(vit->id(), threadnum)].push_back(vit->id());
}
}