QuickGraph,如何使用扩展方法 StronglyConnectedComponents

发布于 2024-12-04 11:29:05 字数 1373 浏览 0 评论 0原文

作为我第一次 C# 实验(在 Mono 2.6.7 上)的一部分,我尝试使用 QuickGraph 中的 StronglyConnectedComponents 方法。这是我的代码:

using System;
using QuickGraph;
using QuickGraph.Data;
using System.Collections.Generic;
using QuickGraph.Algorithms;

namespace Graph
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            IVertexListGraph<int,Edge<int>> graph;
            graph = new AdjacencyGraph<int,Edge<int>>();
            IDictionary<int,int> components=new Dictionary<int,int>();  
            int noc = graph.StronglyConnectedComponents(out components);
        }
    }
}

当尝试编译上面的代码时,我收到错误消息(在 MonoDevelop 中):

Error CS1061: Type `QuickGraph.IVertexListGraph<int,QuickGraph.Edge<int>>' does not 
contain a definition for `StronglyConnectedComponents' and no extension method 
`StronglyConnectedComponents' of type 
`QuickGraph.IVertexListGraph<int,QuickGraph.Edge<int>>' could be found 
(are you missing a using directive or an assembly reference?) (CS1061) (Graph)

正如我从文档中看到的,扩展方法应该可用:

public static int StronglyConnectedComponents<TVertex, TEdge>(
    IVertexListGraph<TVertex, TEdge> g,
    out IDictionary<TVertex, int> components
)

另外,我从 QuickGraph 引用了所有三个 .dll 。我缺少什么?

As part of my first experiments with C# (on Mono 2.6.7) , I am trying to use the StronglyConnectedComponents method from QuickGraph. Here is my code:

using System;
using QuickGraph;
using QuickGraph.Data;
using System.Collections.Generic;
using QuickGraph.Algorithms;

namespace Graph
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            IVertexListGraph<int,Edge<int>> graph;
            graph = new AdjacencyGraph<int,Edge<int>>();
            IDictionary<int,int> components=new Dictionary<int,int>();  
            int noc = graph.StronglyConnectedComponents(out components);
        }
    }
}

When trying to compile the code above, I get the error message (in MonoDevelop):

Error CS1061: Type `QuickGraph.IVertexListGraph<int,QuickGraph.Edge<int>>' does not 
contain a definition for `StronglyConnectedComponents' and no extension method 
`StronglyConnectedComponents' of type 
`QuickGraph.IVertexListGraph<int,QuickGraph.Edge<int>>' could be found 
(are you missing a using directive or an assembly reference?) (CS1061) (Graph)

As for as I can see from the documentation, the extension method should be available:

public static int StronglyConnectedComponents<TVertex, TEdge>(
    IVertexListGraph<TVertex, TEdge> g,
    out IDictionary<TVertex, int> components
)

Also, I referred all three .dll's from QuickGraph. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2024-12-11 11:29:05

好的,我刚刚检查了一下,它适用于我目前拥有的 Mono 2.10.5 (Ubuntu),所以请考虑更新。 2.6.7 已经很旧了。我刚刚下载了快速图形库,仅引用了一个 dll (QuickGraph.dll),复制粘贴了您的代码(刚刚使用 QuickGraph.Data 删除了),它编译并运行没有任何问题。

Ok, I just checked it out and it works for me on Mono 2.10.5 (Ubuntu), which I currently have, so consider updating. 2.6.7 is very old. I just downloaded quick graph library, referenced only one dll (QuickGraph.dll), copypasted your code (just removed using QuickGraph.Data) and it compiles and runs without any problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文