Boost图库:设置边权重值

发布于 2024-08-28 10:52:40 字数 504 浏览 7 评论 0原文

我正在研究 boost 图形库的使用,以便将它们应用于我想到的各种网络问题。

在示例中,我一直在查看图形边缘值(“权重”)始终初始化为整数,例如在这些 贝尔曼-福特Kruskal 算法 例如:

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

我的问题是,如果我尝试将权重更改为双倍,我会收到一堆有关转换等的警告消息,到目前为止我一直不知道如何克服。

有人看到解决这个问题的方法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-09-04 10:52:40

这是由于 weights[] 数组与 boost 图/算法用于边权重的类型不匹配造成的。

例如,在第一个链接的示例中,您还应该更改

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

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

在第二个

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

示例中

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

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文