tags:

views:

77

answers:

2

Hi,

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

thanks

+1  A: 

Greg,

An edge by default only connects two vertices on the graph. If you need more information associated with an edge (i.e. a "Relationship"), you can implement the IEdge<T> interfaces or subclass Edge<T>. Then, in your custom edge class you can store the information that's relevant to that edge.

i.e.

public class MyEdge<TVertex> : Edge<TVertex>
{
    public string Name { get; set; }

    public MyEdge(TVertex source, TVertex target) : base(source, target)
    {
    }
}

... later

var graph = new BidirectionalGraph<int, MyEdge<int>>();

-Doug

Doug
A: 

You can also use the TaggedEdge class, which allows you to associate an arbitrary object with each edge.

RyanHennig