overcoming non distributivity
play

Overcoming non Distributivity A Case Study through Functional - PowerPoint PPT Presentation

Overcoming non Distributivity A Case Study through Functional Programming Juan C Saenz-Carrasco and Mike Stannett Agenda Introduction Definitions The Problem A Functional Approach Applications Conclusion Introduction In order to solve


  1. Overcoming non Distributivity A Case Study through Functional Programming Juan C Saenz-Carrasco and Mike Stannett

  2. Agenda Introduction Definitions The Problem A Functional Approach Applications Conclusion

  3. Introduction In order to solve path finding problems, we should take care about some properties prior the computation of the corresponding algorithm. Some of such properties are: • associativity • distributivity Same goes for the definitions of the operators involved in the (host) algorithm

  4. Definitions: Path Addition

  5. Definitions: Path Addition We consider addition to the computation of the labels (or weights) of two or more edges or paths:

  6. Definitions: Path Addition We consider addition to the computation of the labels (or weights) of two or more edges or paths: x y b a z

  7. Definitions: Path Addition We consider addition to the computation of the labels (or weights) of two or more edges or paths: x y b a z The addition of paths from a to b can be denoted as x ⊕ y ⊕ z , provided the definition for ⊕ .

  8. Definitions: Path Multiplication

  9. Definitions: Path Multiplication We consider multiplication to the computation of the labels (or weights) of two or more consecutive edges or paths:

  10. Definitions: Path Multiplication We consider multiplication to the computation of the labels (or weights) of two or more consecutive edges or paths: y x b a c

  11. Definitions: Path Multiplication We consider multiplication to the computation of the labels (or weights) of two or more consecutive edges or paths: y x b a c The multiplication of paths from a to c can be denoted as x ⊗ y , provided the definition for ⊗ .

  12. Example Let us compute the maximum capacity problem for the following graph, where operators ⊗ 1 = minimum (or ↓ ) and ⊕ 1 = maximum (or ↑ ) 1 1 c 1 2 b a e Now, the maximum capacity from a to e is 1 no matter which path from a to e is selected. That is, we have a tie

  13. Example (cont’d) Now, we can incorporate another criterion to break such a tie, let’s say that we pick the shortest distance, implying ⊗ 2 = arithmetic addition (+) and ⊕ 2 = minimum ( ↓ ). That is, now we have that: ⊗ = ( ⊗ 1 , ⊗ 2 ) and ⊕ = ( ⊕ 1 , ⊕ 2 ) in other words, ⊗ = ( ↓ 1 , + 2 ) and ⊕ = ( ↑ 1 , ↓ 2 )

  14. Example (cont’d) Also, we add the corresponding values for the new criterion as the second element in the pair-labels over the edges. That is, a pair (v j ,v k ) defines v j as the valid elements for maximum capacity and v k as the valid elements for shortest distance. (1,1) (1,1) c (1,1) (2,3) b d a

  15. The Problem Computing the maximum capacity again, yields to a non optimal solution, that is, (1,1) (1,1) c (2,3) b d the partial result, being (2,3) as (maximum capacity, shortest distance) leads to (1,4) instead of (1,3) in the final computation a (1,1) (2,3) b’ d’

  16. The Problem (cont’d) Algebraically, we can represent the above as follows: (1,1) ⊗ [ (1,1) ⊗ (1,1) ⊕ (2,3) ] = (1,1) ⊗ (1,1) ⊗ (1,1) ⊕ (1,1) ⊗ (2,3) (1,1) ⊗ [ (1,2) ⊕ (2,3) ] = (1,1) ⊗ (1,2) ⊕ (1,4) (1,1) ⊗ [(2,3)] = (1,3) ⊕ (1,4) (1,4) ≠ (1,3)

  17. Fun Approach: List of Pairs Preserving local optimal and “potential” optimal results along the computation in a list, allows to compute the global optimal. The conditions are: storing the elements (pairs) preserving the following relation: (x 1 , y 1 ) R (x 2 , y 2 ) → x 1 > x 2 ∧ y 1 > y 2 ∨ (x 2 , y 2 ) R (x 1 , y 1 ) → x 2 > x 1 ∧ y 2 > y 1 otherwise simply store the greatest x-tuple

  18. List of Pairs applied let us denoted the list notation with {} (1,1) ⊗ [ (1,1) ⊗ (1,1) ⊕ (2,3) ] → (1,1) ⊗ [ { (1,2) } ⊕ (2,3) ] → (1,1) ⊗ [ { (2,3),(1,2) } ] → (1,1) ⊗ [ { (2,3),(1,2) } ] → { (1,3) } the global optimal as expected !!

  19. implementing MC-SD We start with the types, calling join for ⊗ and choose for ⊕ since the functions should work either edges or paths, we turn every edge label into a singleton-path prior any computation [ (1,1) ] [ (1,1) ] c [ (1,1) ] [ (2,3) ] b d a

  20. Application: Single Source on DAGs

  21. Application: Single Source on DAGs

  22. Application: Single Source on DAGs (c 45 ,l 45 )

  23. Application: Single Source on DAGs (c 45 ,l 45 ) ⊗ sol 5

  24. Application: Single Source on DAGs (c 45 ,l 45 ) ⊗ sol 5 sol 4

  25. Application: Single Source on DAGs (c 45 ,l 45 ) ⊗ sol 5 sol 4 sol 5 = ( ∞ ,0)

  26. Application: Single Source on DAGs (c 45 ,l 45 ) ⊗ sol 5 sol 4 sol 5 = ( ∞ ,0) ?

  27. Application: Single Source on DAGs (c 45 ,l 45 ) ⊗ sol 5 sol 4 sol 5 = ( ∞ ,0) ? unit for ⊗

  28. Application: Single Source on DAGs (c 45 ,l 45 ) ⊗ sol 5 sol 4 sol 5 = ( ∞ ,0) ? unit for ⊗ double arrow single arrow (sol 2 ) dashed arrow (sol 3 ) ⊕ ⊕ ⊕ (c 15 ,l 15 ) ⊗ sol 5 (c 25 ,l 25 ) ⊗ sol 5 (c 35 ,l 35 ) ⊗ sol 5 (c 14 ,l 14 ) ⊗ sol 4 (c 24 ,l 24 ) ⊗ sol 4 (c 34 ,l 34 ) ⊗ sol 4 (c 13 ,l 13 ) ⊗ sol 3 (c 23 ,l 23 ) ⊗ sol 3 (c 12 ,l 12 ) ⊗ sol 2

  29. Application: Single Source on DAGs (c 45 ,l 45 ) ⊗ sol 5 sol 4 sol 5 = ( ∞ ,0) ? unit for ⊗ double arrow single arrow (sol 2 ) dashed arrow (sol 3 ) ⊕ ⊕ ⊕ (c 15 ,l 15 ) ⊗ sol 5 (c 25 ,l 25 ) ⊗ sol 5 (c 35 ,l 35 ) ⊗ sol 5 (c 14 ,l 14 ) ⊗ sol 4 (c 24 ,l 24 ) ⊗ sol 4 (c 34 ,l 34 ) ⊗ sol 4 (c 13 ,l 13 ) ⊗ sol 3 (c 23 ,l 23 ) ⊗ sol 3 sounds familiar ? (c 12 ,l 12 ) ⊗ sol 2

  30. Application: Single Source on DAGs (c 45 ,l 45 ) ⊗ sol 5 sol 4 sol 5 = ( ∞ ,0) ? unit for ⊗ double arrow single arrow (sol 2 ) dashed arrow (sol 3 ) ⊕ ⊕ ⊕ (c 15 ,l 15 ) ⊗ sol 5 (c 25 ,l 25 ) ⊗ sol 5 (c 35 ,l 35 ) ⊗ sol 5 That’s right: Dynamic (c 14 ,l 14 ) ⊗ sol 4 (c 24 ,l 24 ) ⊗ sol 4 (c 34 ,l 34 ) ⊗ sol 4 Programming !!! (c 13 ,l 13 ) ⊗ sol 3 (c 23 ,l 23 ) ⊗ sol 3 sounds familiar ? (c 12 ,l 12 ) ⊗ sol 2

  31. Application: All Pairs (square matrix) As an example of full (dense) connected graph, including cycles, we can recurre to the Floyd-Roy-Warshall algorithm (all-pairs shortest path) for each (i,j) in N x N: if (i,j) is in E then: d(i,j) := w(i,j) else: d(i,j) := 0 for each k in N: for each i in N: for each j in N: d(i,j) := min{d(i,j),d(i,k) + d(k,j)}

  32. Application: All Pairs (square matrix) As an example of full (dense) connected graph, including cycles, we can recurre to the Floyd-Roy-Warshall algorithm (all-pairs shortest path) for each (i,j) in N x N: if (i,j) is in E then: d(i,j) := w(i,j) else: d(i,j) := 0 for each k in N: for each i in N: for each j in N: d(i,j) := min{d(i,j),d(i,k) + d(k,j)}

  33. Application: All Pairs (square matrix) As an example of full (dense) connected graph, including cycles, we can recurre to the Floyd-Roy-Warshall algorithm (all-pairs shortest path) for each (i,j) in N x N: if (i,j) is in E then: d(i,j) := w(i,j) :: [(Capacity, Distance)] else: d(i,j) := 0 for each k in N: for each i in N: for each j in N: d(i,j) := min{d(i,j),d(i,k) + d(k,j)}

  34. Application: All Pairs (square matrix) As an example of full (dense) connected graph, including cycles, we can recurre to the Floyd-Roy-Warshall algorithm (all-pairs shortest path) for each (i,j) in N x N: if (i,j) is in E then: d(i,j) := w(i,j) :: [(Capacity, Distance)] else: d(i,j) := 0 for each k in N: for each i in N: for each j in N: d(i,j) := min{d(i,j),d(i,k) + d(k,j)}

  35. Application: All Pairs (square matrix) As an example of full (dense) connected graph, including cycles, we can recurre to the Floyd-Roy-Warshall algorithm (all-pairs shortest path) for each (i,j) in N x N: if (i,j) is in E then: d(i,j) := w(i,j) :: [(Capacity, Distance)] else: d(i,j) := 0 unit for ⊕ , that is [(0, ∞ )] for each k in N: for each i in N: for each j in N: d(i,j) := min{d(i,j),d(i,k) + d(k,j)}

  36. Application: All Pairs (square matrix) As an example of full (dense) connected graph, including cycles, we can recurre to the Floyd-Roy-Warshall algorithm (all-pairs shortest path) for each (i,j) in N x N: if (i,j) is in E then: d(i,j) := w(i,j) :: [(Capacity, Distance)] else: d(i,j) := 0 unit for ⊕ , that is [(0, ∞ )] for each k in N: for each i in N: for each j in N: d(i,j) := min{d(i,j),d(i,k) + d(k,j)}

  37. Application: All Pairs (square matrix) As an example of full (dense) connected graph, including cycles, we can recurre to the Floyd-Roy-Warshall algorithm (all-pairs shortest path) for each (i,j) in N x N: if (i,j) is in E then: d(i,j) := w(i,j) :: [(Capacity, Distance)] else: d(i,j) := 0 unit for ⊕ , that is [(0, ∞ )] ⊕ , that is ( ⊕ 1 , ⊕ 2 ) for each k in N: for each i in N: for each j in N: d(i,j) := min{d(i,j),d(i,k) + d(k,j)}

  38. Application: All Pairs (square matrix) As an example of full (dense) connected graph, including cycles, we can recurre to the Floyd-Roy-Warshall algorithm (all-pairs shortest path) for each (i,j) in N x N: if (i,j) is in E then: d(i,j) := w(i,j) :: [(Capacity, Distance)] else: d(i,j) := 0 unit for ⊕ , that is [(0, ∞ )] ⊕ , that is ( ⊕ 1 , ⊕ 2 ) for each k in N: for each i in N: for each j in N: d(i,j) := min{d(i,j),d(i,k) + d(k,j)}

Recommend


More recommend