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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:53:52+00:00 2026-05-24T03:53:52+00:00

I am using the boost graph library to make a call to dijkstra_shortest_paths .

  • 0

I am using the boost graph library to make a call to dijkstra_shortest_paths. However, I have something special setup in that the weight_map is actually a functor. Hence, everytime the boost library requires the weight of an edge, my functor is called, makes a complicated computation and delivers the result back to boost.

Unfortunately, in dijkstra_shortest_paths.hpp the struct dijkstra_bfs_visitor‘s method examine_edge has a get call to the weightmap, only to check if the returned value is negative. I am fully aware that I cannot use Dijkstra’s algorithm with negative values and I am certain that my functor only returns positive values. However, this check causes my functor to be called twice for each edge. As it performs a complicated computation I’d like to avoid performing it twice (the results don’t change between calls.. each edge gets the same wait during a dijkstra_shortest_paths run).

So far, I am manually checking the edge passed to the functor and in case of the duplicate call I am returning the previous remembered result. This clearly is more of a workaround than a solution.

I tried to pass my own visitor that overwrites examine_edge, however, the original method defined by boost’s dijkstra_bfs_visitor is still applied.

Does anyone know if there is a better way to handle this situation and somehow avoid the negate edge weight check?

  • 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-24T03:53:53+00:00Added an answer on May 24, 2026 at 3:53 am

    You are right, even supplying you own visitor the test of negativity will be performed.

      void examine_edge(Edge e, Graph& g) {
        if (m_compare(get(m_weight, e), m_zero))
            boost::throw_exception(negative_edge());
        m_vis.examine_edge(e, g);
      } 
    

    But anyway the weight_map is supposed to be called multiple time (see boost doc):

     for each vertex v in Adj[u]
      if (w(u,v) + d[u] < d[v])
        d[v] := w(u,v) + d[u]
    

    Just call djikstra with a precomputed weight map, every edge weight will have to be computed anyway.

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

Sidebar

Related Questions

I have C++ program using boost graph library. I wonder if there is any
I have a large graph (30k vertices, 250m edges) and using boost graph library
I am confused about how to actually create a Graph using the boost library,
I am using boost graph library for solving a network graph problem. I have
I am writing a Graph-class using boost-graph-library. I use custom vertex and edge properties
Can anyone please tell me that once I've created a graph using Boost Graph
I am trying to understand Directed Graph implementation (without Boost library that is mentioned
I'm using Boost Graph to try and make sense of some dependency graphs I
I am using boost::asio to make a socket network. The library has a number
Using the Boost Graph Library, is it possible to get the port identifiers for

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.