本文整理汇总了C++中graph_access::number_of_nodes方法的典型用法代码示例。如果您正苦于以下问题:C++ graph_access::number_of_nodes方法的具体用法?C++ graph_access::number_of_nodes怎么用?C++ graph_access::number_of_nodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_access
的用法示例。
在下文中一共展示了graph_access::number_of_nodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
示例2: 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);
}
示例3: 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
示例4: 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;
}
示例5: 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 {
示例6: 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
}
示例7: perform_partitioning
void parallel_mh_async::perform_partitioning(const PartitionConfig & partition_config, graph_access & G) {
m_time_limit = partition_config.time_limit;
m_island = new population(m_communicator, partition_config);
m_best_global_map = new PartitionID[G.number_of_nodes()];
srand(partition_config.seed*m_size+m_rank);
random_functions::setSeed(partition_config.seed*m_size+m_rank);
PartitionConfig ini_working_config = partition_config;
initialize( ini_working_config, G);
m_t.restart();
exchanger ex(m_communicator);
do {
PartitionConfig working_config = partition_config;
working_config.graph_allready_partitioned = false;
if(!partition_config.strong)
working_config.no_new_initial_partitioning = false;
working_config.mh_pool_size = ini_working_config.mh_pool_size;
if(m_rounds == 0 && working_config.mh_enable_quickstart) {
ex.quick_start( working_config, G, *m_island );
}
perform_local_partitioning( working_config, G );
if(m_rank == ROOT) {
std::cout << "t left " << (m_time_limit - m_t.elapsed()) << std::endl;
}
//push and recv
if( m_t.elapsed() <= m_time_limit && m_size > 1) {
unsigned messages = ceil(log(m_size));
for( unsigned i = 0; i < messages; i++) {
ex.push_best( working_config, G, *m_island );
ex.recv_incoming( working_config, G, *m_island );
}
}
m_rounds++;
} while( m_t.elapsed() <= m_time_limit );
collect_best_partitioning(G, partition_config);
m_island->print();
//print logfile (for convergence plots)
if( partition_config.mh_print_log ) {
std::stringstream filename_stream;
filename_stream << "log_"<< partition_config.graph_filename <<
"_m_rank_" << m_rank <<
"_file_" <<
"_seed_" << partition_config.seed <<
"_k_" << partition_config.k;
std::string filename(filename_stream.str());
m_island->write_log(filename);
}
delete m_island;
}
示例8: 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
}
示例9: 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
}
示例10: 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
示例11: 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
示例12: mutate
void population_mis::mutate(MISConfig & config, graph_access & G, individuum_mis & ind) {
set_mis_for_individuum(config, G, ind);
delete [] ind.solution;
ind.solution = NULL;
ils iterate;
iterate.perform_ils(config, G, config.ils_iterations);
// Create solution for the individuum
NodeID *solution = new NodeID[G.number_of_nodes()];
unsigned int solution_size = create_solution(G, solution);
ind.solution = solution;
ind.solution_size = solution_size;
}
示例13: 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;
}
示例14: initial_partition
void greedy_mis::initial_partition(const unsigned int seed, graph_access & G) {
random_functions::setSeed(seed);
NodePermutationMap permutation;
generate_permutation(G, permutation);
bucket_array *buckets = new bucket_array(G.number_of_nodes());
G.set_partition_count(2);
// Initialize the priority queue
forall_nodes (G, n) {
NodeID node = permutation[n];
EdgeWeight node_degree = G.getNodeDegree(node);
buckets->increment(node, node_degree);
G.setPartitionIndex(node, 0);
} endfor
示例15: 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