Illustrating Stepwise Refinement Shortest Path ASMs Egon Börger Dipartimento di Informatica, Universita di Pisa

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

© Egon Börger: Linked List 1 Double Linked Lists : Desired Operations Define an ASM which offers the following operations, predicates and functions on.
Great Theoretical Ideas in Computer Science for Some.
Single Source Shortest Paths
Lecture 7 March 1, 11 discuss HW 2, Problem 3
Lecture 24 MAS 714 Hartmut Klauck
Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Congestion Games with Player- Specific Payoff Functions Igal Milchtaich, Department of Mathematics, The Hebrew University of Jerusalem, 1993 Presentation.
Shortest-paths. p2. Shortest-paths problems : G=(V,E) : weighted, directed graph w : E  R : weight function P=
Chapter 5 Shortest Paths: Label-Correcting Algorithms
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
CS 473Lecture 141 CS473-Algorithms I Lecture 14-A Graph Searching: Breadth-First Search.
Breadth-First Search of Graphs Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
CS38 Introduction to Algorithms Lecture 5 April 15, 2014.
Lectures on Network Flows
Asynchronous ASMs Network Leader Election Egon Börger Dipartimento di Informatica, Universita di Pisa
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Introduction to Computability Theory
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
Asynchronous ASMs Ring Load Balance Egon Börger Dipartimento di Informatica, Universita di Pisa
1 Mazes In The Theory of Computer Science Dana Moshkovitz.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Asynchronous ASMs Master/Slave Agreement Egon Börger Dipartimento di Informatica, Universita di Pisa
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
Data Flow Analysis Compiler Design Nov. 3, 2005.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Minimal Spanning Trees. Spanning Tree Assume you have an undirected graph G = (V,E) Spanning tree of graph G is tree T = (V,E T E, R) –Tree has same set.
Asynchronous ASMs Phase Synchronization on Undirected Trees Egon Börger Dipartimento di Informatica, Universita di Pisa
COS 423 Lecture 9 Shortest Paths II ©Robert E. Tarjan 2011.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Using Homogeneous Weights for Approximating the Partial Cover Problem
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
May 1, 2002Applied Discrete Mathematics Week 13: Graphs and Trees 1News CSEMS Scholarships for CS and Math students (US citizens only) $3,125 per year.
MA/CSSE 474 Theory of Computation DFSM Canonical Form Proof of NDFSM  DFSM ALGORITHM (as much as we have time for) This version includes the "answers"
Asynchronous Multi-Agent ASMs An Introduction Egon Börger Dipartimento di Informatica, Universita di Pisa
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
15.082J & 6.855J & ESD.78J September 23, 2010 Dijkstra’s Algorithm for the Shortest Path Problem.
The single-source shortest path problem (SSSP) input: a graph G = (V, E) with edge weights, and a specific source node s. goal: find a minimum weight (shortest)
Introduction to Graphs And Breadth First Search. Graphs: what are they? Representations of pairwise relationships Collections of objects under some specified.
15.082J & 6.855J & ESD.78J September 30, 2010 The Label Correcting Algorithm.
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
Great Theoretical Ideas in Computer Science for Some.
 2004 SDU 1 Lecture5-Strongly Connected Components.
CS38 Introduction to Algorithms Lecture 3 April 8, 2014.
Asynchronous ASMs Echo Algorithm Egon Börger Dipartimento di Informatica, Universita di Pisa
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
TIRGUL 10 Dijkstra’s algorithm Bellman-Ford Algorithm 1.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Data Structures and Algorithm Analysis Lecture 5
All-pairs Shortest paths Transitive Closure
Minimal Spanning Trees
Lectures on Network Flows
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Chapter 5. Optimal Matchings
Minimal Spanning Trees
CSE 421: Introduction to Algorithms
Enumerating Distances Using Spanners of Bounded Degree
Dijkstra’s Algorithm for the Shortest Path Problem
3.5 Minimum Cuts in Undirected Graphs
Lectures on Graph Algorithms: searching, testing and sorting
Basic Graph Algorithms
Algorithms (2IL15) – Lecture 7
3.2 Graph Traversal.
Chapter 24: Single-Source Shortest-Path
Presentation transcript:

Illustrating Stepwise Refinement Shortest Path ASMs Egon Börger Dipartimento di Informatica, Universita di Pisa

© Egon Börger:Shortest Path (ASM Refinements) 2 E. Börger, R. Stärk Abstract State Machines A Method for High-Level System Design and Analysis Springer-Verlag 2003 For update info see AsmBook web page: For details see Chapter 3.2 (Incremental Design by Refinements) of:

© Egon Börger:Shortest Path (ASM Refinements) 3 Shortest Path ASMs: Illustrating Stepwise Refinement Computing Graph Reachability Sets: M 0 Wave Propagation of Frontier: M 1 Neighborhoodwise Frontier Propagation : M 2 Edgewise Frontier Extension per Neighborhood: M 3 Queue and Stack Implementation of Frontier and Neighborhoods: M 4 Introducing abstract weights for measuring paths and computing shortest paths: M 5 (Moore’s algorithm) Instantiating data structures for measures and weights

© Egon Börger:Shortest Path (ASM Refinements) 4 Computing Graph Reachability Set The problem: –given a directed graph (NODE, E, source) (here mostly assumed to be finite) with a distinguished source node –label every node which is reachable from source via E –arrange the labeling so that it terminates for finite graphs Solution idea: –starting at source, move along edges to neighbor nodes and label every reached node as visited –proceed stepwise, pushing in each step the “frontier” of the lastly reached nodes one edge further, without revisiting nodes which have already been labeled as visited

© Egon Börger:Shortest Path (ASM Refinements) 5 Computing Reachability Set: Machine M 0 Initially only source is labeled as visited (V(source)=1) Wave Propagation Rule: for all (u,v)  E s.t. u is labeled as visited & v is not labeled as visited label v as visited Correctness Lemma : Each node which is reachable from source is exactly once labeled as visited Proof. Existence claim : induction on the length of paths from source Uniqueness property follows from the rule guard enforcing that only nodes not yet labeled as visited are considered for being labeled as visited Termination Lemma : For finite graphs, the machine terminates The meaning of termination: there is no more edge (u,v)  E whose tail u is labeled as visited but whose head v is not Proof. By each rule application, the set of nodes which are not labeled as visited decreases.

© Egon Börger:Shortest Path (ASM Refinements) 6 Identifying the FRONTIER of wave propagation frontier = set of nodes lastly labeled as visited (*) –Initially: frontier = {source} only source is labeled as visited M 1  scan forall u  frontier shift frontier to neighb(u) delete u from frontier Lemma: M 0 / M 1 steps are in 1-1 correspondence & perform the same labelings Proof: by run induction from (*) above label v as visited  visited(v):= true neigb(u) = {v| (u,v)  E} shift frontier to neighb  forall v  neighb shift frontier to v shift frontier to v  if v is not labeled as visited then insert v into frontier label v as visited NB.Nodes in frontier are labeled as visited

© Egon Börger:Shortest Path (ASM Refinements) 7 M 1 -run computing the reachability set s t Fire1 step frontier visited Fire1 step Animation courtesy of M. Veanes Frontier propagation: moving frontier simultaneously for each node in frontier to all its neighbors (restricted to those which have not yet been labeled as visited) u n 1,1 n 1,k n 1,i neighb(u) n 2,1 n 2,l In t steps all nodes reachable by a path of length at most t are labeled as visited

© Egon Börger:Shortest Path (ASM Refinements) 8 Refinement: Shifting frontier to neighborhood of ONE node per step determining one next node for frontier propagation by abstract scheduling function select (to be refined later) M 2  let u=select(frontier) in delete u from frontier shift frontier to neighb(u) scan frontier not empty Lemma 2. If M 2 in step t labels a node as visited, then M 1 does the same in some step t’  t. Proof: Ind(t) Lemma 1.  t  u  frontier t (M 2 )  t’  t s.t. u  frontier t’ (M 1 ) Proof: Ind(t) Corollary 3 : M 2 -labeling is complete if every node in frontier is eventually selected Corollary: M 1 terminates iff M 2 terminates Corollary 2: Uniqueness of M 1 -labeling preserved by M 2 assuming finite fan-out

© Egon Börger:Shortest Path (ASM Refinements) 9 Canonically relating M 1 - and M 2 - runs (for finite fan-out) Each run of M 1 can be simulated by a “breadth-first” run of M 2 producing the same labelings of nodes as visited, where each step of M 1 applied to frontier (M 1 ) in state S is simulated by selecting successively all the elements of frontier (M 1 ) in state S. M 2  let u=select(frontier) in delete u from frontier shift frontier to neighb(u) scan frontier not empty M 1  scan forall u  frontier delete u from frontier shift frontier to neighb(u)

© Egon Börger:Shortest Path (ASM Refinements) 10 Refinement: Edgewise frontier extension per neighborhood Refine M 2 -rule “shift frontier to neighb(u)” to a submachine shift- frontier-to-neighb which selects one by one every node v of neighb(u) to edgewise “shift frontier to v” (using another scheduling fct select ) shift-frontier- to-neighb (n)  label neighb not empty let v=select(neighb) in delete v from neighb shift frontier to v initialize neighb by n NB. With an appropriate mechanism for the initialization of submachines upon calling, executing M 2 -rule “shift frontier to neighb(u)” can be replaced by a call to shift-frontier-to- neighb(u).

© Egon Börger:Shortest Path (ASM Refinements) 11 Machine with edgewise frontier extension per neighborhood Each “shift frontier to neighb(u)” step of M 2 is refined by a run of M 3 -submachine “shift-frontier-to-neighb” with actual parameter neighb(u): started with initializing neighb to neighb(u), iterating “shift frontier to v” for every v in neighb, and exited by returning to scan, thus producing the same labeling of nodes as visited. Corollary: Correctness and Termination Lemma carry over from M 2 to M 3 (assuming finite fan-out and fair scheduling functions) M 3  neighb not empty label let v=select(neighb) in delete v from neighb shift frontier to v let u=select(frontier) in delete u from frontier initialize neighb by neighb(u) frontier not empty scan

© Egon Börger:Shortest Path (ASM Refinements) 12 Refinement of frontier to (fair) queue and of neighb to stack M 4  neighb not empty label let v=select(neighb) in delete v from neighb shift frontier to v let u=select(frontier) in delete u from frontier initialize neighb by neighb(u) frontier not empty scan neighborhood as stack select = top delete  pop for the initialization, neighb(u) is assumed to be given as stack for every u frontier as queue: select = first (at left end) delete …  frontier := rest(frontier) insert = append (at right end) NB. No node occurs more than once in frontier Exercise. Prove that M 4 preserves correctness and termination of M 3 Exercise. Write and test an efficient C++ program for machine M 4.

© Egon Börger:Shortest Path (ASM Refinements) 13 Computing the weight of paths from source to determine “shortest” paths to reachable nodes Measuring paths by accumulated weight of edges –(M,<) well-founded partial order of path measures with smallest element 0 and largest element  greatest lower bound glb(m,m’) for every m,m’  M –edge weight: E  WEIGHT –+: M  WEIGHT  M “ adding edge weight to path measure” monotonicity: m < m’ implies m + w < m + w distributivity wrt glb: glb(m,m’) + w = glb(m + w,m’ + w) –path weight:PATH  M defined inductively by weight(  ) = 0 weight(pe)= weight(p)+weight(e)

© Egon Börger:Shortest Path (ASM Refinements) 14 Computing minimal weight of paths min-weight: NODE  M defined by –min-weight(u) = glb{weight(p)| p is a path from source to u} NB. The function is well-defined since by the well- foundedness of <, countable sets of measures (which may occur due to paths with cycles) have a glb Successive approximation of min-weight from above for nodes reachable from source by a function up-bd: NODE  M –initially up-bd(u) =  for all u except up-bd(source) = 0 –for every v reachable by an edge e from u s.t. up-bd(v) can be decreased via up-bd(u)+weight(e), lower up-bd(v) to glb{up-bd(v), up-bd(u)+weight(e)} NB. If not up-bd(v)  up-bd(u)+weight(e), then glb{up-bd(v), up-bd(u)+weight(e)} < up-bd(v)

© Egon Börger:Shortest Path (ASM Refinements) 15 Refining M 4 to compute up-bd  min-weight: same machine refining “frontier shift” to “lowering up-bd” Initially: frontier = {source} ctl-state = scan up-bd(u)=  for all u except up-bd(source) = 0 shift frontier to v  if v is not labeled as visited then label v as visited insert v into frontier shift frontier to v  if not up-bd(v)  up-bd(u)+weight(u,v) then up-bd(v):= glb{up-bd(v), up- bd(u)+weight(u,v)} if v  frontier then insert v into frontier lower up-bd(v) via u NB.frontier not a multi-set neighb not empty label let v=select(neighb) in delete v from neighb shift frontier to v let u=select(frontier) in delete u from frontier initialize neighb by (u,neighb(u)) frontier not empty scan M 4/5  Moore 1959

© Egon Börger:Shortest Path (ASM Refinements) 16 Refining termination and completeness proofs for M 5 Moore’s algorithm M 5 terminates (for finite graphs) –each scan step diminishes the size of frontier –each label step shrinks neighb; each head node v upon entering frontier gets up-bd(v) updated to a smaller value. Since < is well-founded, this can happen only finitely often. neighb not empty label let v=select(neighb) in delete v from neighb lower up-bd(v) via u let u=select(frontier) in delete u from frontier initialize neighb by (u,neighb(u)) frontier not empty scan

© Egon Börger:Shortest Path (ASM Refinements) 17 Correctness Proof for the computation of min-weight Theorem. When Moore’s algorithm M 5 terminates, min-weight(u)= up-bd(u) for every u. –Proof. min-weight(u)  up-bd(u) (lemma 1). Since up-bd(u) is a lower bound for weight(p) for every path p from source to u (lemma 2) and since min-weight by definition is the glb of such path weights, also  holds. Lemma 1. At each step t and for each v: min-weight(v)  up-bd(v) t. Lemma 2. When M 5 terminates, up-bd(v)  weight(p) for every path p from source to v.

© Egon Börger:Shortest Path (ASM Refinements) 18 Proof for the approximation of min-weight by up-bd Lemma 1. At each step t, for each v: min-weight(v)  up-bd(v) t. –Proof 1. Ind(t). For t=0 the claim holds by definition. At t+1 (only) rule “lower up-bd(v) via u” sets up-bd(v) t+1, namely to glb{up-bd(v) t, up-bd(u) t +weight(u,v)}. Remains to show –min-weight(v)  up-bd(v) t (which is true by ind.hyp. for v) –min-weight(v)  up-bd(u) t +weight(u,v) The latter relation follows from (*) min-weight(v)  min-weight(u)+weight(u,v) by min-weight(u)  up-bd(u) t (ind.hyp.) via monotonicity of + ad (*): glb({weight(p)| p path from source to v})  glb({weight(p.(u,v)) | p path from source to u}) = def weight glb({weight(p)+weight(u,v) | p path from source to u}) = glb distrib glb({weight(p) | p path from source to u}) +weight(u,v) = min-weight min-weight(u) +weight(u,v) lower up-bd(v) via u  if not up-bd(v)  up-bd(u)+weight(u,v) then up-bd(v):= glb{up-bd(v), up-bd(u)+weight(u,v)} if v  frontier then insert v into frontier

© Egon Börger:Shortest Path (ASM Refinements) 19 Proof for lower bound up-bd(v) of weight of paths to v Lemma 2. When M 5 terminates, up-bd(v)  weight(p) for every path p from source to v. –Proof 2. Ind(path length). For t=0 the claim holds by definition. Let p.(u,v) be a path of length t+1. up-bd(v)  up-bd(u) +weight(u,v) by termination of M 5 (otherwise lower up-bd(v) via u could fire) up-bd(u)  weight(p) (ind.hyp.), thus by monotonicity of + up-bd(u) +weight(u,v)  weight(p) +weight(u,v) = def weight weight(p.(u,v)) lower up-bd(v) via u  if not up-bd(v)  up-bd(u)+weight(u,v) then up-bd(v):= glb{up-bd(v), up-bd(u)+weight(u,v)} if v  frontier then insert v into frontier

© Egon Börger:Shortest Path (ASM Refinements) 20 Instantiating data structures for weight and measure (M,<) = (Nat  {  },<) well-founded order of shortest path measures with smallest element 0 and largest element  greatest lower bound glb(m,m’) = min(m,m’) WEIGHT = (Nat, +) with n+  =  monotonicity: m<m’ implies m+w<m’+w glb distributive wrt +: glb(m +w,m’ +w) = glb(m,m’)+w For an instantiation to the constrained shortest path problem see K. Stroetmann’s paper in JUCS For Dijkstra’s refinement M 5 see Ch of the AsmBook

© Egon Börger:Shortest Path (ASM Refinements) 21 References E. F. Moore: The Shortest Path Through a Maze. –Proc. International Symposium on the Theory of Switching, Part II, Vol. 30 of “The Annals of the Computation Laboratory of Harvard University”, Cambridge, MA, 1959, Harvard University Press. K. Stroetmann: The Constrained Shortest Path Problem: A Case Study in Using ASMs –In: J. of Universal Computer Science 3 (4), E. Börger, R. Stärk: Abstract State Machines. A Method for High-Level System Design and Analysis Springer-Verlag 2003, see Chapter