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

不羁的心 提交于 2019-12-06 04:46:58

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.

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