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 }
// 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