Shortest path in “two-graph” with limited number of changes

后端 未结 1 1920
眼角桃花
眼角桃花 2021-01-16 06:02

Let\'s say we have two directed and positive-weighted graphs on one set of vertices (first graph represents for example rail-roads and the second one - bus lanes; vertices a

相关标签:
1条回答
  • 2021-01-16 06:57

    I don't think it is the best way, but you can create Nodes as follow:

    Node:(NodeId, GraphId, correspondenceLeftCount)
    

    (the total number of nodes will be number_of_initial_nodes * number_of_graphs * number_of_correspondences_allowed)

    So:

    For edge where GraphId doesn't change, correspondenceLeftCount doesn't change neither. You add a new Edge for correspondance:

    (NodeId, Graph1, correspondenceLeftCount) -> (NodeId, Graph2, correspondenceLeftCount - 1)`

    And for the request A->B: Your start point are (A, graph1, maxCorrespondenceLeftCount) and (A, graph2, maxCorrespondenceLeftCount).
    And your end points are (B, graph1, 0), ... , (B, graph1, maxCorrespondenceLeftCount), (B, graph2, 0), ... , (B, graph2, maxCorrespondenceLeftCount).

    So you may to have to adapt your Dijkstra implementation for the end condition, and to be able to insert more than one start point.

    0 讨论(0)
提交回复
热议问题