-1

The point of the weight limit is that the algorithm should not use paths that exceed that limit even if it is the shortest path.

So if the weight limit was 50, in the graph below the algorithm should choose the path from 0 to 2. https://i.sstatic.net/I9SCL.png

This is some code to find the shortest path using Floyd Warshall's algorithm

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];
            }
        }
    }
}

1 Answer 1

1

I’m pretty sure you didn’t write that code. But in any case, if certain edges should be disallowed because of a “ weight limit”, just ignore them when setting the initial edge costs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.