本文整理汇总了C++中graph_access::getEdgeWeight方法的典型用法代码示例。如果您正苦于以下问题:C++ graph_access::getEdgeWeight方法的具体用法?C++ graph_access::getEdgeWeight怎么用?C++ graph_access::getEdgeWeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_access
的用法示例。
在下文中一共展示了graph_access::getEdgeWeight方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extract_block
void graph_extractor::extract_block(graph_access & G,
graph_access & extracted_block,
PartitionID block,
std::vector<NodeID> & mapping) {
// build reverse mapping
std::vector<NodeID> reverse_mapping;
NodeID nodes = 0;
NodeID dummy_node = G.number_of_nodes() + 1;
forall_nodes(G, node) {
if(G.getPartitionIndex(node) == block) {
reverse_mapping.push_back(nodes++);
} else {
reverse_mapping.push_back(dummy_node);
}
} endfor
extracted_block.start_construction(nodes, G.number_of_edges());
forall_nodes(G, node) {
if(G.getPartitionIndex(node) == block) {
NodeID new_node = extracted_block.new_node();
mapping.push_back(node);
extracted_block.setNodeWeight( new_node, G.getNodeWeight(node));
forall_out_edges(G, e, node) {
NodeID target = G.getEdgeTarget(e);
if( G.getPartitionIndex( target ) == block ) {
EdgeID new_edge = extracted_block.new_edge(new_node, reverse_mapping[target]);
extracted_block.setEdgeWeight(new_edge, G.getEdgeWeight(e));
}
} endfor
}
示例2: writeGraphWeighted
int graph_io::writeGraphWeighted(graph_access & G, std::string filename) {
std::ofstream f(filename.c_str());
f << G.number_of_nodes() << " " << G.number_of_edges()/2 << " 11" << std::endl;
forall_nodes(G, node) {
f << G.getNodeWeight(node) ;
forall_out_edges(G, e, node) {
f << " " << (G.getEdgeTarget(e)+1) << " " << G.getEdgeWeight(e) ;
} endfor
示例3: edge_cut
EdgeWeight quality_metrics::edge_cut(graph_access & G) {
EdgeWeight edgeCut = 0;
forall_nodes(G, n) {
PartitionID partitionIDSource = G.getPartitionIndex(n);
forall_out_edges(G, e, n) {
NodeID targetNode = G.getEdgeTarget(e);
PartitionID partitionIDTarget = G.getPartitionIndex(targetNode);
if (partitionIDSource != partitionIDTarget) {
edgeCut += G.getEdgeWeight(e);
}
} endfor
示例4: convert_ds
EdgeWeight edge_cut_flow_solver::convert_ds( const PartitionConfig & config,
graph_access & G,
PartitionID & lhs,
PartitionID & rhs,
std::vector<NodeID> & lhs_boundary_stripe,
std::vector<NodeID> & rhs_boundary_stripe,
std::vector<NodeID> & new_to_old_ids,
long *n_ad,
long* m_ad,
node** nodes_ad,
arc** arcs_ad,
long ** cap_ad,
node** source_ad,
node** sink_ad,
long* node_min_ad,
EdgeID & no_edges_in_flow_graph) {
//should soon be refactored
#include "convert_ds_variables.h"
//building up the graph as in parse.h of hi_pr code
NodeID idx = 0;
new_to_old_ids.resize(lhs_boundary_stripe.size() + rhs_boundary_stripe.size());
std::unordered_map<NodeID, NodeID> old_to_new;
for( unsigned i = 0; i < lhs_boundary_stripe.size(); i++) {
G.setPartitionIndex(lhs_boundary_stripe[i], BOUNDARY_STRIPE_NODE);
new_to_old_ids[idx] = lhs_boundary_stripe[i];
old_to_new[lhs_boundary_stripe[i]] = idx++ ;
}
for( unsigned i = 0; i < rhs_boundary_stripe.size(); i++) {
G.setPartitionIndex(rhs_boundary_stripe[i], BOUNDARY_STRIPE_NODE);
new_to_old_ids[idx] = rhs_boundary_stripe[i];
old_to_new[rhs_boundary_stripe[i]] = idx++;
}
std::vector<NodeID> outer_lhs_boundary;
std::vector<NodeID> outer_rhs_boundary;
EdgeID no_edges = regions_no_edges(G, lhs_boundary_stripe, rhs_boundary_stripe,
lhs, rhs,
outer_lhs_boundary, outer_rhs_boundary);
no_edges_in_flow_graph = no_edges;
if(outer_lhs_boundary.size() == 0 || outer_rhs_boundary.size() == 0) return false;
n = lhs_boundary_stripe.size() + rhs_boundary_stripe.size() + 2; //+source and target
m = no_edges + outer_lhs_boundary.size() + outer_rhs_boundary.size();
nodes = (node*) calloc ( n+2, sizeof(node) );
arcs = (arc*) calloc ( 2*m+1, sizeof(arc) );
arc_tail = (long*) calloc ( 2*m, sizeof(long) );
arc_first= (long*) calloc ( n+2, sizeof(long) );
acap = (long*) calloc ( 2*m, sizeof(long) );
arc_current = arcs;
node_max = 0;
node_min = n;
unsigned nodeoffset = 1;
source = n - 2 + nodeoffset;
sink = source+1;
idx = 0;
for( unsigned i = 0; i < lhs_boundary_stripe.size(); i++, idx++) {
NodeID node = lhs_boundary_stripe[i];
NodeID sourceID = idx + nodeoffset;
forall_out_edges(G, e, node) {
if(G.getPartitionIndex(G.getEdgeTarget(e)) == BOUNDARY_STRIPE_NODE) {
NodeID targetID = old_to_new[G.getEdgeTarget(e)] + nodeoffset;
EdgeWeight capacity = G.getEdgeWeight(e);
tail = sourceID;
head = targetID;
cap = capacity;
createEdge()
}
} endfor
}