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

overcoming non distributivity
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Overcoming non Distributivity

A Case Study through Functional Programming

Juan C Saenz-Carrasco and Mike Stannett

slide-2
SLIDE 2

Agenda

Introduction Definitions The Problem A Functional Approach Applications Conclusion

slide-3
SLIDE 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

slide-4
SLIDE 4

Definitions: Path Addition

slide-5
SLIDE 5

Definitions: Path Addition

We consider addition to the computation of the labels (or weights) of two or more edges or paths:

slide-6
SLIDE 6

Definitions: Path Addition

We consider addition to the computation of the labels (or weights) of two or more edges or paths:

a b

x y z

slide-7
SLIDE 7

Definitions: Path Addition

We consider addition to the computation of the labels (or weights) of two or more edges or paths:

a b

x y z

The addition of paths from a to b can be denoted as x ⊕ y ⊕ z, provided the definition for ⊕.

slide-8
SLIDE 8

Definitions: Path Multiplication

slide-9
SLIDE 9

Definitions: Path Multiplication

We consider multiplication to the computation of the labels (or weights)

  • f two or more consecutive edges or paths:
slide-10
SLIDE 10

Definitions: Path Multiplication

We consider multiplication to the computation of the labels (or weights)

  • f two or more consecutive edges or paths:

a b c

x y

slide-11
SLIDE 11

Definitions: Path Multiplication

We consider multiplication to the computation of the labels (or weights)

  • f two or more consecutive edges or paths:

a b c

x y

The multiplication of paths from a to c can be denoted as x ⊗ y, provided the definition for ⊗.

slide-12
SLIDE 12

Example

Let us compute the maximum capacity problem for the following graph, where operators ⊗1 = minimum (or ↓) and ⊕1 = maximum (or ↑)

a b c e

1 1 2 1

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

slide-13
SLIDE 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)

slide-14
SLIDE 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 (vj,vk) defines vj as the valid elements for maximum capacity and vk as the valid elements for shortest distance.

a b c d

(1,1) (1,1) (2,3) (1,1)

slide-15
SLIDE 15

The Problem

Computing the maximum capacity again, yields to a non optimal solution, that is,

a (1,1) b c d

(1,1) (2,3) (1,1)

the partial result, being (2,3) as (maximum capacity, shortest distance) leads to (1,4) instead of (1,3) in the final computation

b’ d’

(2,3)

slide-16
SLIDE 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)

slide-17
SLIDE 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: (x1, y1) R (x2, y2) → x1 > x2 ∧ y1 > y2 ∨ (x2, y2) R (x1, y1) → x2 > x1 ∧ y2 > y1

  • therwise simply store the greatest x-tuple
slide-18
SLIDE 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 !!

slide-19
SLIDE 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

a b c d

[(1,1)] [(1,1)] [(2,3)] [(1,1)]

slide-20
SLIDE 20

Application: Single Source on DAGs

slide-21
SLIDE 21

Application: Single Source on DAGs

slide-22
SLIDE 22

Application: Single Source on DAGs

(c45,l45)

slide-23
SLIDE 23

Application: Single Source on DAGs

(c45,l45) ⊗ sol5

slide-24
SLIDE 24

Application: Single Source on DAGs

(c45,l45) ⊗ sol5

sol4

slide-25
SLIDE 25

Application: Single Source on DAGs

sol5 = (∞,0) (c45,l45) ⊗ sol5

sol4

slide-26
SLIDE 26

Application: Single Source on DAGs

sol5 = (∞,0) ? (c45,l45) ⊗ sol5

sol4

slide-27
SLIDE 27

Application: Single Source on DAGs

sol5 = (∞,0) ? (c45,l45) ⊗ sol5

sol4

unit for ⊗

slide-28
SLIDE 28

Application: Single Source on DAGs

double arrow single arrow (sol2) dashed arrow (sol3)

⊕ ⊕ ⊕

(c15,l15) ⊗ sol5 (c25,l25) ⊗ sol5 (c35,l35) ⊗ sol5 (c14,l14) ⊗ sol4 (c24,l24) ⊗ sol4 (c34,l34) ⊗ sol4 (c13,l13) ⊗ sol3 (c23,l23) ⊗ sol3 (c12,l12) ⊗ sol2

sol5 = (∞,0) ? (c45,l45) ⊗ sol5

sol4

unit for ⊗

slide-29
SLIDE 29

Application: Single Source on DAGs

double arrow single arrow (sol2) dashed arrow (sol3)

⊕ ⊕ ⊕

(c15,l15) ⊗ sol5 (c25,l25) ⊗ sol5 (c35,l35) ⊗ sol5 (c14,l14) ⊗ sol4 (c24,l24) ⊗ sol4 (c34,l34) ⊗ sol4 (c13,l13) ⊗ sol3 (c23,l23) ⊗ sol3 (c12,l12) ⊗ sol2

sol5 = (∞,0) ? (c45,l45) ⊗ sol5

sol4

unit for ⊗

sounds familiar ?

slide-30
SLIDE 30

Application: Single Source on DAGs

double arrow single arrow (sol2) dashed arrow (sol3)

⊕ ⊕ ⊕

(c15,l15) ⊗ sol5 (c25,l25) ⊗ sol5 (c35,l35) ⊗ sol5 (c14,l14) ⊗ sol4 (c24,l24) ⊗ sol4 (c34,l34) ⊗ sol4 (c13,l13) ⊗ sol3 (c23,l23) ⊗ sol3 (c12,l12) ⊗ sol2

sol5 = (∞,0) ? (c45,l45) ⊗ sol5

sol4

unit for ⊗

sounds familiar ? That’s right: Dynamic Programming !!!

slide-31
SLIDE 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)}

slide-32
SLIDE 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)}

slide-33
SLIDE 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) 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)}

:: [(Capacity, Distance)]

slide-34
SLIDE 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) 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)}

:: [(Capacity, Distance)]

slide-35
SLIDE 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) 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)}

:: [(Capacity, Distance)] unit for ⊕, that is [(0,∞)]

slide-36
SLIDE 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) 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)}

:: [(Capacity, Distance)] unit for ⊕, that is [(0,∞)]

slide-37
SLIDE 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) 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)}

:: [(Capacity, Distance)] unit for ⊕, that is [(0,∞)]

⊕, that is (⊕1,⊕2)

slide-38
SLIDE 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) 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)}

:: [(Capacity, Distance)] unit for ⊕, that is [(0,∞)]

⊕, that is (⊕1,⊕2)

slide-39
SLIDE 39

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)}

:: [(Capacity, Distance)] unit for ⊕, that is [(0,∞)]

⊕, that is (⊕1,⊕2) ⊗, that is (⊗1,⊗2)

slide-40
SLIDE 40
slide-41
SLIDE 41
slide-42
SLIDE 42

What is next?

  • Include the analysis on Knapsack problem, where the ⊗ takes the weight
  • f the bag as an argument
  • Include an analysis on the lazy and strict evaluations
  • Monadic implementation (Floyd-Roy-Warshall algorithm)

http://staffwww.dcs.shef.ac.uk/people/J.Saenz_Carrasco/