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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:28:27+00:00 2026-06-11T19:28:27+00:00

I am using the Boost Graph Library to store an undirected graph with double

  • 0

I am using the Boost Graph Library to store an undirected graph with double edge weights and double vertex weights. At several places in my code, I need to apply Dijkstra’s algorithm in order to search for shortest paths. This works quite well until I decided I wanted to temporarily override the stored edge weights by my own weights (only temporarily, the graph weights shall not be modified). My code basically looks like this:

  // Initial typedefs

  typedef boost::property<boost::edge_weight_t, double> edge_weight_t;
  typedef boost::property<boost::vertex_discover_time_t, double> vertex_weight_t;
  typedef boost::adjacency_list<boost::vecS,
                                boost::vecS,
                                boost::undirectedS,
                                vertex_weight_t,
                                edge_weight_t> graph_t;

 // In a function, where graph is a const reference of type graph_t

 std::vector<double> pathLengths( boost::num_vertices( graph ) );

 boost::property_map<graph_t, boost::edge_weight_t>::type weightMap;
 boost::graph_traits<graph_t>::edge_iterator e_it, e_it_end;
 for( boost::tie( e_it, e_it_end ) = boost::edges( graph );
      e_it != e_it_end;
      ++e_it )
 {
   weightMap[ *e_it ] = 1.0;
 }

 boost::dijkstra_shortest_paths( graph,
                                 boost::vertex( vertex, graph ),
                                 boost::distance_map( &pathLengths[0] ).weight_map( weightMap ) );

Although graph is a const reference in the code above, the edge weights of the graph will be changed afterwards. What am I doing wrong? Or more specifically, how can I temporarily override the edge weights in a weighted graph?

Obviously, I could simply store the current edge weights, replace them by my weights, and change them back afterwards. However, I am convinced that I am at fault, and I do not want ignore this problem.

  • 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-11T19:28:29+00:00Added an answer on June 11, 2026 at 7:28 pm

    I had, I believe, the same issue – I wanted to temporarily (for a specific run of a search algorithm) modify edge weights, without permanently changing the graph itself. After some searching, I found this, which allows you to register a functor that is used to generate weights. This is used as the weight_map parameter:

    http://www.boost.org/doc/libs/1_51_0/boost/property_map/function_property_map.hpp

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

Sidebar

Related Questions

I am writing a Graph-class using boost-graph-library. I use custom vertex and edge properties
I'm using the Boost Graph Library to process an undirected graph, and declared my
I am using boost graph library for solving a network graph problem. I have
I have C++ program using boost graph library. I wonder if there is any
I need a functions thats find a cycle in an undirected graph (boost) and
I have a large graph (30k vertices, 250m edges) and using boost graph library
I am using the boost graph library to make a call to dijkstra_shortest_paths .
I'm looking at using Boost Graph Library as the basis for a dag graph.
Using the Boost Graph Library, is it possible to get the port identifiers for
I am confused about how to actually create a Graph using the boost library,

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.