开发者

Boost graph libraries: setting edge weight values

开发者 https://www.devze.com 2022-12-26 12:50 出处:网络
I am investigating the use of the boost graph libraries in order to apply them to various network problems I have in mind.

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 gra开发者_开发问答ph 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?


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消