Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4863

C/C++ • Re: Boost provides free peer-reviewed portable C++ source libraries.

$
0
0
I had to use breadth_first_search (BFS) on really big graphs I created.
I found this page as perfect starter on how to do BFS with Boost graph library:
https://theboostcpplibraries.com/boost.graph-algorithms

Especially 31.8 to determine distances from a single source.
31.9 to determine the shortest path predecessor for each vertex to single source.
And 31.10 doing both: here both visitors have to be passed in a std::make_pair(...).

I used 31.8 for now.
My Pi5 had to few ram, worked on my 7950X CPU with 32GB ram.
But even there I was only able to create (very dense) graph with 314,227 vertices only for my scenario.
Determination of all the number theory motivated 314,227 vertices took 20.3s.
Creation of the really many edges took 128.4s.
The BFS then took only 0.8s(!), including determining of the maximal distance from single source.
I learned that not Boost lib, but standard library (STL) function "max_element()" did what I needed:

Code:

...  boost::array<int, mx> distances{{0}};  boost::breadth_first_search(g, src,    boost::visitor(      boost::make_bfs_visitor(        boost::record_distances(distances.begin(),          boost::on_tree_edge{}))));  std::cout << ": " << *std::max_element(distances.begin(), distances.end()) << std::endl;...

Since I am interested in even bigger graphs I just booted an old Xeon e5-2680 (2CPU) 24C/48T — that has 384GB of ram and should get me further ...

P.S:
Simple time measurements done with:

Code:

...clock_t start;...start = clock();...std::cout << static_cast<float>(clock() - start) / CLOCKS_PER_SEC << "s [max]\n";...start = clock();...std::cout << static_cast<float>(clock() - start) / CLOCKS_PER_SEC << "s [max1]\n";...

Statistics: Posted by HermannSW — Sun Mar 17, 2024 8:05 pm



Viewing all articles
Browse latest Browse all 4863

Trending Articles