Finding shortest path for multi-weighted edges between any two nodes

Rishabh1234
@rishabh1234-Oi9Xdl โ€ข Oct 26, 2024

How can we use use Dijkstra's algorithm to find shortest path when there are multiple edges having different weights to go from one node to another and also the availability of edges to go from one mode to another depends on the edge you have taken to come to that path.

This is the situation in the case of trip planning for cheapest path when there are multiple trains/flights between any two stations and arrival time at any intermediate node should be atleast some hours before the departure time of next flight/train.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • durga ch

    @durga-TpX3gO • Apr 22, 2015

    start with breadth first algorithm. let the distance of all nodes from source node be infinity. as and when a new node gets discovered update the distance with the shorted distance
    In case a node has already been discovered, compare the distances and re-update with shortest distance. maintain a DataStructure for path and update the same

  • Rishabh1234

    @rishabh1234-Oi9Xdl • Apr 22, 2015

    durgastart with breadth first algorithm. let the distance of all nodes from source node be infinity. as and when a new node gets discovered update the distance with the shorted distance
    In case a node has already been discovered, compare the distances and re-update with shortest distance. maintain a DataStructure for path and update the same

    This is precisely Dijkstra's algorithm but the case is not that simple.There are more than one edges between any two node and also availability of edge for lets say node 2 to node 3 depends on the edge you have chosen to come to node 2.

  • rahul69

    @rahul69-97fAOs • Apr 23, 2015

    Rishabh1234This is precisely Dijkstra's algorithm but the case is not that simple.There are more than one edges between any two node and also availability of edge for lets say node 2 to node 3 depends on the edge you have chosen to come to node 2.

    Well if that is the case, you can treat that node as two separate nodes. Thus it essentially boils down to simple structure which you can solve using dijkstra algorithm.
    ๐Ÿ˜€

  • Rishabh1234

    @rishabh1234-Oi9Xdl • Apr 23, 2015

    rahul69Well if that is the case, you can treat that node as two separate nodes. Thus it essentially boils down to simple structure which you can solve using dijkstra algorithm.
    ๐Ÿ˜€

    can you please elaborate . i am unable to understand which node you are referring and how you are proposing to split it.

  • durga ch

    @durga-TpX3gO • Apr 23, 2015

    if I got it right what Rahul suggested is this
    if there are 2 edges a ,b between nodes n1 and n2, then assume n2 as two nodes n2a and n2b , thus you end up having
    n1-(a)- n2a and n1-(b)-n2b
    also,. I supposed you should first eliminate duplicate edges before computing the end to end shortest path, you can look up the internet to find suitable methods to detect duplicate edges

  • Rishabh1234

    @rishabh1234-Oi9Xdl • Apr 24, 2015

    durgaif I got it right what Rahul suggested is this
    if there are 2 edges a ,b between nodes n1 and n2, then assume n2 as two nodes n2a and n2b , thus you end up having
    n1-(a)- n2a and n1-(b)-n2b
    also,. I supposed you should first eliminate duplicate edges before computing the end to end shortest path, you can look up the internet to find suitable methods to detect duplicate edges

    This will still won't solve the time constraint problem ๐Ÿ˜”