本文整理汇总了C++中sgraph::copy_vertex_field方法的典型用法代码示例。如果您正苦于以下问题:C++ sgraph::copy_vertex_field方法的具体用法?C++ sgraph::copy_vertex_field怎么用?C++ sgraph::copy_vertex_field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sgraph
的用法示例。
在下文中一共展示了sgraph::copy_vertex_field方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
virtual void execute(sgraph& output,
const std::vector<sgraph*>& parents) {
output.copy_vertex_field(field, new_field, group);
}
示例2: triple_apply_pagerank
void triple_apply_pagerank(sgraph& g, size_t& num_iter, double& total_pagerank, double& total_delta) {
typedef sgraph_compute::sgraph_engine<flexible_type>::graph_data_type graph_data_type;
typedef sgraph::edge_direction edge_direction;
// initialize every vertex with core id kmin
g.init_vertex_field(PAGERANK_COLUMN, reset_probability);
g.init_vertex_field(PREV_PAGERANK_COLUMN, 1.0);
g.init_vertex_field(DELTA_COLUMN, 0.0);
// Initialize degree count
sgraph_compute::sgraph_engine<flexible_type> ga;
auto degrees = ga.gather(
g,
[=](const graph_data_type& center,
const graph_data_type& edge,
const graph_data_type& other,
edge_direction edgedir,
flexible_type& combiner) {
combiner += 1;
},
flexible_type(0),
edge_direction::OUT_EDGE);
g.add_vertex_field(degrees, OUT_DEGREE_COLUMN);
num_iter = 0;
total_delta = 0.0;
total_pagerank = 0.0;
timer mytimer;
// Triple apply
double w = (1 - reset_probability);
const size_t degree_idx = g.get_vertex_field_id(OUT_DEGREE_COLUMN);
const size_t pr_idx = g.get_vertex_field_id(PAGERANK_COLUMN);
const size_t old_pr_idx = g.get_vertex_field_id(PREV_PAGERANK_COLUMN);
sgraph_compute::triple_apply_fn_type apply_fn =
[&](sgraph_compute::edge_scope& scope) {
auto& source = scope.source();
auto& target = scope.target();
scope.lock_vertices();
target[pr_idx] += w * source[old_pr_idx] / source[degree_idx];
scope.unlock_vertices();
};
table_printer table({{"Iteration", 0},
{"L1 change in pagerank", 0}});
table.print_header();
for (size_t iter = 0; iter < max_iterations; ++iter) {
if(cppipc::must_cancel()) {
log_and_throw(std::string("Toolkit cancelled by user."));
}
mytimer.start();
++num_iter;
g.init_vertex_field(PAGERANK_COLUMN, reset_probability);
sgraph_compute::triple_apply(g, apply_fn, {PAGERANK_COLUMN});
// compute the change in pagerank
auto delta = sgraph_compute::vertex_apply(
g,
flex_type_enum::FLOAT,
[&](const std::vector<flexible_type>& vdata) {
return std::abs((double)(vdata[pr_idx]) - (double)(vdata[old_pr_idx]));
});
// make the current pagerank the old pagerank
g.copy_vertex_field(PAGERANK_COLUMN, PREV_PAGERANK_COLUMN);
g.replace_vertex_field(delta, DELTA_COLUMN);
total_delta =
sgraph_compute::vertex_reduce<double>(g,
DELTA_COLUMN,
[](const flexible_type& v, double& acc) {
acc += (flex_float)v;
},
[](const double& v, double& acc) {
acc += v;
});
table.print_row(iter+1, total_delta);
// check convergence
if (total_delta < threshold) {
break;
}
} // end of pagerank iterations
table.print_footer();
// cleanup
g.remove_vertex_field(PREV_PAGERANK_COLUMN);
g.remove_vertex_field(OUT_DEGREE_COLUMN);
total_pagerank =
sgraph_compute::vertex_reduce<double>(g,
PAGERANK_COLUMN,
[](const flexible_type& v, double& acc) {
//.........这里部分代码省略.........