本文整理汇总了C++中AdjacencyList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ AdjacencyList::size方法的具体用法?C++ AdjacencyList::size怎么用?C++ AdjacencyList::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyList
的用法示例。
在下文中一共展示了AdjacencyList::size方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
LowestCommonAncestor(
int root, const AdjacencyList<EdgeType> &graph)
: m_depth_table(graph.size(), -1)
, m_skip_table(
graph.size(),
std::vector<int>(32 - __builtin_clz(graph.size()), -1))
{
std::vector<int> s;
build_tables(root, s, graph);
}
示例2: AbstractSparseMatrix
SymmetricCSlRMatrix::SymmetricCSlRMatrix(AdjacencyList const & adjList)
: AbstractSparseMatrix(adjList.size(), adjList.size())
, _iptr(adjList.size() + 1)
, _diag(adjList.size()) {
for (size_t i = 0; i < adjList.size(); i++)
_iptr[i + 1] = _iptr[i] + adjList[i].size();
_jptr.reserve(_iptr[_w]);
for (size_t i = 0; i < adjList.size(); i++)
for (auto neighbour : adjList[i])
_jptr.emplace_back(neighbour);
_lval.resize(_iptr[_w]);
}
示例3: passed
std::vector<int> compute_subtree_size(
const AdjacencyList<EdgeType> &conn, int root) const
{
const int n = conn.size();
std::vector<int> subtree_size(n);
std::vector<bool> passed(n), gathered(n);
std::stack<pii> count_stack;
count_stack.push(pii(root, 0));
while(!count_stack.empty()){
const pii p = count_stack.top();
count_stack.pop();
const int u = p.first, i = p.second;
if(i == 0){
passed[u] = true;
count_stack.push(pii(u, 1));
for(size_t j = 0; j < conn[u].size(); ++j){
const int v = conn[u][j].to;
if(passed[v]){ continue; }
count_stack.push(pii(v, 0));
}
}else{
int sum = 1;
gathered[u] = true;
for(size_t j = 0; j < conn[u].size(); ++j){
const int v = conn[u][j].to;
if(!gathered[v]){ continue; }
sum += subtree_size[v];
}
subtree_size[u] = sum;
}
}
return subtree_size;
}
示例4: min_distance
unsigned int min_distance(const AdjacencyList& graph)
{
vector<unsigned int> distances(graph.size(), infinity);
MinHeap cut;
distances[0] = 0;
cut.push(make_pair(0, 0));
while (!cut.empty())
{
unsigned int closest = cut.top().second;
unsigned int to_closest = cut.top().first;
cut.pop();
if (distances[closest] < to_closest)
{
continue;
}
for (unsigned int i = 0; i < graph[closest].size(); ++i)
{
unsigned int adjacent = graph[closest][i].first;
unsigned int distance = graph[closest][i].second;
if (distances[adjacent] > to_closest + distance)
{
distances[adjacent] = to_closest + distance;
cut.push(make_pair(distances[adjacent], adjacent));
}
}
}
return distances.back();
}
示例5: enumerate_maximal_independent_sets
void enumerate_maximal_independent_sets(
const AdjacencyList<EdgeType> &graph, Func func)
{
const int n = graph.size();
std::vector<uint64_t> bit_graph(n), incr_bit_graph(n + 1);
for(int i = n - 1; i >= 0; --i){
uint64_t mask = (1ull << i);
for(const auto &e : graph[i]){ mask |= (1ull << e.to); }
bit_graph[i] = mask;
incr_bit_graph[i] = mask | incr_bit_graph[i + 1];
}
std::function<void(int, uint64_t, uint64_t)> recur =
[&, n](int i, uint64_t picked, uint64_t eliminated) -> void {
if(i == n){
func(picked);
return;
}
const bool force_ignore = ((eliminated & (1ull << i)) != 0);
int flags = 1; // 1: select v_i, 2: ignore v_i
if(bit_graph[i] & ~(incr_bit_graph[i + 1] | eliminated)){
flags = (force_ignore ? 2 : 1);
}else if((incr_bit_graph[i + 1] | eliminated) & (1ull << i)){
flags = (force_ignore ? 2 : 3);
}
if(flags & 1){
recur(i + 1, picked | (1ull << i), eliminated | bit_graph[i]);
}
if(flags & 2){ recur(i + 1, picked, eliminated); }
};
recur(0, 0, 0);
}
示例6: HeavyLightDecomposer
explicit HeavyLightDecomposer(
const AdjacencyList<EdgeType> &conn, int root = 0)
: m_paths(0)
, m_path_ids(conn.size(), -1)
, m_local_indices(conn.size(), -1)
{
const std::vector<int> subtree_size = compute_subtree_size(conn, root);
std::stack<pii> decompose_stack;
decompose_stack.push(pii(root, -1));
while(!decompose_stack.empty()){
const pii p = decompose_stack.top();
decompose_stack.pop();
const int parent_vertex = p.second;
const int pid = m_paths.size();
m_paths.push_back(Path());
Path &path = m_paths.back();
path.parent_vertex = parent_vertex;
if(parent_vertex >= 0){
const int parent_pid = m_path_ids[parent_vertex];
const int parent_index = m_local_indices[parent_vertex];
m_paths[parent_pid].children.push_back(
Connection(parent_index, pid));
path.depth = m_paths[parent_pid].depth + 1;
}else{
path.depth = 0;
}
int cur = p.first;
while(cur >= 0){
const int st_size = subtree_size[cur], threshold = st_size / 2;
m_path_ids[cur] = pid;
m_local_indices[cur] = path.vertices.size();
path.vertices.push_back(cur);
int heavy_edge = -1;
for(size_t i = 0; i < conn[cur].size(); ++i){
const int v = conn[cur][i].to;
if(subtree_size[v] > subtree_size[cur]){ continue; }
if(heavy_edge < 0 && subtree_size[v] >= threshold){
heavy_edge = v;
}else{
decompose_stack.push(pii(v, cur));
}
}
cur = heavy_edge;
}
}
}
示例7:
//#################### CONSTRUCTORS ####################
AdjacencyTable::AdjacencyTable(const AdjacencyList& adjList)
: m_size(adjList.size())
{
m_table.resize(m_size);
for(int i=0; i<m_size; ++i)
{
m_table[i].resize(m_size, (float)INT_MAX); // use a very large weight to represent +inf (i.e. no edge)
m_table[i][i] = 0.0f;
const std::list<AdjacencyList::Edge>& adjEdges = adjList.adjacent_edges(i);
for(std::list<AdjacencyList::Edge>::const_iterator jt=adjEdges.begin(), jend=adjEdges.end(); jt!=jend; ++jt)
{
m_table[i][jt->to_node()] = jt->length();
}
}
}
示例8: PrintHamiltonianCycle
void Graph::PrintHamiltonianCycle() {
for (const auto &kv : adjacency_list_) {
Tracker tracker(adjacency_list_.size(), kv.first);
if (Visit(kv.first, tracker)) {
std::cout << tracker.walk[0];
for (int i = 1; i < tracker.walk.size(); ++i) {
std::cout << " " << tracker.walk[i];
}
std::cout << std::endl;
return;
}
}
printf("N\n");
}
示例9: dijkstra
vector<unsigned int> dijkstra(const AdjacencyList& graph,
unsigned int start_node)
{
vector<unsigned int> distances(graph.size(), infinity);
distances[start_node] = 0;
priority_queue<
pair<unsigned int, unsigned int>,
vector<pair<unsigned int, unsigned int>>,
greater<pair<unsigned int, unsigned int>>
> cut;
cut.push(make_pair(0, start_node));
while (!cut.empty())
{
unsigned int closest_node {cut.top().second};
unsigned int to_closest {cut.top().first};
cut.pop();
if (distances[closest_node] < to_closest)
{
continue;
}
for (const auto& adjacent : graph[closest_node])
{
unsigned int adjacent_node {adjacent.first};
unsigned int edge_weight {adjacent.second};
if (distances[adjacent_node] > to_closest + edge_weight)
{
distances[adjacent_node] = to_closest + edge_weight;
cut.push(make_pair(distances[adjacent_node], adjacent_node));
}
}
}
return distances;
}
示例10: OSMReader
OSMReader ( const char * osm_file,
AdjacencyList & alist,
AdjacencyList & palist,
WaynodeLocations & waynode_locations,
WayNodesMap & busWayNodesMap,
Way2Nodes & way2nodes ) : alist ( alist ),
palist ( palist ),
waynode_locations ( waynode_locations ),
busWayNodesMap ( busWayNodesMap ),
way2nodes ( way2nodes )
{
try
{
#ifdef DEBUG
std::cout << "\n OSMReader is running... " << std::endl;
#endif
osmium::io::File infile ( osm_file );
osmium::io::Reader reader ( infile, osmium::osm_entity_bits::all );
using SparseLocations = osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location>;
osmium::handler::NodeLocationsForWays<SparseLocations> node_locations ( locations );
osmium::apply ( reader, node_locations, *this );
reader.close();
#ifdef DEBUG
std::cout << " #OSM Nodes: " << nOSM_nodes << "\n";
std::cout << " #OSM Highways: " << nOSM_ways << "\n";
std::cout << " #Kms (Total length of highways) = " << sum_highhway_length/1000.0 << std::endl;
std::cout << " #OSM Relations: " << nOSM_relations << "\n";
std::cout << " #Highway Nodes: " << sum_highhway_nodes << "\n";
std::cout << " #Unique Highway Nodes: " << sum_unique_highhway_nodes << "\n";
std::cout << " E= (#Highway Nodes - #OSM Highways): " << sum_highhway_nodes - nOSM_ways << "\n";
std::cout << " V= (#Unique Highway Nodes):" << sum_unique_highhway_nodes << "\n";
std::cout << " V^2/E= "
<<
( ( long ) sum_unique_highhway_nodes * ( long ) sum_unique_highhway_nodes )
/ ( double ) ( sum_highhway_nodes - nOSM_ways )
<< "\n";
std::cout << " Edge_multiplicity: " << edge_multiplicity << std::endl;
std::cout << " max edle length: " << max_edge_length << std::endl;
std::cout << " edle length mean: " << mean_edge_length/cedges << std::endl;
std::cout << " cedges: " << cedges << std::endl;
std::cout << " #Buses = " << busWayNodesMap.size() << std::endl;
std::cout << " Node locations " << locations.used_memory() /1024.0/1024.0 << " Mbytes" << std::endl;
//std::cout << " Waynode locations " << waynode_locations.used_memory() /1024.0/1024.0 << " Mbytes" << std::endl;
std::cout << " Vertices " << vert.used_memory() /1024.0/1024.0 << " Mbytes" << std::endl;
std::cout << " way2nodes " << way2nodes.size() << "" << std::endl;
std::set<osmium::unsigned_object_id_type> sum_vertices;
std::map<osmium::unsigned_object_id_type, size_t> word_map;
int sum_edges {0};
for ( auto busit = begin ( alist );
busit != end ( alist ); ++busit )
{
sum_vertices.insert ( busit->first );
sum_edges+=busit->second.size();
for ( const auto &v : busit->second )
{
sum_vertices.insert ( v );
}
}
std::cout << " #citymap edges = "<< sum_edges<< std::endl;
std::cout << " #citymap vertices = "<< sum_vertices.size() << std::endl;
std::cout << " #citymap vertices (deg- >= 1) = "<< alist.size() << std::endl;
std::cout << " #onewayc = "<< onewayc<< std::endl;
#endif
m_estimator *= 8;
}
catch ( std::exception &err )
{
google::protobuf::ShutdownProtobufLibrary();
throw;
}
}