本文整理汇总了C++中graph_access::getPartitionIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ graph_access::getPartitionIndex方法的具体用法?C++ graph_access::getPartitionIndex怎么用?C++ graph_access::getPartitionIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_access
的用法示例。
在下文中一共展示了graph_access::getPartitionIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setup_start_nodes
void kway_graph_refinement::setup_start_nodes(PartitionConfig & config, graph_access & G, complete_boundary & boundary, boundary_starting_nodes & start_nodes) {
QuotientGraphEdges quotient_graph_edges;
boundary.getQuotientGraphEdges(quotient_graph_edges);
unordered_map<NodeID, bool> allready_contained;
for( unsigned i = 0; i < quotient_graph_edges.size(); i++) {
boundary_pair & ret_value = quotient_graph_edges[i];
PartitionID lhs = ret_value.lhs;
PartitionID rhs = ret_value.rhs;
PartialBoundary & partial_boundary_lhs = boundary.getDirectedBoundary(lhs, lhs, rhs);
forall_boundary_nodes(partial_boundary_lhs, cur_bnd_node) {
ASSERT_EQ(G.getPartitionIndex(cur_bnd_node), lhs);
if(allready_contained.find(cur_bnd_node) == allready_contained.end() ) {
start_nodes.push_back(cur_bnd_node);
allready_contained[cur_bnd_node] = true;
}
} endfor
PartialBoundary & partial_boundary_rhs = boundary.getDirectedBoundary(rhs, lhs, rhs);
forall_boundary_nodes(partial_boundary_rhs, cur_bnd_node) {
ASSERT_EQ(G.getPartitionIndex(cur_bnd_node), rhs);
if(allready_contained.find(cur_bnd_node) == allready_contained.end()) {
start_nodes.push_back(cur_bnd_node);
allready_contained[cur_bnd_node] = true;
}
} 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: collect_best_partitioning
EdgeWeight parallel_mh_async::collect_best_partitioning(graph_access & G) {
//perform partitioning locally
EdgeWeight min_objective = 0;
m_island->apply_fittest(G, min_objective);
int best_local_objective = min_objective;
int best_global_objective = 0;
PartitionID* best_local_map = new PartitionID[G.number_of_nodes()];
std::vector< NodeWeight > block_sizes(G.get_partition_count(),0);
forall_nodes(G, node) {
best_local_map[node] = G.getPartitionIndex(node);
block_sizes[G.getPartitionIndex(node)]++;
} endfor
示例5: initial_partition
void bipartition::initial_partition( const PartitionConfig & config,
const unsigned int seed,
graph_access & G,
int* partition_map) {
timer t;
t.restart();
unsigned iterations = config.bipartition_tries;
EdgeWeight best_cut = std::numeric_limits<EdgeWeight>::max();
int best_load = std::numeric_limits<int>::max();
for( unsigned i = 0; i < iterations; i++) {
if(config.bipartition_algorithm == BIPARTITION_BFS) {
grow_regions_bfs(config, G);
} else if( config.bipartition_algorithm == BIPARTITION_FM) {
grow_regions_fm(config, G);
}
G.set_partition_count(2);
post_fm(config, G);
quality_metrics qm;
EdgeWeight curcut = qm.edge_cut(G);
int lhs_block_weight = 0;
int rhs_block_weight = 0;
forall_nodes(G, node) {
if(G.getPartitionIndex(node) == 0) {
lhs_block_weight += G.getNodeWeight(node);
} else {
rhs_block_weight += G.getNodeWeight(node);
}
} endfor
int lhs_overload = std::max(lhs_block_weight - config.target_weights[0],0);
int rhs_overload = std::max(rhs_block_weight - config.target_weights[1],0);
if(curcut < best_cut || (curcut == best_cut && lhs_overload + rhs_block_weight < best_load) ) {
//store it
best_cut = curcut;
best_load = lhs_overload + rhs_overload;
forall_nodes(G, n) {
partition_map[n] = G.getPartitionIndex(n);
} endfor
}
示例6: init_queue_with_boundary
void two_way_fm::init_queue_with_boundary(const PartitionConfig & config,
graph_access & G,
std::vector<NodeID> & bnd_nodes,
refinement_pq * queue,
PartitionID partition_of_boundary,
PartitionID other) {
if(config.permutation_during_refinement == PERMUTATION_QUALITY_FAST) {
random_functions::permutate_vector_fast(bnd_nodes, false);
} else if(config.permutation_during_refinement == PERMUTATION_QUALITY_GOOD) {
random_functions::permutate_vector_good(bnd_nodes, false);
}
for( unsigned int i = 0, end = bnd_nodes.size(); i < end; i++) {
NodeID cur_bnd_node = bnd_nodes[i];
//compute gain
EdgeWeight int_degree = 0;
EdgeWeight ext_degree = 0;
int_ext_degree(G, cur_bnd_node, partition_of_boundary, other, int_degree, ext_degree);
Gain gain = ext_degree - int_degree;
queue->insert(cur_bnd_node, gain);
ASSERT_TRUE(ext_degree > 0);
ASSERT_EQ(partition_of_boundary, G.getPartitionIndex(cur_bnd_node));
}
}
示例7: construct_initial_mapping_bottomup_internal
void fast_construct_mapping::construct_initial_mapping_bottomup_internal( PartitionConfig & config, graph_access & C, matrix & D, int idx, std::vector< NodeID > & perm_rank) {
PartitionID num_parts = C.number_of_nodes()/config.group_sizes[idx];
partition_C_perfectly_balanced( config, C, num_parts);
if( idx ==(int)(config.group_sizes.size() - 1) ) {
// build initial offsets
int nodes_per_block = m_tmp_num_nodes / config.group_sizes[idx];
perm_rank[0] = 0;
for( unsigned int block = 1; block < perm_rank.size(); block++) {
perm_rank[block] = perm_rank[block-1]+nodes_per_block;
}
} else {
//contract partitioned graph
graph_access Q; complete_boundary bnd(&C);
bnd.build();
bnd.getUnderlyingQuotientGraph(Q);
std::vector< NodeID > rec_ranks( num_parts, 0);
construct_initial_mapping_bottomup_internal( config, Q, D, idx+1, rec_ranks);
//recompute offsets
forall_nodes(C, node) {
PartitionID block = C.getPartitionIndex(node);
perm_rank[node] = rec_ranks[block];
rec_ranks[block] += C.getNodeWeight(node);
} endfor
}
示例8: move_node_back
void kway_graph_refinement_core::move_node_back(PartitionConfig & config,
graph_access & G,
NodeID & node,
PartitionID & to,
vertex_moved_hashtable & moved_idx,
refinement_pq * queue,
complete_boundary & boundary) {
PartitionID from = G.getPartitionIndex(node);
G.setPartitionIndex(node, to);
boundary_pair pair;
pair.k = config.k;
pair.lhs = from;
pair.rhs = to;
//update all boundaries
boundary.postMovedBoundaryNodeUpdates(node, &pair, true, true);
NodeWeight this_nodes_weight = G.getNodeWeight(node);
boundary.setBlockNoNodes(from, boundary.getBlockNoNodes(from)-1);
boundary.setBlockNoNodes(to, boundary.getBlockNoNodes(to)+1);
boundary.setBlockWeight( from, boundary.getBlockWeight(from)-this_nodes_weight);
boundary.setBlockWeight( to, boundary.getBlockWeight(to)+this_nodes_weight);
}
示例9: initial_partition
void initial_partition_bipartition::initial_partition( const PartitionConfig & config,
const unsigned int seed,
graph_access & G, int* partition_map) {
graph_partitioner gp;
PartitionConfig rec_config = config;
rec_config.initial_partitioning_type = INITIAL_PARTITIONING_BIPARTITION;
rec_config.initial_partitioning_repetitions = 0;
rec_config.global_cycle_iterations = 1;
rec_config.use_wcycles = false;
rec_config.use_fullmultigrid = false;
rec_config.fm_search_limit = config.bipartition_post_ml_limits;
rec_config.matching_type = MATCHING_GPA;
//rec_config.matching_type = CLUSTER_COARSENING;
rec_config.permutation_quality = PERMUTATION_QUALITY_GOOD;
rec_config.initial_partitioning = true;
std::streambuf* backup = std::cout.rdbuf();
std::ofstream ofs;
ofs.open("/dev/null");
std::cout.rdbuf(ofs.rdbuf());
gp.perform_recursive_partitioning(rec_config, G);
ofs.close();
std::cout.rdbuf(backup);
forall_nodes(G, n) {
partition_map[n] = G.getPartitionIndex(n);
} endfor
示例10: construct_flow_pb
bool vertex_separator_flow_solver::construct_flow_pb( const PartitionConfig & config,
graph_access & G,
PartitionID & lhs,
PartitionID & rhs,
std::vector<NodeID> & lhs_nodes,
std::vector<NodeID> & rhs_nodes,
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) {
//very dirty for loading variables :). some time this should all be refactored. for now we can focus on the important stuff.
#include "../refinement/quotient_graph_refinement/flow_refinement/flow_solving_kernel/convert_ds_variables.h"
//building up the graph as in parse.h of hi_pr code
//first we have to count the number of edges
// s to lhs + rhs to t + lhs to rhs
unsigned no_edges = 0;
for( unsigned i = 0; i < lhs_nodes.size(); i++) {
NodeID node = lhs_nodes[i];
forall_out_edges(G, e, node) {
NodeID target = G.getEdgeTarget(e);
if(rhs == G.getPartitionIndex(target)) {
++no_edges;
}
} endfor
}
示例11: construct
void mis_permutation::construct(graph_access & G) {
inconsistencies = 0;
solution_size = 0;
free_size = 0;
total_size = G.number_of_nodes();
nodes.clear();
tightness.clear();
position.clear();
nodes.resize(total_size);
tightness.resize(total_size);
position.resize(total_size);
onetight_all.init(G.number_of_nodes());
// Insert solution nodes
forall_nodes(G, n) {
nodes[n] = n;
position[n] = n;
unsigned int index = G.getPartitionIndex(n);
// Maybe implement tightness calculations here
if (index == 1) {
move_to_solution(n, G);
} else {
int tight = calculate_tightness(n, G);
tightness[n] = tight;
if (tight == 0) move_to_free(n, G);
else move_to_non_free(n, G);
if (tight == 1) onetight_all.insert(n);
}
} endfor
示例12: addSnapshot
void partition_snapshooter::addSnapshot(graph_access & G) {
std::cout << "idx " << m_partition_map_buffer.size() << std::endl;
std::vector<PartitionID>* partition_map = new std::vector<PartitionID>();
m_partition_map_buffer.push_back(partition_map);
forall_nodes(G, node) {
partition_map->push_back(G.getPartitionIndex(node));
} endfor
示例13: calculate_tightness
int mis_permutation::calculate_tightness(NodeID node, graph_access & G) {
int tightness = 0;
forall_out_edges(G, edge, node) {
NodeID target = G.getEdgeTarget(edge);
bool target_index = G.getPartitionIndex(target);
if (target_index == 1) {
tightness++;
}
} endfor
示例14: perform_refinement
EdgeWeight tabu_search::perform_refinement(PartitionConfig & config, graph_access & G, complete_boundary & boundary) {
quality_metrics qm;
EdgeWeight input_cut = qm.edge_cut(G);
EdgeWeight cur_cut = input_cut;
EdgeWeight best_cut = input_cut;
std::vector< PartitionID > bestmap(G.number_of_nodes(), 0);
forall_nodes(G, node) {
bestmap[node] = G.getPartitionIndex(node);
} endfor
示例15: create_solution
unsigned int population_mis::create_solution(graph_access & G, NodeID *solution) {
unsigned int solution_size = 0;
forall_nodes(G, node) {
if (G.getPartitionIndex(node) == 1) {
solution[node] = 1;
solution_size++;
}
else solution[node] = 0;
} endfor
return solution_size;
}