Find Strongly Connected C omponents Using K osaraju’s Algorithm And T arjan’s Algorithm
Verified Efficient Implementation of Gabow's Strongly Connected ...
Transcript of Verified Efficient Implementation of Gabow's Strongly Connected ...
![Page 1: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/1.jpg)
Verified Efficient Implementation of Gabow’sStrongly Connected Component Algorithm
Peter Lammich
TU München
July 2014
![Page 2: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/2.jpg)
Motivation
• Verify algorithm that computes SCCs of a digraph• Variants/Applications of algorithm
• Enumerate SCCs• Emptiness check of Generalized Büchi-Automata• . . .
• Re-use formalization between variants• Generate efficiently executable code
![Page 3: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/3.jpg)
Outline
1 Gabow’s SCC Algorithm
2 Isabelle/HOL Formalization
3 Performance Evaluation
![Page 4: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/4.jpg)
Outline
1 Gabow’s SCC Algorithm
2 Isabelle/HOL Formalization
3 Performance Evaluation
![Page 5: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/5.jpg)
Strongly Connected Components• SCC is maximal set of mutually reachable nodes
A
B
C
D E
F
![Page 6: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/6.jpg)
Strongly Connected Components• SCC is maximal set of mutually reachable nodes
A
B
C
D E
F
![Page 7: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/7.jpg)
Path-Based Algorithms
• Depth first search• On back edge, collapse nodes of induced cycle• Eventually, each node represents SCC
![Page 8: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/8.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 9: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/9.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 10: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/10.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 11: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/11.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 12: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/12.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 13: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/13.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 14: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/14.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 15: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/15.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 16: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/16.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 17: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/17.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 18: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/18.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 19: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/19.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 20: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/20.jpg)
Path-Based Algorithm Example
A
B
C
D E
F
![Page 21: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/21.jpg)
Gabow’s Data Structure
• How to maintain collapsed nodes on stack?• Use boundary stack
• contains indexes of bounds between collapsed nodes
• Yields linear-time algorithm
![Page 22: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/22.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack:Boundary stack:
![Page 23: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/23.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: ABoundary stack: 0
![Page 24: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/24.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A BBoundary stack: 0 1
![Page 25: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/25.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A BBoundary stack: 0
![Page 26: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/26.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A B CBoundary stack: 0 2
![Page 27: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/27.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A B CBoundary stack: 0
![Page 28: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/28.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A B C DBoundary stack: 0 4
![Page 29: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/29.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A B CBoundary stack: 0
![Page 30: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/30.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A B C EBoundary stack: 0 4
![Page 31: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/31.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A B C E FBoundary stack: 0 4 5
![Page 32: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/32.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A B C E FBoundary stack: 0 4
![Page 33: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/33.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack: A B CBoundary stack: 0
![Page 34: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/34.jpg)
Gabow’s Data Structure Example
A
B
C
D E
F
DFS stack:Boundary stack:
![Page 35: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/35.jpg)
Outline
1 Gabow’s SCC Algorithm
2 Isabelle/HOL Formalization
3 Performance Evaluation
![Page 36: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/36.jpg)
Re-usable Formalization
• Goal: Formalize family of SCC-based algorithms• Enumerate SCCs• GBA emptiness check• ...
• Approach: Formalize “skeleton” SCC algorithm first• Just the node-contracting DFS, no output• Theorems for VCs (invariant preservation, . . .)• Stepwise refinement to executable code
• Reuse this formalization for actual algorithms• Utilize existing Isabelle technologies
• Collection Framework, Refinement Framework, Autoref tool• Code generator, locales
![Page 37: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/37.jpg)
Re-usable Formalization
• Goal: Formalize family of SCC-based algorithms• Enumerate SCCs• GBA emptiness check• ...
• Approach: Formalize “skeleton” SCC algorithm first• Just the node-contracting DFS, no output• Theorems for VCs (invariant preservation, . . .)• Stepwise refinement to executable code
• Reuse this formalization for actual algorithms• Utilize existing Isabelle technologies
• Collection Framework, Refinement Framework, Autoref tool• Code generator, locales
![Page 38: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/38.jpg)
Re-usable Formalization
• Goal: Formalize family of SCC-based algorithms• Enumerate SCCs• GBA emptiness check• ...
• Approach: Formalize “skeleton” SCC algorithm first• Just the node-contracting DFS, no output• Theorems for VCs (invariant preservation, . . .)• Stepwise refinement to executable code
• Reuse this formalization for actual algorithms
• Utilize existing Isabelle technologies• Collection Framework, Refinement Framework, Autoref tool• Code generator, locales
![Page 39: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/39.jpg)
Re-usable Formalization
• Goal: Formalize family of SCC-based algorithms• Enumerate SCCs• GBA emptiness check• ...
• Approach: Formalize “skeleton” SCC algorithm first• Just the node-contracting DFS, no output• Theorems for VCs (invariant preservation, . . .)• Stepwise refinement to executable code
• Reuse this formalization for actual algorithms• Utilize existing Isabelle technologies
• Collection Framework, Refinement Framework, Autoref tool• Code generator, locales
![Page 40: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/40.jpg)
Design of the Formalization
Skeleton Specification
Abstract Skeleton Algorithm
v
Gabow’s Implementation
v
SML Code
v
Actual Spec
Actual Algo
vre-use
Actual Impl
vre-use
SML Code
vre-use
![Page 41: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/41.jpg)
Design of the Formalization
Skeleton Specification
Abstract Skeleton Algorithm
v
Gabow’s Implementation
v
SML Code
v
Actual Spec
Actual Algo
vre-use
Actual Impl
vre-use
SML Code
vre-use
![Page 42: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/42.jpg)
Design of the Formalization
Skeleton Specification
Abstract Skeleton Algorithm
v
Gabow’s Implementation
v
SML Code
v
Actual Spec
Actual Algo
vre-use
Actual Impl
vre-use
SML Code
vre-use
![Page 43: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/43.jpg)
Design of the Formalization
Skeleton Specification
Abstract Skeleton Algorithm
v
Gabow’s Implementation
v
SML Code
v
Actual Spec
Actual Algo
vre-use
Actual Impl
vre-use
SML Code
vre-use
![Page 44: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/44.jpg)
Design of the Formalization
Skeleton Specification
Abstract Skeleton Algorithm
v
Gabow’s Implementation
v
SML Code
v
Actual Spec
Actual Algo
vre-use
Actual Impl
vre-use
SML Code
vre-use
![Page 45: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/45.jpg)
Design of the Formalization
Skeleton Specification
Abstract Skeleton Algorithm
v
Gabow’s Implementation
v
SML Code
v
Actual Spec
Actual Algo
vre-use
Actual Impl
vre-use
SML Code
vre-use
![Page 46: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/46.jpg)
Design of the Formalization
Skeleton Specification
Abstract Skeleton Algorithm
v
Gabow’s Implementation
v
SML Code
v
Actual Spec
Actual Algo
vre-use
Actual Impl
vre-use
SML Code
vre-use
![Page 47: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/47.jpg)
Design of the Formalization
Skeleton Specification
Abstract Skeleton Algorithm
v
Gabow’s Implementation
v
SML Code
v
Actual Spec
Actual Algo
vre-use
Actual Impl
vre-use
SML Code
vre-use
![Page 48: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/48.jpg)
Isabelle Refinement Framework• Nondeterministic monadic programs
• Supports stepwise refinement• Verification Condition Generator
![Page 49: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/49.jpg)
Isabelle Refinement Framework• Nondeterministic monadic programs• Supports stepwise refinement• Verification Condition Generator
![Page 50: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/50.jpg)
Autoref-Tool and Collections Framework• Automatic Refinement Tool (Autoref)
• Parametricity-based approach to data refinement• Automatic synthesis of implementation from abstract program
• Isabelle Collection Framework• Efficient data structures (Array, Hash-Table, Bitvector, . . .)• Generic Algorithm Library• Integrated with Autoref
![Page 51: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/51.jpg)
Re-use of Invariants• Exploit locale mechanism to define extended invariants• Set up VCG: Only preservation of extension needs to be proved
![Page 52: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/52.jpg)
Re-use of Refinements• Use basic operations in extended algorithm• Re-use refinements for basic operations
![Page 53: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/53.jpg)
Outline
1 Gabow’s SCC Algorithm
2 Isabelle/HOL Formalization
3 Performance Evaluation
![Page 54: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/54.jpg)
Benchmark against Java Reference Implementation
1
10
100
1000
105 106
Tim
e in m
s
Number of edges
Poly/MLMLton
JavaJava*
![Page 55: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/55.jpg)
Conclusions
• Efficient, extensible formalization of Gabow’s Algorithm• Performance comparable to Java implementation (×3 . . .×4)• Variants: Enumerate SCCs, emptiness check for GBA
• Used by the CAVA fully verified LTL model checker [CAV ‘13]• Example of verified algorithm design in Isabelle/HOL
• Using Collection/Refinement/Autoref framework [ITP ’10,’12,’13]• Refinement separates algorithmic ideas from implementation• Sharing of proofs between variants of the algorithm
![Page 56: Verified Efficient Implementation of Gabow's Strongly Connected ...](https://reader034.fdocuments.net/reader034/viewer/2022042707/58a384091a28ab735d8c2b30/html5/thumbnails/56.jpg)
Questions
Questions?Remarks?