开发者

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

开发者 https://www.devze.com 2022-12-28 01:47 出处:网络
Q1 - How can I associate a开发者_JS百科n 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

Q1 - How can I associate a开发者_JS百科n 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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号