本文整理汇总了C++中graph_access类的典型用法代码示例。如果您正苦于以下问题:C++ graph_access类的具体用法?C++ graph_access怎么用?C++ graph_access使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了graph_access类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
}
示例2: 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
示例3: set_mis_for_individuum
void population_mis::set_mis_for_individuum(MISConfig & config, graph_access & G, individuum_mis & ind, bool secondary) {
G.resizeSecondPartitionIndex(G.number_of_nodes());
forall_nodes(G, node) {
if (!secondary) G.setPartitionIndex(node, ind.solution[node]);
else G.setSecondPartitionIndex(node, ind.solution[node]);
} endfor
}
示例4: 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);
}
示例5: find_random_cycle
void cycle_search::find_random_cycle(graph_access & G, std::vector<NodeID> & cycle) {
//first perform a bfs starting from a random node and build the parent array
std::deque<NodeID>* bfsqueue = new std::deque<NodeID>;
NodeID v = random_functions::nextInt(0, G.number_of_nodes()-1);
bfsqueue->push_back(v);
std::vector<bool> touched(G.number_of_nodes(),false);
std::vector<bool> is_leaf(G.number_of_nodes(),false);
std::vector<NodeID> parent(G.number_of_nodes(),0);
std::vector<NodeID> leafes;
touched[v] = true;
parent[v] = v;
while(!bfsqueue->empty()) {
NodeID source = bfsqueue->front();
bfsqueue->pop_front();
bool is_leaf = true;
forall_out_edges(G, e, source) {
NodeID target = G.getEdgeTarget(e);
if(!touched[target]) {
is_leaf = false;
touched[target] = true;
parent[target] = source;
bfsqueue->push_back(target);
}
} endfor
if(is_leaf)
leafes.push_back(source);
}
示例6: partition_C_perfectly_balanced
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
}
示例7: 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
示例8: 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
示例9: 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
示例10: 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
示例11: init
void separator_pool::init(MISConfig & config, graph_access & G) {
xadj = G.UNSAFE_metis_style_xadj_array();
adjncy = G.UNSAFE_metis_style_adjncy_array();
separators_size = config.number_of_separators;
partitions_size = config.number_of_partitions;
k_separators_size = config.use_multiway_vc ? 0 : config.number_of_k_separators;
k_partitions_size = config.use_multiway_vc ? config.number_of_k_partitions : 0;
if (config.use_multiway_vc) scores.resize(config.multiway_blocks*config.population_size*config.number_of_k_partitions);
else scores.resize(config.multiway_blocks*config.population_size*config.number_of_k_separators);
clear_scores(config);
}
示例12: 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
示例13: sort
void topological_sort::sort( graph_access & G, std::vector<NodeID> & sorted_sequence) {
std::vector<int> dfsnum(G.number_of_nodes(), -1);
int dfscount = 0;
std::vector<NodeID> nodes(G.number_of_nodes());
random_functions::permutate_vector_good(nodes, true);
forall_nodes(G, node) {
NodeID curNode = nodes[node];
if(dfsnum[curNode] == -1) {
sort_dfs(curNode, G, dfsnum, dfscount, sorted_sequence);
}
} endfor
示例14: build_augmented_quotient_graph
bool augmented_Qgraph_fabric::build_augmented_quotient_graph( PartitionConfig & config,
graph_access & G,
complete_boundary & boundary,
augmented_Qgraph & aqg,
unsigned & s, bool rebalance, bool plus) {
graph_access G_bar;
boundary.getUnderlyingQuotientGraph(G_bar);
if(m_eligible.size() != G.number_of_nodes()) {
m_eligible.resize(G.number_of_nodes());
forall_nodes(G, node) {
m_eligible[node] = true;
} endfor
} else {
示例15: perform_partitioning
int wcycle_partitioner::perform_partitioning(const PartitionConfig & config, graph_access & G) {
PartitionConfig cfg = config;
if(config.stop_rule == STOP_RULE_SIMPLE) {
m_coarsening_stop_rule = new simple_stop_rule(cfg, G.number_of_nodes());
} else {
m_coarsening_stop_rule = new multiple_k_stop_rule(cfg, G.number_of_nodes());
}
int improvement = (int) perform_partitioning_recursive(cfg, G, NULL);
delete m_coarsening_stop_rule;
return improvement;
}