![](/img/trans.png)
[英]Is there a way that gives shortest path using Floyd-Warshall's algorithm where negative weight cycle exists whereas overlapped edges are not allowed?
[英]Is it possible to calculate the shortest path using Floyd Warshall's algorithm with a weight limit (C++)?
權重限制的重點是算法不應使用超過該限制的路徑,即使它是最短路徑。
因此,如果權重限制為 50,則在下圖中,算法應選擇從 0 到 2 的路徑。 https://i.stack.imgur.com/I9SCL.png
這是一些使用 Floyd Warshall 算法找到最短路徑的代碼
for (unsigned int i = 0; i < m; i++)
{
// Pick all vertices as source one by one
for (unsigned int j = 0; j < m; j++)
{
// Pick all vertices as destination for the
// above picked source
for (unsigned int k = 0; k < m; k++)
{
// If vertex k is on the shortest path from
// i to j, then update the value of dist[i][j]
if (dist[i][k] + dist[k][j] < dist[i][j])
{
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
我很確定您 沒有編寫該代碼。 但無論如何,如果某些邊由於“權重限制”而被禁止,則在設置初始邊成本時忽略它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.