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

回眸只為那壹抹淺笑 提交于 2020-01-02 17:30:52

问题


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:


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



回答2:


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



来源:https://stackoverflow.com/questions/2718522/quickgraph-how-can-i-associate-an-edge-with-a-class-i-e-like-you-can-with-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!