QuickGraph - How can I associate an Edge with a Class? (i.e. like you can with a Vertex)

Topics: graph
Apr 27, 2010 at 4:32 AM


Q1 - How can I associate an Edge with a Class?  (i.e. like you can with a Vertex)

In my case there are various types of edges I want to be able to model.  So my real question I guess is how can I associate some level of data with Edges (e.g. edge type).

The graph I was looking at using was:  http://quickgraph.codeplex.com/wikipage?title=BidirectionalGraph&referringTitle=Documentation


May 11, 2010 at 3:23 PM

In all graph structures expected type of edge is IEdge<TVertex>, or something implementing this interface.
So you can simple create class MyEdge : IEdge<TVertex>. If you prefer composition over impl. you can use
TaggedEdge<TVertex,TTag>. But to be honest i must say that i don't understand your problem. Can you
provide some details?

May 12, 2010 at 12:36 PM

I think I have the hang of it now.  This seems to work:


    class Program
        static void Main(string[] args)
            var graph = new BidirectionalGraph<Node, Relationship<Node>>();

            Node n1 = new Node();
            n1.Name = "first";
            Node n2 = new Node();
            n1.Name = "second";

            var r1 = new Relationship<Node>(n1, n2);


    public class Relationship<TVertex> : Edge<TVertex>
        public int Type { get; set; }

        public Relationship(TVertex source, TVertex target)
            : base(source, target)


    internal class Node
        public string Name { get; set; }