Wednesday, April 11, 2012

How to represent directed cyclic graph in Prolog with direct access to neighbour verticies

I need to construct directed graph (at runtime) with cycles in Prolog and don't know how to represent it, so i can get from one vertex to his neigbour in a constant time.
Is it possible to do it somehow like in a tree representation, something like: t(left_son,V,right_son), but how to solve the cycles?
I can make a list of edges like: graph([a,b,c,d],
[e(a,b),e(b,c),e(c,a),e(c,d)]), OR just [a->[b],b->[c],c->[a,d],d->[]], but how to avoid calling function 'member' on list while searching for neighbours, which cost linear time?
Thanks for ur help

No comments:

Post a Comment