Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost graph libraries: setting edge weight values

I am investigating the use of the boost graph libraries in order to apply them to various network problems I have in mind.

In the examples I have been looking at the graph edge values ("weights") are always initialized as integers, such as in these Bellman-Ford and Kruskal algorithms eg:

int weights[] = { 1, 1, 2, 7, 3, 1, 1, 1 };

My problem is if I try and change the weights to double, I get a heap of warning messages about conversions etc, which so far I have not been able to figure out how to overcome.

Does anyone see a way around this?

like image 561
AndyUK Avatar asked Apr 09 '10 14:04

AndyUK


People also ask

What are edge weights in a graph?

The weight of an edge is often referred to as the "cost" of the edge. In applications, the weight may be a measure of the length of a route, the capacity of a line, the energy required to move between locations along a route, etc.

Which data structure is used in Boost graph Library?

Data Structures The adjacency_matrix class stores edges in a |V| x |V| matrix (where |V| is the number of vertices). The elements of this matrix represent edges in the graph. Adjacency matrix representations are especially suitable for very dense graphs, i.e., those where the number of edges approaches |V|2.


1 Answers

It's caused by a mismatch between the weights[] array and the type used for edge weights by your boost graph/algorithm.

In the first linked sample, eg, you should also change

struct EdgeProperties {
  int weight;
};
[...]
property_map<Graph, int EdgeProperties::*>::type 

to

struct EdgeProperties {
  double weight;
};
[...]
property_map<Graph, double EdgeProperties::*>::type 

In the second

typedef adjacency_list < vecS, vecS, undirectedS,
    no_property, property < edge_weight_t, int > > Graph;

to

typedef adjacency_list < vecS, vecS, undirectedS,
    no_property, property < edge_weight_t, double > > Graph;
like image 79
baol Avatar answered Sep 29 '22 23:09

baol