Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graph theory question, Java. Which algorithm to achieve the following

I have a graph, with X nodes and Y edges. Weighted edges. The point is to start at one node, and stop at another. Now here comes the problem;

Visualize the problem. The edges are roads, and the edge weights are the max weight limits for vehicles driving on the roads. We would like to drive the biggest truck possible from A to B. So the maximum allowed weight for a truck taking a given path is the smallest weight of all of the edges in that path. I want the largest maximum allowed weight for all paths from A to B.

Can I use some sort of Dijkstra's algorithm for this problem? I'm not sure how to express this problem in the form of an algorithm that I can implement. Any help is much appreciated.

Update: I tested out somethings that didn't work for me. A node would have to have one max truck for every incoming edge.


1 Answers

Dijkstra's algorithm should work, but your "distance" in this case is a bit weird. Your "distance" is the maximum sized truck you can get to a node. Let's call that M[v] for a node v. You need to process nodes in order from largest M[v] to smallest M[v] (opposite of normal Dijkstra), and calculate for each edge e from v to w:

M[w] = max(M[w], min(e.weight, M[v]))
like image 173
Keith Randall Avatar answered Jun 03 '26 04:06

Keith Randall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!