Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3999472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:39:41+00:00 2026-05-20T07:39:41+00:00

I’m using Boost Graph to try and make sense of some dependency graphs I

  • 0

I’m using Boost Graph to try and make sense of some dependency graphs I have generated in Graphviz Dot format.

Unfortunately I don’t know very much about graph theory, so I have a hard time framing what I want to know in terms of graph theory lingo.

From a directed dependency graph with ~150 vertices, I’d like to “zoom in” on one specific vertex V, and build a subgraph containing V, all its incoming edges and their incoming edges, all its outgoing edges and their outgoing edges, sort of like a longest path through V.

These dependency graphs are pretty tangled, so I’d like to remove clutter to make it clearer what might affect the vertex in question.

For example, given;

     g
     |
     v
a -> b -> c -> d
|    |         |
v    v         |
e    f <-------+

if I were to run the algorithm on c, I think I want;

     g
     |
     v
a -> b -> c -> d -> f

Not sure if b -> f should be included as well… I think of it as all vertices “before” c should have their in-edges included, and all vertices “after” c should have their out-edges included, but it seems to me that that would lose some information.

It feels like there should be an algorithm that does this (or something more sensible, not sure if I’m trying to do something stupid, cf b->f above), but I’m not sure where to start looking.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:39:42+00:00Added an answer on May 20, 2026 at 7:39 am

    Ok, so I’ll translate and adapt my tutorial to your specific question.
    The documentation always assumes tons of “using namespace”; I won’t use any so you know what is what.
    Let’s begin :

    #include <boost/graph/adjacency_list.hpp>
    #include <boost/graph/astar_search.hpp>
    

    First, define a Vertex and an Edge :

    struct Vertex{
        string name; // or whatever, maybe nothing
    };
    struct Edge{
        // nothing, probably. Or a weight, a distance, a direction, ...
    };
    

    Create the type or your graph :

    typedef boost::adjacency_list<  // adjacency_list is a template depending on :
        boost::listS,               //  The container used for egdes : here, std::list.
        boost::vecS,                //  The container used for vertices: here, std::vector.
        boost::directedS,           //  directed or undirected edges ?.
        Vertex,                     //  The type that describes a Vertex.
        Edge                        //  The type that describes an Edge
    > MyGraph;
    

    Now, you can use a shortcut to the type of the IDs of your Vertices and Edges :

    typedef MyGraph::vertex_descriptor VertexID;
    typedef MyGraph::edge_descriptor   EdgeID;
    

    Instanciate your graph :

    MyGraph graph;
    

    Read your Graphviz data, and feed the graph :

    for (each Vertex V){
        VertexID vID = boost::add_vertex(graph); // vID is the index of a new Vertex
        graph[vID].name = whatever;
    }
    

    Notice that graph[ a VertexID ] gives a Vertex, but graph[ an EdgeID ] gives an Edge. Here’s how to add one :

    EdgeID edge;
    bool ok;
    boost::tie(edge, ok) = boost::add_edge(u,v, graphe); // boost::add_edge gives a std::pair<EdgeID,bool>. It's complicated to write, so boost::tie does it for us. 
    if (ok)  // make sure there wasn't any error (duplicates, maybe)
        graph[edge].member = whatever you know about this edge
    

    So now you have your graph. You want to get the VertexID for Vertex “c”. To keep it simple, let’s use a linear search :

    MyGraph::vertex_iterator vertexIt, vertexEnd;
    boost::tie(vertexIt, vertexEnd) = vertices(graph);
    for (; vertexIt != vertexEnd; ++vertexIt){
        VertexID vertexID = *vertexIt; // dereference vertexIt, get the ID
        Vertex & vertex = graph[vertexID];
        if (vertex.name == std::string("c")){} // Gotcha
    }
    

    And finally, to get the neighbours of a vertex :

    MyGraph::adjacency_iterator neighbourIt, neighbourEnd;
    boost::tie(neighbourIt, neighbourEnd) = adjacent_vertices( vertexIdOfc, graph );
    for(){you got it I guess}
    

    You can also get edges with

    std::pair<out_edge_iterator, out_edge_iterator> out_edges(vertex_descriptor u, const adjacency_list& g)
    std::pair<in_edge_iterator, in_edge_iterator> in_edges(vertex_descriptor v, const adjacency_list& g)
     // don't forget boost::tie !
    

    So, for your real question :

    • Find the ID of Vertex “c”
    • Find in_edges recursively
    • Find out_edges recursively

    Example for in_edges (never compiled or tried, out of the top of my head):

    void findParents(VertexID vID){
        MyGraph::inv_adjacency_iterator parentIt, ParentEnd;
        boost::tie(parentIt, ParentEnd) = inv_adjacent_vertices(vID, graph);
        for(;parentIt != parentEnd); ++parentIt){
            VertexID parentID = *parentIt;
            Vertex & parent = graph[parentID];
            add_edge_to_graphviz(vID, parentID); // or whatever
            findParents(parentID);
        }
    }
    

    For the other way around, just rename Parent into Children, and use adjacency_iterator / adjacent_vertices.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.