5

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?

Flexo
  • 87,323
  • 22
  • 191
  • 272
AndyUK
  • 3,933
  • 7
  • 42
  • 44

1 Answers1

6

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;
baol
  • 4,362
  • 34
  • 44
  • Hi the code can be seen in those links: bellman-example.cpp and kruskal-example.cpp – AndyUK Apr 09 '10 at 15:03
  • Your suggestion for the second (Kruskal) has worked, cheers. I cannot quite get over the Bellman hurdle yet. – AndyUK Apr 09 '10 at 15:17
  • In the bellman example you also need to change the type of the property map for the edges. Bundled properties are my favorite way to use the BGL (http://www.boost.org/doc/libs/1_42_0/libs/graph/doc/bundles.html). – baol Apr 09 '10 at 15:53