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

  • SEARCH
  • Home
  • 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 6779193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:21:22+00:00 2026-05-26T16:21:22+00:00

BGL’s depth_first_search algorithm sometimes calls back_edge() on visitors even if there are no cycles

  • 0

BGL’s depth_first_search algorithm sometimes calls back_edge() on visitors even if there are no cycles in the graph. By definition of back edge, and according to Boost’s DFS Visitor Documentation, this shouldn’t happen. Note that this is reproducible only when listS is used as the representation for both vertices and edges.

The code example below (should compile as is) constructs a graph with two nodes and a single edge. It incorrectly prints “back edge.” Am I doing anything wrong here? Or is this a bug?

#include <iostream>
using namespace std;

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/visitors.hpp>
using namespace boost;

typedef boost::property<boost::vertex_index_t,std::size_t> VertexProperties;
typedef boost::adjacency_list<boost::listS,
                              boost::listS,
                              boost::bidirectionalS,
                              VertexProperties> Graph;  // Graph object type

typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
typedef boost::graph_traits<Graph>::edge_descriptor Edge;

class VisitorClass : public dfs_visitor<> {
 public:
  VisitorClass() {}

  template <typename Edge, typename Graph>
  void back_edge(Edge, const Graph&) const {
    cout << "back edge" << endl;
  }
};

int
main() {
  Graph g;
  Vertex v = add_vertex(g);
  Vertex u = add_vertex(g);

  bool inserted;
  tie(tuples::ignore, inserted) = add_edge(v, u, g);
  assert(inserted);

  VisitorClass vst;
  depth_first_search(g, visitor(vst));
  // Should not print "back edge", but does.

  return 0;
}

Tested with Boost 1.46.1 using i686-apple-darwin11-llvm-g++-4.2 on Mac OS 10.7;

Tested with Boost 1.42.0 using gcc 4.4.5 on Debian 2.6.32-34squeeze1.

  • 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-26T16:21:23+00:00Added an answer on May 26, 2026 at 4:21 pm

    You filed a bug, but you didn’t follow up there.

    Not long afterwards, you got an answer:

    You are not initializing the vertex_index property of your graph. Try adding some code such as:

    graph_traits::vertices_size_type i = 0;

    BGL_FORALL_VERTICES(v, graph, Graph) put(vertex_index, g, v, i++);

    I tried this (fixing the typo) and it works fine:

    #include <boost/graph/iteration_macros.hpp>
    
    int main() {
      Graph g;   
      Vertex v = add_vertex(g);   
      Vertex u = add_vertex(g);
    
      graph_traits<Graph>::vertices_size_type i = 0;  
      BGL_FORALL_VERTICES(v, g, Graph) put(vertex_index, g, v, i++);
    
      bool inserted;   
      tie(tuples::ignore, inserted) = add_edge(v, u, g); 
      assert(inserted);
    
      VisitorClass vst;   
      depth_first_search(g, visitor(vst));
    // Should not print "back edge", but does.
    
      return 0;
      }
    

    (at least, it no longer prints “back edge”)

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

Sidebar

Related Questions

Anybody out there using BGL for large production servers? How many node does your
So I'm using a boost graph of the following type: typedef boost::adjacency_list<boost::listS, boost::vecS, boost:directedS,
I'm new to BGL. I'm trying to transform a range of edges to equivalent
How can i convert Babylon glossaries (*.BGL) to a database table (mySQL) ?
I'm currently dealing with a performance issue of graph implementation. Used technologies It is
This may be a rather novice or even wrong question so please be forgiving.
I'm looking at using Boost Graph Library as the basis for a dag graph.
I'm wondering if it's possible to make dynamic edges weights in BGL? I'm writing
I need to iterate over the vertices and edges of a BGL adjacency_list from
Perhaps this is a stupid question, but I'm trying to use BGL's dijkstra_shortest_paths ,

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.