Reputation:
I am using HASKELL for graph games. I am willing to get a suitable method for reach ability from a node to a particular node in the graph apart from using bfs or trees etc.
As I asked for code in haskell for reach ability from one node to a particular node, it is necessary to tell you that I am totally new to haskell. I have been reading the tutorials and simple examples, but when it come to implementation then I am lost. My graph is a directed graph, and say I want to check whether I can reach from node v to node w in graph.
Upvotes: 2
Views: 3062
Reputation: 137937
Not entirely sure what your question is, in the context of Haskell.
Either way, check http://hackage.haskell.org for graph-related packages:
Upvotes: 2
Reputation: 7277
From Data.Graph:
reachable :: Graph -> Vertex -> [Vertex]
To search the Haskell API and libraries:
Upvotes: 8
Reputation: 136141
There are several All pair shortest path algorithms in hand. For small graphs, wikipedia says:
Floyd-Warshall algorithm is an elegant, quickly implementable O(n3) algorithm (Assumes absence of negatively-weighed cycles).
EDIT: Are you looking for a ready-made Haskell code?
Upvotes: 2
Reputation: 158254
Try representing your graph as a matrix where a 1 represents an edge.
E.g.:
Node/Node A B C D
A 0 0 1 1
B 0 0 1 1
C 0 0 1 0
D 1 0 1 0
For directed graphs the order of the matrix indices matters, for undirected graphs they don't. The above being a directed graph where there is an edge from D->C but not from C->D.
Upvotes: 2