@MISC{Eijck_assertivecoding, author = {Jan Van Eijck}, title = {Assertive Coding for Graph Algorithms and Matching Algorithms}, year = {} }

Share

OpenURL

Abstract

This lecture discusses a number of well-known graph algorithms, develops testable specifications for them, and uses the specifications to write assertive (self-testing) versions of the algorithms. Next, we move on to a famous matching algorithm “Stable Marriage”.Module Declaration module Week6 where import Data.List import While import Assert The modules While and Assert give the code for while loops and for assertion and invariant wrappers that was developed and discussed in the lecture on Algorithm Specification. Background on the key importance of graph theory for the analysis of what goes on in social and other networks can be found in [1]. An enlightening introduction to graph algorithms is [3].Basic Update Operation Here is the general definition of the update of a function for a single argument-value pair: update:: Eq a => (a-> b)-> (a,b)-> a-> b update f (y,z) x = if x = = y then z else f x And here is the update of a function for a list of argument-value pairs: updates:: Eq a => (a-> b)-> [(a,b)]-> a-> b updates = foldl update These function updates will be a key ingredient in some of the algorithms below. A Graph Reachability Algorithm A directed graph G without parallel edges is a pair (V, E) with E ⊆ V 2. If (v1, v2) ∈ E, we write this as v1 → v2, and we say that there is an edge from v1 to v2. A vertex y is reachable from a vertex x in G = (V, E) if there is a path of → edges from x to y, or, equivalently, if (x, y) ∈ E ∗ , where E ∗ is the reflexive transitive closure of E. In an algorithm for this, we can assume G is given by its edge set E.Algorithm for Graph Reachability Here is an algorithm that computes the set of reachable vertices from a given vertex. Graph reachability algorithm • Let edge set E and vertex x be given; • C: = {x}, M: = {x}; • while C = ∅ do: – select y ∈ C;