30 Ekim 2017 Pazartesi

graph breadth_first_search metodu

Giriş
Şu satırı dahil ederiz
#include <boost/graph/breadth_first_search.hpp>
Örnek
Şöyle yaparız.
class BreadthFirstSearchVisitor : public boost::default_bfs_visitor
{
  ...
};

GraphType g = ...;
BreadthFirstSearchVisitor breadthFirstSearchVisitor(g);

unsigned int startVertex = 0;

// named argument signature
breadth_first_search(g, vertex(startVertex, g),
 visitor(breadthFirstSearchVisitor).color_map(get(boost::vertex_color_t(), g)));

Örnek
Şöyle yaparız
VertexDescr source = ...; 
VertexDescr target = ...;
DirectedGraph const  g = ...;

std::vector<double> distances(num_vertices(g));
std::vector<boost::default_color_type> colormap(num_vertices(g));

// Run BFS and record all distances from the source node
breadth_first_search(g, source,
  visitor(make_bfs_visitor(boost::record_distances(distances.data(),
    boost::on_tree_edge())))
    .color_map(colormap.data())
);

for (auto vd : boost::make_iterator_range(vertices(g)))
  if (colormap.at(vd) == boost::default_color_type{})
    distances.at(vd) = -1;



Hiç yorum yok:

Yorum Gönder