khaled el omar
khaled el omar

Reputation: 149

How could I Implement inductive graph in haskell?

Given a graph described by the list of its edges, such as

[("c","cac"),("cac","cb"),("cac","bcc"),("c","ba")]

where cac comes after c, cb comes after cac, bcc comes after cac

How do I convert it to a graph in the sense of the fgl library, so that I can make use of the graph algorithms therein?

Upvotes: 1

Views: 200

Answers (1)

Joachim Breitner
Joachim Breitner

Reputation: 25763

In fgl, nodes are identified by Ints. But the module Data.Graph.Inductive.NodeMap can help you manage the mapping from your node names (String) to fgl’s nodes.

In particular, you can use insMapNodes on the list of strings in your list to create a NodeMap, and then pass that NodeMap and your list to insMapEdges.

Upvotes: 3

Related Questions