Yen shortest path algorithm is the K

As we all know, Dijkstra algorithm can obtain a shortest path, but if you want to ask a number of short path or a number of the shortest path can not be obtained, the need to use Yen algorithm.

 1 Yen algorithm principle

  • First, using Dijkstra's algorithm obtained from the source node to the Q shortest path first destination node (1).
  • Next, when evaluated K-1 of short path using departing from the idea of ​​the algorithm is recursive path method.
  • When seeking Q (i + 1), all the nodes (1) Q in addition to the destination node are regarded as a departure node, and offset from each node to calculate the shortest path between the destination node, then the Q ( 1 on the source node) node of the path deviates spliced ​​together constitute the candidate path to deviate from the shortest path is obtained.

 2 Yen algorithm illustrated

      

     Source points C, H end

    1) C obtained by Dijkstra shortest path algorithm to the shortest path H

         Q(1)=C-E-F-H(5)

    2) deviates from the point C, E, F

    3) C-> H, candidate path: CDFH (8)

    4) E-> H, candidate path: CEGH (7)

    5) F-> H, candidate path: CEFGH (8)

    6) the second short path: Q (2) = CEGH (7)

3 supplement knowledge (Yen algorithm)

  Q: What suitable route selected from the candidate list

  If the path of minimum weight and a number of road: the number of nodes from which to select the least path.

  Q: Vi to find the shortest path to the end point d

  Provided the starting point for the s, the end of t, departing from the point Vi. Pay attention to two problems to find the shortest path deviates end point

(1) preventing the entire path from the beginning to the end with a ring

         Any node can not contain Vi shortest path from s to t Vi is on the path

(2) has a path to avoid duplication with the result list

        Vi is not emitted from the side of p1 and the path in the result list, p2, ... pk, emitted from the same side of the Vi

Guess you like

Origin www.cnblogs.com/Horizon-asd/p/12602273.html
Recommended