本文整理汇总了C++中graph_access::number_of_edges方法的典型用法代码示例。如果您正苦于以下问题:C++ graph_access::number_of_edges方法的具体用法?C++ graph_access::number_of_edges怎么用?C++ graph_access::number_of_edges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_access
的用法示例。
在下文中一共展示了graph_access::number_of_edges方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: contract
// for documentation see technical reports of christian schulz
void contraction::contract(const PartitionConfig & partition_config,
graph_access & G,
graph_access & coarser,
const Matching & edge_matching,
const CoarseMapping & coarse_mapping,
const NodeID & no_of_coarse_vertices,
const NodePermutationMap & permutation) const {
if(partition_config.combine) {
coarser.resizeSecondPartitionIndex(no_of_coarse_vertices);
}
std::vector<NodeID> new_edge_targets(G.number_of_edges());
forall_edges(G, e) {
new_edge_targets[e] = coarse_mapping[G.getEdgeTarget(e)];
} endfor
std::vector<EdgeID> edge_positions(no_of_coarse_vertices, UNDEFINED_EDGE);
//we dont know the number of edges jet, so we use the old number for
//construction of the coarser graph and then resize the field according
//to the number of edges we really got
coarser.start_construction(no_of_coarse_vertices, G.number_of_edges());
NodeID cur_no_vertices = 0;
forall_nodes(G, n) {
NodeID node = permutation[n];
//we look only at the coarser nodes
if(coarse_mapping[node] != cur_no_vertices)
continue;
NodeID coarseNode = coarser.new_node();
coarser.setNodeWeight(coarseNode, G.getNodeWeight(node));
if(partition_config.combine) {
coarser.setSecondPartitionIndex(coarseNode, G.getSecondPartitionIndex(node));
}
// do something with all outgoing edges (in auxillary graph)
forall_out_edges(G, e, node) {
visit_edge(G, coarser, edge_positions, coarseNode, e, new_edge_targets);
} endfor
示例4: broadcast_graph
void graph_communication::broadcast_graph( graph_access & G, unsigned root) {
int rank = MPI::COMM_WORLD.Get_rank();
//first B-Cast number of nodes and number of edges
unsigned number_of_nodes = 0;
unsigned number_of_edges = 0;
std::vector< int > buffer(2,0);
if(rank == (int)root) {
buffer[0] = G.number_of_nodes();
buffer[1] = G.number_of_edges();
}
MPI::COMM_WORLD.Bcast(&buffer[0], 2, MPI_INT, root);
number_of_nodes = buffer[0];
number_of_edges = buffer[1];
int* xadj;
int* adjncy;
int* vwgt;
int* adjwgt;
if( rank == (int)root) {
xadj = G.UNSAFE_metis_style_xadj_array();
adjncy = G.UNSAFE_metis_style_adjncy_array();
vwgt = G.UNSAFE_metis_style_vwgt_array();
adjwgt = G.UNSAFE_metis_style_adjwgt_array();
} else {
xadj = new int[number_of_nodes+1];
adjncy = new int[number_of_edges];
vwgt = new int[number_of_nodes];
adjwgt = new int[number_of_edges];
}
MPI::COMM_WORLD.Bcast(xadj, number_of_nodes+1, MPI_INT, root);
MPI::COMM_WORLD.Bcast(adjncy, number_of_edges , MPI_INT, root);
MPI::COMM_WORLD.Bcast(vwgt, number_of_nodes , MPI_INT, root);
MPI::COMM_WORLD.Bcast(adjwgt, number_of_edges , MPI_INT, root);
G.build_from_metis_weighted( number_of_nodes, xadj, adjncy, vwgt, adjwgt);
delete[] xadj;
delete[] adjncy;
delete[] vwgt;
delete[] adjwgt;
}
示例5: run_maxent_optimization_internal
void local_optimizer::run_maxent_optimization_internal( const Config & config, graph_access & G ) {
if(G.number_of_edges() == 0) return;
std::vector< coord_t > new_coord(G.number_of_nodes());
CoordType alpha = config.maxent_alpha;
int iterations = config.maxent_inner_iterations;
CoordType q = config.q;
std::vector<CoordType> distances(G.number_of_edges(),0);
configure_distances( config, G, distances);
for( int i = 0; i < config.maxent_outer_iterations; i++) {
CoordType norm_coords = 0;
CoordType norm_diff = 0;
do {
forall_nodes_parallel(G, node) {
CoordType rho_i = 0; // assume graph is connected?
if(G.getNodeDegree(node) == 0) continue;
forall_out_edges(G, e, node) {
CoordType distance = distances[e];
rho_i += 1/(distance*distance);
} endfor
rho_i = 1/rho_i;
CoordType S_x = 0;
CoordType S_y = 0;
CoordType n_S_x = 0;
CoordType n_S_y = 0;
forall_out_edges(G, e, node) {
NodeID target = G.getEdgeTarget(e);
CoordType diffX = G.getX(node) - G.getX(target);
CoordType diffY = G.getY(node) - G.getY(target);
CoordType dist_square = diffX*diffX+diffY*diffY;
CoordType distance = distances[e];
CoordType dist = sqrt(dist_square);
CoordType scaled_distance = distance/dist;
CoordType squared_distance = distance*distance;
S_x += (G.getX(target) + scaled_distance*diffX)/(squared_distance);
S_y += (G.getY(target) + scaled_distance*diffY)/(squared_distance);
CoordType dist_q = pow(dist, q+2);
n_S_x -= diffX/dist_q;
n_S_y -= diffY/dist_q;
} endfor
S_x *= rho_i;
S_y *= rho_i;
forall_nodes(G, target) {
if( node == target ) continue;
CoordType diffX = G.getX(node) - G.getX(target);
CoordType diffY = G.getY(node) - G.getY(target);
CoordType dist_square = diffX*diffX+diffY*diffY;
CoordType dist = sqrt(dist_square);
CoordType dist_q = pow(dist, q+2);
n_S_x += diffX/dist_q;
n_S_y += diffY/dist_q;
} endfor
CoordType mult_factor = alpha*rho_i;
n_S_x *= mult_factor;
n_S_y *= mult_factor;
new_coord[node].x = S_x + sgn(q)*n_S_x;
new_coord[node].y = S_y + sgn(q)*n_S_y;
} endfor