Finding a path - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Finding a path

Description:

Let G be a graph, and A and Z two nodes in G. We are interested in a ... find an acyclic path, P1, from node Y to Z, and find a path from A to Y avoiding ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 6
Provided by: waseem3
Category:
Tags: finding | graf | path

less

Transcript and Presenter's Notes

Title: Finding a path


1
Finding a path
Let G be a graph, and A and Z two nodes in G. We
are interested in a relation path(A, Z,
G, P)
where P is an acyclic path from A to Z in G.
X
Z
A
Y
To find an acyclic path, P, between A and Z in a
graph GIf AZ then P A, otherwise find an
acyclic path, P1, from node Y to Z, and find a
path from A to Y avoiding thenodes in P1
2
Finding a path (contd)
path1
X
Z
A
Y
path
To find an acyclic path, P, between A and Z in a
graph GIf AZ then P A, otherwise find an
acyclic path, P1, from node Y to Z, and find a
path from A to Y avoiding thenodes in P1
This formulation implies another relation find a
path under the restriction of avoiding some
subset of nodes (P1 above) path1(A, Path1, G,
Path).
3
Finding a path (contd)
path1
X
Z
A
Y
path
  • path1(A, Path1, G, Path).
  • The arguments are
  • A is a node,
  • G is a graph,
  • Path1 is a path in G,
  • Path is an acyclic path in G that goes from A to
    the beginning of Path1and continues along Path1
    up to its end.
  • The relation between path and path1 is
    path(A,Z,G,Path) - path1(A,Z, G, Path).

4
Finding a path (contd)
path1
X
Z
A
Y
path
  • path(A,Z,G,Path) - path1(A,Z, G, Path).
  • The definition of path1 is recursive. The
    boundary case arises when the start node of Path1
    (Y in the above figure) coincides with the
    start node of Path, A.
  • If the start nodes do not coincide then there
    must be a node , X, such that
  • Y is adjacent to X, and
  • X is not in path1, and
  • path must satisfy the relation
    path1(A,Xpath1, G, Path).

5
Finding a path Example
path(A, Z, Graph, Path) - path1(A,
Z, Graph, Path). path1(A, APath1, Graph,
APath1). path1(A, YPath1, graph(Nodes,
Edges), Path) - member(c(X,Y),
Edges), not_member(X, Path1),
path1(A, X,YPath1, graph(Nodes, Edges),
Path). not_member(X, ). not_member(X, YL)
- not_member(X, L), X \ Y.
solve(Path) - path(a,d,graph(a,b,c,d,e,
c(a,b),c(b,c),c(d,c),c(b,d),c(d,b),c(d,a),c(a,
e),c(e,d),c(c,d)), Path).
a
e
b
d
c
graph(a,b,c,d,e, c(a,b),c(b,c),
c(d,c),c(b,d), c(d,b),c(d,a),
c(a,e),c(e,d), c(c,d))
?- solve(X). X a, b, d X a, e, d X
a, b, c, d No
Write a Comment
User Comments (0)
About PowerShow.com