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 8634337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:42:01+00:00 2026-06-12T09:42:01+00:00

I have a need to use the Boost library to get the shortest path

  • 0

I have a need to use the Boost library to get the shortest path from one point to another. I’ve looked over the example code and it is decently easy to follow. However, the example only shows how to get the overall distances. I’m trying to figure out how to iterate over the predecessor map to actually get the shortest path and I can’t seem to figure it out. I’ve read these two questions on the subject:

Dijkstra Shortest Path with VertexList = ListS in boost graph

Boost:: Dijkstra Shortest Path, how to get vertice index from path iterator?

But in both of the examples provided, the IndexMap typedef doesn’t seem to work with the Visual Studio compiler and, frankly, Boost typedefs are a little confusing to me and I’m having some trouble figuring all of this out. Based on the Boost example code here, could anyone tell me how I can just get the path out of it? I would be very thankful.

http://www.boost.org/doc/libs/1_46_1/libs/graph/example/dijkstra-example.cpp

  • 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-06-12T09:42:02+00:00Added an answer on June 12, 2026 at 9:42 am

    If you just want to get the path from the predecessor map you can do it like this.

    //p[] is the predecessor map obtained through dijkstra
    //name[] is a vector with the names of the vertices
    //start and goal are vertex descriptors
    std::vector< graph_traits< graph_t >::vertex_descriptor > path;
    graph_traits< graph_t >::vertex_descriptor current=goal;
    
    while(current!=start) {
        path.push_back(current);
        current=p[current];
    }
    path.push_back(start);
    
    //This prints the path reversed use reverse_iterator and rbegin/rend
    std::vector< graph_traits< graph_t >::vertex_descriptor >::iterator it;
    for (it=path.begin(); it != path.end(); ++it) {
    
        std::cout << name[*it] << " ";
    }
    std::cout << std::endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use IBM Informix for my project where I have point coordinates
I need to use the mongo-storm library and Clojars doesn't have it . So
I have a xsl file where i need to use parameters from an external
To use some recompiled libraries (f.ex. boost chrono) i need to specify the library
I have a macro that might look as follows (from boost log library) #define
I have some socket connection code that makes use of boost::asio which reads from
I have a thread pool that is using shared mutexes from the boost library.
I have the need to use a Stack-like data structure for a program that
I have installed Matlab r2010a on my computer I need use the function xlsread
I need to use something like get_or_create() but the problem is that I have

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.