88%(25)22 out of 25 people found this document helpful
This preview shows page 12 - 13 out of 13 pages.
neighbors as the adjacency list ofsinG8.For eacht∈listofneighbors:9.If not visited(t):10.ExploreSystem(t,G)GenerateInducedGraph(G0,dir)1.G:=G02.For each vertexv∈G:3.if (isRed(v,dir) ==false):4.removevfromGby removing its adjacency list5.For each edge(u,v)∈G:6.if (isRed(v,dir) ==false):7.remove edge(u,v)fromG8.ReturnGHasInfiniteRedLoops(s0)1.G= GenerateGraph(s0)2.Fori:=1,2,3,4:3.Gi:= GenerateInducedGraph(G,diri):4.if (hasCycle(Gi) ==true):5.Returntrue6.ReturnfalseProof of correctness.The procedures GenerateGraph() and ExploreSystem() correctly generate an adja-cency list ofGsince essentially they perform a DFS in G and in line 7 of procedure ExploreSystem() weadd inGthe adjacency list of the vertex we visit and then we recursively explore this adjacency list. Also,the procedure GenerateInducedGraph() generates correctly an induced graphGisince it removes fromGallthe vertices (states) that have green light in directiondiand all of their incoming edges.The only thing that remains to be proved (and also it implies the correctness of the procedure HasIn-finiteLoops()) is that a car can wait infinitely in a directiondiriif and only if there is a cycle in the inducedsubgraphGi.Let’s prove first the direction: a car can wait infinitely in a directiondiri⇒there is a cycle in the inducedsubgraphGi. Well, if a car can wait infinitely in a directiondirithen it means that there is a cycle inGwhereallof its vertices (or equivalently states) have red light in that directiondiri. However, by construction ofthe inducted graphGiwe don’t remove any vertices from the original graphGthat have red light in thatdirectiondirineither we remove any edges ofGthat go to such vertices. Thus, the same cycle ofGshouldbe also found inGi.The other direction: there is a cycle in the induced subgraphGi⇒a car can wait infinitely in a directiondiri.This follows from the fact that the vertices and the edges of the induced subgraphGican be alsoCS 170, Fall 2014, Sol 412