 Tags IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 # Find all reachable vertices in a Boost BGL graph efficiently

By : haha
Date : October 14 2020, 02:15 PM
I hope this helps you . I'm new to boost graph library and trying to solve the following problem: ,
Use a filtered_graph and just use BFS or DFS to traverse? code :

## Python - Graph Data Structure - How Do I Implement Breadth-First Search to Find Reachable Vertices Correctly

By : user3058430
Date : March 29 2020, 07:55 AM
I hope this helps . Your code is way too complicated.
Start with a code just implementing the fundamentals and add features gradually. In order to get you started I'll post something simple but fundamental when handling graphs.
code :
``````from collections import deque

class fringe(object):
def __init__(self, kind= 'stack'):
f= deque()
self._p= f.append if kind is 'stack' else f.appendleft
self._f= f

def __call__(self, item):
self._p(item)
return self

def __iter__(self):
while len(self._f):
item= self._f.pop()
yield item

def __repr__(self):
return self._f.__repr__().replace('deque', 'fringe')

def paths(G, start, terminal, F= fringe()):
for node, path in F((start, [start])):
for node in G[node]:
if node is terminal:
yield path+ [terminal]
elif node not in path:
F((node, path+ [node]))
``````
``````if __name__ == '__main__':
a, b, c, d, e, f= 'A', 'B', 'C', 'D', 'E', 'F'
G= {a: [b, c], b: [c, d], c: [d], d: [c], e: [f], f: [c]}
print 'All paths from:', a, 'to:', d
print 'BFS'
for path in paths(G, a, d): print path
print 'DFS'
for path in paths(G, a, d, fringe('queue')): print path
``````
``````All paths from: A to: D
BFS
['A', 'C', 'D']
['A', 'B', 'D']
['A', 'B', 'C', 'D']
DFS
['A', 'B', 'D']
['A', 'C', 'D']
['A', 'B', 'C', 'D']
``````

## find the minimum number of vertices in a directed graph from which the other vertices are reachable

By : Bomber Saichan
Date : March 29 2020, 07:55 AM
will be helpful for those in need For the graph without cycle(i.e acyclic graph), it will be easy. All the nodes without incoming edges will be an optimal solution. Since all other nodes should be reachable from one of the nodes.
For the graph with cycle, find strongly connected component first, then you get a acyclic graph. The method above works again.

## vertex or set of vertices reachable from all other vertices in a directed graph

By : user2711220
Date : March 29 2020, 07:55 AM
this one helps. Given a directed graph how to find vertex(call it "special vertex") that can be reached from all other vertices? It is not necessary that other vertices have to be reachable from this special vertex. , I would assume the graph is acyclic (i.e. a DAG)

## Find all reachable vertices in a Boost BGL graph using BFS

Date : March 29 2020, 07:55 AM
will be helpful for those in need The docs say that the Buffer needs to be a queue of vertex_descriptors. You accidentally declared it to have vertex_t (the vertex property bundle) as the value type.
Fix it:
code :
``````using vertex_descriptor = boost::graph_traits<Graph_t>::vertex_descriptor;

boost::queue<vertex_descriptor> Q;
``````
``````#include <boost/graph/adjacency_list.hpp>
#include <variant>
#include <queue>

struct node_t {
};
struct specialNode_t {
};
enum class TerminalType {
};

using vertex_t = std::variant<node_t, specialNode_t>; // structs
using edge_t = std::variant<TerminalType>;            // enum

using Graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, vertex_t, edge_t>;

int main() {
Graph_t myGraph(5);
boost::default_bfs_visitor vis; // Will do my collecting visitor later...

auto indexmap = boost::get(boost::vertex_index, myGraph);
auto colormap = boost::make_vector_property_map<boost::default_color_type>(indexmap);

using vertex_descriptor = boost::graph_traits<Graph_t>::vertex_descriptor;

boost::queue<vertex_descriptor> Q; 