Checking Graph Properties with GP Chris Poskitt - - PowerPoint PPT Presentation

checking graph properties with gp
SMART_READER_LITE
LIVE PREVIEW

Checking Graph Properties with GP Chris Poskitt - - PowerPoint PPT Presentation

Checking Graph Properties with GP Checking Graph Properties with GP Chris Poskitt (cmp501@cs.york.ac.uk) The University of York PLASMA Seminar: 5th March 2009 Checking Graph Properties with GP Motivation Todays Talk 1. Motivation 2. GP


slide-1
SLIDE 1

Checking Graph Properties with GP

Checking Graph Properties with GP

Chris Poskitt (cmp501@cs.york.ac.uk)

The University of York

PLASMA Seminar: 5th March 2009

slide-2
SLIDE 2

Checking Graph Properties with GP Motivation

Today’s Talk

  • 1. Motivation
  • 2. GP Refresher
  • 3. Testing and describing graph properties with GP
  • 4. Examples and demonstrations
  • 5. Conclusions and future work
  • 6. Questions
slide-3
SLIDE 3

Checking Graph Properties with GP Motivation

Graphs

A graph G comprises

◮ a finite set of nodes, VG ◮ a finite set of edges, EG ◮ source and target functions mapping edges to nodes

◮ Edges are directed

◮ labelling functions

If VG = ∅, then G is the empty graph ∅. 1 2 1 a

slide-4
SLIDE 4

Checking Graph Properties with GP Motivation

Motivation

◮ Graphs are ubiquitous in computer science ◮ Represented at a low level in programming languages

◮ Adjacency matrices ◮ Adjacency lists

slide-5
SLIDE 5

Checking Graph Properties with GP Motivation Adjacency Matrices

Adjacency Matrix Example

1 2 1 A =   1   Aij = no. edges with source i and target j LV =

  • 1

2 1

  • ◮ Use a two dimensional array: a[i][j]

◮ . . . and one dimensional arrays for labels

slide-6
SLIDE 6

Checking Graph Properties with GP Motivation Adjacency Lists

Adjacency Lists Example

◮ Array entry a[i] contains a linked list of nodes adjacent to

node i, where i is the source node

slide-7
SLIDE 7

Checking Graph Properties with GP Motivation Trade-Offs

Trade-Offs

To make things more difficult!

Requirement Preferred Data Structure Huge sparse graphs Adjacency lists Complete or almost complete graphs Adjacency matrices Testing the existence of an edge Adjacency matrices Edge insertion and deletion Adjacency matrices, O(1) vs. O(degreevi ) Finding the degree of a node Adjacency lists Traversing graphs Adjacency lists, Θ(m + n) vs. Θ(n2)

slide-8
SLIDE 8

Checking Graph Properties with GP Motivation Summary

Motivation

◮ Low level representations of graphs ◮ Performance trade-offs ◮ Difficult to implement, comprehend, and verify graph

algorithms that test for graph properties GP removes the need to work at such a low level when solving graph problems. Programmers work with the nodes and edges of the input graph directly; underlying data structures are of no concern.

slide-9
SLIDE 9

Checking Graph Properties with GP GP Refresher

Today’s Talk

  • 1. Motivation
  • 2. GP Refresher
  • 3. Testing and describing graph properties with GP
  • 4. Examples and demonstrations
  • 5. Conclusions and future work
  • 6. Questions
slide-10
SLIDE 10

Checking Graph Properties with GP GP Refresher

GP

◮ . . . initialism of “Graph Programs” ◮ Experimental graph programming language ◮ High level of abstraction ◮ Based on graph transformation rules ◮ Non-deterministic ◮ Prolog-style backtracking (optional)

slide-11
SLIDE 11

Checking Graph Properties with GP GP Refresher Rule Schemata

Conditional Rule Schemata

GP introduces rule schemata, from which rules are induced. RSchemaName(x, y, k : int) =

1

x

2

x y k ⇒

1

x+1 k

2

x+1 k

◮ Expressions over labels ◮ Conditions

◮ where x + k > y ◮ where not edge(2, 1)

◮ Rule applications are local (dangling condition)

slide-12
SLIDE 12

Checking Graph Properties with GP GP Refresher Rule Schemata

Rule (DPO Approach)

1

1

2

1 2 3 ⇒

1

2 3

2

2 3

1

1

2

1 2 3 ← −

1 2

− →

1

2 3

2

2 3

slide-13
SLIDE 13

Checking Graph Properties with GP GP Refresher Rule Schemata

Rule (DPO Approach)

1

1

2

1 2 3 ← −

1 2

− →

1

2 3

2

2 3 ↓ 1 1 1 3 3 2 ↓ ↓

slide-14
SLIDE 14

Checking Graph Properties with GP GP Refresher Rule Schemata

Rule (DPO Approach)

1

1

2

1 2 3 ← −

1 2

− →

1

2 3

2

2 3 ↓

1

1∗

2

1∗ 1 3∗ 3 2∗ ← − ↓

1

2

∗ 1 3 − → ↓

1

2∗ 3∗

2

2∗ 3∗ 1 3

slide-15
SLIDE 15

Checking Graph Properties with GP GP Refresher Control Constructs

Control Constructs

◮ Sequential composition, ‘;’

slide-16
SLIDE 16

Checking Graph Properties with GP GP Refresher Control Constructs

Control Constructs

◮ Sequential composition, ‘;’ ◮ Non-deterministic single-step application of a set of

conditional rule schemata, e.g. {RS1, RS2, RS3}

slide-17
SLIDE 17

Checking Graph Properties with GP GP Refresher Control Constructs

Control Constructs

◮ Sequential composition, ‘;’ ◮ Non-deterministic single-step application of a set of

conditional rule schemata, e.g. {RS1, RS2, RS3}

◮ The as-long-as-possible looping construct, ‘!’

slide-18
SLIDE 18

Checking Graph Properties with GP GP Refresher Control Constructs

Control Constructs

◮ Sequential composition, ‘;’ ◮ Non-deterministic single-step application of a set of

conditional rule schemata, e.g. {RS1, RS2, RS3}

◮ The as-long-as-possible looping construct, ‘!’ ◮ Branching constructs if-then-else and try-then-else

slide-19
SLIDE 19

Checking Graph Properties with GP GP Refresher Control Constructs

Control Constructs

◮ Sequential composition, ‘;’ ◮ Non-deterministic single-step application of a set of

conditional rule schemata, e.g. {RS1, RS2, RS3}

◮ The as-long-as-possible looping construct, ‘!’ ◮ Branching constructs if-then-else and try-then-else ◮ The while-do looping construct

slide-20
SLIDE 20

Checking Graph Properties with GP GP Refresher Control Constructs

Control Constructs

◮ Sequential composition, ‘;’ ◮ Non-deterministic single-step application of a set of

conditional rule schemata, e.g. {RS1, RS2, RS3}

◮ The as-long-as-possible looping construct, ‘!’ ◮ Branching constructs if-then-else and try-then-else ◮ The while-do looping construct

main = if NotComplete then No else Yes. NotComplete = {Loop, ParallelEdges, UnconnectedNodes}.

slide-21
SLIDE 21

Checking Graph Properties with GP GP Refresher Control Constructs

if vs. try

◮ Powerful ◮ if hides the result of rule applications in the guard

◮ Useful for destructive tests, e.g. trees

◮ try does not

slide-22
SLIDE 22

Checking Graph Properties with GP GP Refresher Implementation

Implementation

slide-23
SLIDE 23

Checking Graph Properties with GP GP Refresher Implementation

Implementation

slide-24
SLIDE 24

Checking Graph Properties with GP GP Refresher Implementation

Implementation: Backtracking

◮ Optional (check box) ◮ Prolog-like ◮ Expensive ◮ Allows for some elegant programs

◮ Hamiltonian path (later)

slide-25
SLIDE 25

Checking Graph Properties with GP GP Refresher Implementation

Implementation: Kinks

main = if SomeMacro then RuleSchema1 else RuleSchema2. SomeMacro = Rule1; Rule2; Rule3!; Test.

◮ Does not terminate on “large” input graphs, ◮ even with backtracking disabled

slide-26
SLIDE 26

Checking Graph Properties with GP GP Refresher Implementation

Implementation: Kinks

◮ Cannot use if-then without also else ◮ Workaround:

NullRule : ∅ ⇒ ∅

slide-27
SLIDE 27

Checking Graph Properties with GP GP Refresher Implementation

Implementation: Kinks

◮ Uses an updated semantics that drops while-do ◮ Can be simulated

while C do P. ≡ (if C then P else fail)!; if C then fail else NullRule.

◮ fail?

slide-28
SLIDE 28

Checking Graph Properties with GP GP Refresher Implementation

Implementation: Kinks

◮ Empty error messages (aaaarrghh!) ◮ Some differing notation

◮ where ∼ edge 2 1 vs. where not edge(2, 1)

slide-29
SLIDE 29

Checking Graph Properties with GP Testing and Describing Graph Properties with GP

Today’s Talk

  • 1. Motivation
  • 2. GP Refresher
  • 3. Testing and describing graph properties with GP
  • 4. Examples and demonstrations
  • 5. Conclusions and future work
  • 6. Questions
slide-30
SLIDE 30

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Describing Results

Describing Results

◮ GP takes a graph as input and returns a graph as output ◮ No additional variables in which to store a result (e.g.

true/false indicating the existence of a property)

◮ Result must be encoded into the output graph

slide-31
SLIDE 31

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Describing Results

Describing Results

  • 1. Generate a “Yes” or “No”-labelled node

Yes = ∅ ⇒

”Yes”

slide-32
SLIDE 32

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Describing Results

Describing Results

  • 1. Generate a “Yes” or “No”-labelled node
  • 2. Arbitrarily replace an existing label with “Yes” or “No”
slide-33
SLIDE 33

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Describing Results

Describing Results

  • 1. Generate a “Yes” or “No”-labelled node
  • 2. Arbitrarily replace an existing label with “Yes” or “No”
  • 3. Return input graph with data encoded into the labels

◮ Degree ◮ Steps of a Hamiltonian path ◮ etc.

slide-34
SLIDE 34

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Describing Results

Describing Results

  • 1. Generate a “Yes” or “No”-labelled node
  • 2. Arbitrarily replace an existing label with “Yes” or “No”
  • 3. Return input graph with data encoded into the labels

◮ Degree ◮ Steps of a Hamiltonian path ◮ etc.

  • 4. Return single node or empty graph, following successful

application of destructive rules

slide-35
SLIDE 35

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Approaching Graph Programming

Approaching Graph Programming

◮ Assume integers

◮ No duplication of “Yes” or “No”

◮ Information gathering approach

◮ Store in tags

◮ Destructive approach

◮ Some invariant holds after each reduction

slide-36
SLIDE 36

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Approaching Graph Programming

Colours and Counting

◮ An infinite number of tags may be appended to a label. ◮ Of l t1 t2 . . . tn, l is the label and t1 to tn the tags. ◮ A single tag may represent colour

◮ 0 = White (not visited) ◮ 1 = Grey (being visited) ◮ 2 = Black (“fully” visited, nothing more to do)

◮ Tags may also be used for counting

◮ (Current) degree of a node ◮ Sequence in a path

InitNode(x : int) = x ⇒ x 0

slide-37
SLIDE 37

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Expecting Failure

Expecting Failure

main = if Loop then No else Yes. Loop(x, k : int) = x k ⇒ x k

◮ Fine in this case ◮ But implementation will not allow RSchema!; Test in the

guard

slide-38
SLIDE 38

Checking Graph Properties with GP Testing and Describing Graph Properties with GP Undirected Graphs

Dealing with Undirected Graphs

1

x

2

y k ∼ =

1

x

2

y k k

◮ Edges partitioned into pairs (e, e′) such that for all pairs ◮ (e, e′) : sG(e) = tG(e′), tG(e) = sG(e′), mG(e) = mG(e′),

and e and e′ are not in any other pair

slide-39
SLIDE 39

Checking Graph Properties with GP Examples and Demonstrations

Today’s Talk

  • 1. Motivation
  • 2. GP Refresher
  • 3. Testing and describing graph properties with GP
  • 4. Examples and demonstrations
  • 5. Conclusions and future work
  • 6. Questions
slide-40
SLIDE 40

Checking Graph Properties with GP Examples and Demonstrations Complete Graph

Complete Graph

main = if NotComplete then No else Yes. NotComplete = {Loop, ParallelEdges, UnconnectedNodes}. ParallelEdges(x, y, k, l : int) =

1

x

2

y k l ⇒

1

x

2

y k l UnconnectedNodes(x, y : int) =

1

x

2

y where not edge(1, 2) ⇒

1

x

2

y

slide-41
SLIDE 41

Checking Graph Properties with GP Examples and Demonstrations Unilaterally Connected Graph

Unilaterally Connected Graph

◮ ∀vi, vj ∈ VG, there is one of:

  • 1. A path from vi to vj
  • 2. A path from vj to vi
  • 3. Paths in both directions

◮ Unilaterally connected graphs are also weakly connected

slide-42
SLIDE 42

Checking Graph Properties with GP Examples and Demonstrations Strongly Connected Graph

Strongly Connected Graph

◮ ∀vi, vj ∈ VG, there is a path from vi to vj ◮ Strongly connected graphs are also unilaterally connected

graphs

◮ Same program as CheckUnilaterallyConnected, except for

  • ne rule schema!
slide-43
SLIDE 43

Checking Graph Properties with GP Examples and Demonstrations Eulerian Circuit

Eulerian Circuit

[Image from Wikipedia]

slide-44
SLIDE 44

Checking Graph Properties with GP Examples and Demonstrations Eulerian Circuit

Eulerian Circuit

◮ A connected graph is Eulerian if every node has an even

degree

◮ Test by reducing pairs of edges for as long as possible, and

test for a remaining edge

◮ Computing the Eulerian circuit is more complicated

slide-45
SLIDE 45

Checking Graph Properties with GP Examples and Demonstrations Eulerian Circuit

Eulerian Circuit

◮ Fleury’s algorithm

  • 1. Pick any node to start: “leading node”
  • 2. Pick an edge connected to the node, subject to the rule below
  • 3. Darken the edge
  • 4. Move the “leading node” across the edge
  • 5. Repeat 2-4 until returning to the initial node

RULE: Never cross a bridge of the reduced graph unless there is no other choice.

slide-46
SLIDE 46

Checking Graph Properties with GP Examples and Demonstrations Eulerian Circuit

Eulerian Circuit

slide-47
SLIDE 47

Checking Graph Properties with GP Examples and Demonstrations Hamiltonian Path

Hamiltonian Path

◮ Path that includes every single node in VG exactly once ◮ NP-complete ◮ Heuristics unhelpful!

◮ We do not want to weaken the “exactly once” condition

◮ Elegant, expensive program, making use of backtracking.

slide-48
SLIDE 48

Checking Graph Properties with GP Examples and Demonstrations Hamiltonian Path

Hamiltonian Path

main = PickNode; PickNeighbour!; (if UntaggedNode then fail else NullRule).

◮ Throws away result if it is not Hamiltonian ◮ Keeps backtracking until a satisfactory result is found

slide-49
SLIDE 49

Checking Graph Properties with GP Conclusions and Further Work

Today’s Talk

  • 1. Motivation
  • 2. GP Refresher
  • 3. Testing and describing graph properties with GP
  • 4. Examples and demonstrations
  • 5. Conclusions and future work
  • 6. Questions
slide-50
SLIDE 50

Checking Graph Properties with GP Conclusions and Further Work

Conclusions and Further Work

◮ Have a go:

◮ http : //www − course.cs.york.ac.uk/gra/ ◮ http : //www.cs.york.ac.uk/ ∼ cmp501/gp/

◮ Conclusions ◮ Further work

◮ Verification of graph programs ◮ Implementation improvements

slide-51
SLIDE 51

Checking Graph Properties with GP Questions

Today’s Talk

  • 1. Motivation
  • 2. GP Refresher
  • 3. Testing and describing graph properties with GP
  • 4. Examples and demonstrations
  • 5. Conclusions and future work
  • 6. Questions
slide-52
SLIDE 52

Checking Graph Properties with GP Questions

Questions?