计算下一个最短路径(到目的地的最小跳数)
calculate next shortest path(minimum hop to destination)
这里是omnet使用Dijkstra计算最短路径(hop)的结构。
void cTopology::calculateUnweightedSingleShortestPathsTo(Node * _target) {
// multiple paths not supported :-(
if (!_target) throw cRuntimeError(this, "..ShortestPathTo(): target node is NULL");
target = _target;
for (int i = 0; i < num_nodes; i++) {
nodev[i].known = false; // not really needed for unweighted
nodev[i].dist = INFINITY;
nodev[i].out_path = NULL;
}
target - > dist = 0;
std::deque < Node * > q;
q.push_back(target);
while (!q.empty()) {
Node * v = q.front();
q.pop_front();
// for each w adjacent to v...
for (int i = 0; i < v - > num_in_links; i++) {
if (!(v - > in_links[i] - > enabl)) continue;
Node * w = v - > in_links[i] - > src_node;
if (!w - > enabl) continue;
if (w - > dist == INFINITY) {
w - > dist = v - > dist + 1;
w - > out_path = v - > in_links[i];
q.push_back(w);
}
}
}
}
我想找到并记录下下一个最短的跳跃。有人能在这件事上帮我吗?理论上,我需要创建一个新的结构,在没有之前选择的下一个节点的情况下计算最短路径,对吧?。感谢
让它变得更容易
你可以使用
parent[]存储有关上一个节点的数据/id'。。
那么要获得路径,你只需要反转它。
parent[parent[goal]]->parent[target]->parent[目标]
关于代码,你可以在这里看到。。。
http://pastebin.com/YUBicFjy
相关文章:
- 重新定位图像时如何前进到下一个内存块
- 为什么C++对链表中的下一个节点使用指针,而像 C# 或 Java 这样的语言只使用类 Node 的名称?
- 用于在 C++ 中使用 while 循环查找下一个素数的简单函数
- CIN 仅在输入非数字值时跳过下一个 CIN
- 查找最小的下一个更大的元素
- 转到基于范围的 for 循环中的下一个迭代器
- 如何检查流中文件的下一个单词是否为 alpha?
- 如何打印下一个字母直到 Z 并继续到 A?
- 在使用堆栈为下一个最大数字编写代码时面临 SIGSEGV(分段错误)
- 使用一个内存集数组和单个堆栈在 O(n) 中查找数组的下一个更大元素
- 有没有一种标准方法可以在C++中获取第 n 个"下一个"浮点值
- 下一个云桌面客户端构建过程
- C++自定义流操纵器,用于更改流上的下一个字符串
- 链表指针赋值为什么我们不能直接将尾巴分配给 temp 而不是尾巴>尾巴下一个
- 下一个排列定义
- 查找下一个具有真值C++的数组索引
- 如何比较文件中包含的下一个字符
- 检查IP是否在其他IP网络范围内,并查找下一个可用IP
- 当我使用c++生成器时,如何在输入完成后自动跳转到下一个"TEdit"
- 计算下一个最短路径(到目的地的最小跳数)