Greg
Greg

Reputation: 34798

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

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

Upvotes: 2

Views: 1761

Answers (2)

Doug
Doug

Reputation: 5338

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>>();

Upvotes: 5

RyanHennig
RyanHennig

Reputation: 1072

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

Upvotes: 4

Related Questions