SWS: Group 4 Laurence Cabenda, Niels Reyngoud, Roy van den Broek
Problem Find a generic specification for graph problems like “shortest path” and “highest path” Give the abstract specification Embed concrete problems into this specification We assume that we have a start and an end node
Given: Some type Node Some type D :: (Path, L) Path :: Sequence(Node x Node) L = R U { } : absorbing element of L Example: When adding real numbers, is the absorbing element
Given: We stepped away from last weeks representation with the operators defined on a type D : L -> L -> L Combining the values of two sequential paths : L -> L -> L Choosing the best value out of the values of two parallel paths Both are commutative and associative
Input: Sequence S {0…n-1} -> Node Function f: Node x Node -> L Returns the value of the arc between two nodes Gives back when there’s no direct arc between two nodes Node start, end, such that start end
Output: (solution_path, solution_value) :: D
Intermezzo: All possible paths We need to have a notion of all possible paths P is the set of all possible paths P = P seq (all 2_tuplepermutations of S )
Intermezzo: All possible paths 2_tuplepermutations {1,2,3} -> {(1,2),(1,3),(2,1),(2,3),(3,1),(3,2)} Analog to k_permutations of a set, k_permutations gives a set of sets k_tuplepermutations gives a set of tuples
Intermezzo: All possible paths P seq (powersequence) {(1,2),(1,3),(2,1),(2,3),(3,1),(3,2)} -> { [(1,2)], [(1,2),(1,3)], [(1,2),(1,3),(2,3)], [(1,3),(1,2)], … } Analog to powerset of a set powerset gives a set of sets powersequences gives a set of sequences
Intermezzo: All possible paths New problem: not all of these paths are valid (e.g. of the form (a,b), (b,c), … ) A path P with length n is valid if: i {0..n-2} : f(fst(P[i]), snd(P[i])) snd(p[i]) = fst(P[i+1])
Another helper function We assume a function exists that calculates the value of a path. value could be defined as: value [] = 0 value (a,b) = f(a,b) value (a,b):rest = f(a,b) value(rest)
Such that: solution_path must be valid: valid solution_path solution_path should have the correct start and finish nodes first(head(solution_path)) = start second(last(solution_path)) = end solution_value must be equal to the value of solution_path solution_value = value (solution_path)
Such that: And most important ;-): (solution_path, solution_value) is the best possible solution: (pospath, posval = value (pospad)) : pospath P : (valid pospath /\ fst (head (pospath)) = s /\ snd (last (pospath)) = e ) -> solution_value posval = solution_value
Embedding shortest path Shortest path: should be defined as should be defined as + should be defined as The generic operators in valid, value and the notion of best path now become concrete
Embedding highest path Highest path: should be defined as 0 should be defined as should be defined as