1 / 9

FLOYD-WARSHALL Diseño y análisis de algoritmos. Luis Rodríguez Pérez.

FLOYD-WARSHALL Diseño y análisis de algoritmos. Luis Rodríguez Pérez. Algoritmo de Floyd-Warshall. Conocido también como la clausura transitiva de un grafo. Entrada: Grafo dirigido/no dirigido, con peso asociado a las aristas. Salida:

santa
Download Presentation

FLOYD-WARSHALL Diseño y análisis de algoritmos. Luis Rodríguez Pérez.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FLOYD-WARSHALL Diseño y análisis de algoritmos. Luis Rodríguez Pérez.

  2. Algoritmo de Floyd-Warshall • Conocido también como la clausura transitiva de un grafo. • Entrada: Grafo dirigido/no dirigido, con peso asociado a las aristas. • Salida: • Matriz Dn que entrega el menor camino para ir de un nodoi a un nodo j del grafo. • Matriz Sn que entrega el nodo intermedio para llegar desde un nodo i a un nodo j del grafo.

  3. D0 1 2 3 4 5 1 2 2 1 4 3 5 3 4 5 3 1 4 5 1 5 1 3 2 5 1 1 3 2 2 2 3 1 1 1 4 3 4 3 4 5 2 2 5 5 4 5 3 3 4 5 2 4 2 4 Ejemplo: • Tenemos el siguiente grafo: 5 3 4 3 10   6  3 5  15  10 10 6 15  5 6 4    4

  4. D0 S0 1 1 2 2 3 3 4 4 5 5 2 3 10 3   4 5 1 1  3 1 3 4 5  5 2 2  2 3 3 10 1 6 4 15 5  1 4 4 2 5 6 3 5 4 5 5    4 4 1 2 3 Ejemplo: • Ahora obtenemos la matriz S0

  5. 3 3 10 10         3 3 5    10 6 D1 S1 D0 S0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 3 2 10 3   4 5 1 1 1 1  3 3 1 5 4  5 2 2 2 2 2 3 4 5 3 10    2 3 3 3 3 1 10 4 6 15 5 1  1 3 4 4 4 4 2 5 6 3 5 4 5 5 5 5    4 4 1 2 3 1 10 1 2 3 5  5 6 4 4 1 2 3    4  < 5 ? 13 <  ?  <  ?  5  Cada vez que hay un  en una fila o columna esta, no cambia  < 6 ? 13 <  ? 6 15  < 15 ? 1 4 5 5  13 1 4 5 13 6 15

  6. 3 3 10 10   3 3 3 3 13 13 13 5 5 5 5  Como hay  en una fila y una columna estas se copian igual 10 10 13 13 6 6   5 6 S2 D1 D2 S1 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5  1 1 1 1 2 2 2 2 3 3 3 3 2 5 3  4 4 4 4 1 1 4 5 3 5  13 5 5 5 5 1 5 13 15 2 5 5 4 4 1 2 3    4 2 3 4 5 3 10   8 < ? 16 < 10 ? 1 1 4 5 3 5   13 1 18 < 6? 1 4 5 16 < 10? 13 10 6 15 1 2 3 5  8 < ? 5 6 4 18 < 6? 4 1 2 3    4 3 2 10 8 1 4 10 6 2 3 8 6

  7. 3 3 10 10 8 8   3 3 13 5 5  Como hay  en una fila esta se copia igual. 10 10 13 13 6 6 6 6 15 15 15 S3 S2 D2 D3 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5  1 1 1 1 2 2 2 2 3 3 3 3 2 2 3 2 5 3 3 3 10 8 25  4 4 4 4 3 1 1 1 1 4 5 3 3 5 28  13 13 5 5 5 5 1 1 1 4 5 5 13 13 10 6 15 15 2 2 2 3 5 5 8 5 5 6 4 4 4 4 1 1 2 2 3 3       4 4 10 8 23 < 3? 16< 8? 25< ? 3 2 23< 3? 28<  ? Como en la fila 4 todos los numeros son menores que la fila pivote(3), queda igual. 19< 5? 10 6 1 4 2 8 6 3 4 5

  8. 3 3 10 10 8 8 25 25 3 3 13 13 5 5 28 28 10 10 13 13 6 6 15 15 8 8 8 8 8 8 5 5 5 5 5 5 6 6 6 6 6 4 4 4 4 4 4 D3 D4 S3 S4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5      4 1 1 1 1 2 2 2 2 3 3 3 3 2 3 2 3 3 10 8 25 2 3 2 4 3 10 8 12 4 4 4 4 3 1 1 4 3 28 1 4 13 4 3 5 9 11 5 5 5 5 1 1 4 5 13 4 10 6 15 1 4 4 11 10 6 10 2 2 3 5 2 8 5 6 4 2 3 5 8 5 6 4 4 1 2 3    4 4 4 4 4 4 12 9 10 14< 10? 13< 3? 12< 25? 9< 28? 11< 13? 13< 3? 4 5 11< 13? 14< 10 10< 15? 12< ? 9< ? 10< ?

  9. 3 3 10 10 12 12 8 8 3 3 11 11 9 9 5 5 10 10 11 11 10 10 6 6 8 8 5 5 6 4 D5 D4 S5 S4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 12 12 12 12 12 12 9 9 9 9 9 9 10 10 10 10 10 4 4 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 2 3 2 4 3 10 8 12 2 3 2 4 3 10 8 12 4 4 4 4 1 4 4 4 3 9 1 4 11 4 3 5 5 9 11 5 5 5 5 4 1 4 4 11 4 10 6 10 1 4 4 11 10 6 10 2 2 2 2 3 3 5 5 8 8 5 5 6 6 4 4 4 4 4 4 4 12 9 10 4 4 4 4 4 12 9 10 16< 8? 22< 10? 21< 3? 21< 3? 13< 5? 19< 11? 14< 6? 19< 11? 22< 10? 13< 5? 14< 6? 16< 8? 4

More Related