Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用GraphSharp graph layout WPF库绘制图形并编辑顶点标签_C#_Wpf_Graph_Graph Sharp - Fatal编程技术网

C# 使用GraphSharp graph layout WPF库绘制图形并编辑顶点标签

C# 使用GraphSharp graph layout WPF库绘制图形并编辑顶点标签,c#,wpf,graph,graph-sharp,C#,Wpf,Graph,Graph Sharp,我是一名大学生,这是我的算法分析教授交给我们班的家庭作业。我没有使用家庭作业标签,因为它将被弃用,但它基本上是家庭作业。非常感谢您的帮助 我们要用任何一种语言编写一个程序,在标准中读取xml,并将其打印到程序屏幕上,告诉图形有多少个节点、边和连接的组件,使用一个计数器进行计数 我已经使用graphsharp的c#graph layout库制作了这个程序,另外它在xml读取时绘制图形,但只对按钮点击时的项目进行计数,以提供一些交互 我已经完成了这个绘图+计数部分。问题是这个graphsharp项目

我是一名大学生,这是我的算法分析教授交给我们班的家庭作业。我没有使用家庭作业标签,因为它将被弃用,但它基本上是家庭作业。非常感谢您的帮助

我们要用任何一种语言编写一个程序,在
标准中读取xml,并将其打印到程序屏幕上,告诉图形有多少个节点、边和连接的组件,使用一个计数器进行计数

我已经使用graphsharp的c#graph layout库制作了这个程序,另外它在xml读取时绘制图形,但只对按钮点击时的项目进行计数,以提供一些交互

我已经完成了这个绘图+计数部分。问题是这个graphsharp项目几乎没有文档,我需要显示BFS在我的图形中的运行顺序。我做了一些非常简单的事情,比如在BFS的执行过程中更改节点的标签名称,如下所示:

  • “n0”变为“n0-1”
  • “n1”变为“n1-2”
  • 等等
我遇到的问题是:

Property or indexer 'QuickGraph.IVertexSet<object>.Vertices'
cannot be assigned to -- it is read only
属性或索引器“QuickGraph.IVertexSet.Vertices”
无法分配给--它是只读的

顶点是否仅“可创建”,而不可编辑?

我想我知道为什么该组件的边缘部分是只读的。这可能与这些图形的渲染方式有关。我在下面制作了另一个示例代码,删除一条边并将其添加回图形(这在某种程度上可以实现您的目标,但也可能不是您想要的(似乎没有其他方法可以更改图形中的边))

在我看来,您希望在实际绘制图形(我认为这也是组件的意图)之前,将您的树进行布局。如果你能完成,请告诉我

    string edgeSource = "n3";
    string edgeTarget = "n4";
    string newEdgeSource = "n0";
    string newEdgeTarget = "n4";

    IEnumerator<IEdge<object>> edgeEnumeratoer = g.Edges.GetEnumerator();
    edgeEnumeratoer.MoveNext();
    while (edgeEnumeratoer.Current != null)
    {
        var edge = edgeEnumeratoer.Current;
        string source = (string)(edge.Source);
        string target = (string)(edge.Target);
        if ((source.CompareTo(edgeSource) == 0) && (target.CompareTo(edgeTarget) == 0))
        {
            if (g.RemoveEdge(edge))
            {
                IEdge<object> newEdge = new Edge<object>(newEdgeSource, newEdgeTarget);
                g.AddEdge(newEdge);
                break;
            }
            else
            {
                Debug.WriteLine("Could not remove edge from graph.");
            }
        }
        edgeEnumeratoer.MoveNext();
    }

    graphLayout.Graph = g;
string edgeSource=“n3”;
字符串edgeTarget=“n4”;
字符串newEdgeSource=“n0”;
字符串newEdgeTarget=“n4”;
IEnumerator edgeEnumeratoer=g.Edges.GetEnumerator();
edgenumeratoer.MoveNext();
while(edgenumeratoer.Current!=null)
{
var edge=边缘电流;
字符串源=(字符串)(edge.source);
字符串目标=(字符串)(edge.target);
if((source.CompareTo(edgeSource)==0)和&(target.CompareTo(edgeTarget)==0))
{
如果(g.移除边缘(边缘))
{
IEdge newEdge=新边(newEdgeSource,newEdgeTarget);
g、 AddEdge(newEdge);
打破
}
其他的
{
WriteLine(“无法从图形中删除边。”);
}
}
edgenumeratoer.MoveNext();
}
graphLayout.Graph=g;

我想我已经知道了为什么这个组件的边缘部分是只读的。这可能与这些图形的渲染方式有关。我在下面制作了另一个示例代码,删除一条边并将其添加回图形(这在某种程度上可以实现您的目标,但也可能不是您想要的(似乎没有其他方法可以更改图形中的边))

在我看来,您希望在实际绘制图形(我认为这也是组件的意图)之前,将您的树进行布局。如果你能完成,请告诉我

    string edgeSource = "n3";
    string edgeTarget = "n4";
    string newEdgeSource = "n0";
    string newEdgeTarget = "n4";

    IEnumerator<IEdge<object>> edgeEnumeratoer = g.Edges.GetEnumerator();
    edgeEnumeratoer.MoveNext();
    while (edgeEnumeratoer.Current != null)
    {
        var edge = edgeEnumeratoer.Current;
        string source = (string)(edge.Source);
        string target = (string)(edge.Target);
        if ((source.CompareTo(edgeSource) == 0) && (target.CompareTo(edgeTarget) == 0))
        {
            if (g.RemoveEdge(edge))
            {
                IEdge<object> newEdge = new Edge<object>(newEdgeSource, newEdgeTarget);
                g.AddEdge(newEdge);
                break;
            }
            else
            {
                Debug.WriteLine("Could not remove edge from graph.");
            }
        }
        edgeEnumeratoer.MoveNext();
    }

    graphLayout.Graph = g;
string edgeSource=“n3”;
字符串edgeTarget=“n4”;
字符串newEdgeSource=“n0”;
字符串newEdgeTarget=“n4”;
IEnumerator edgeEnumeratoer=g.Edges.GetEnumerator();
edgenumeratoer.MoveNext();
while(edgenumeratoer.Current!=null)
{
var edge=边缘电流;
字符串源=(字符串)(edge.source);
字符串目标=(字符串)(edge.target);
if((source.CompareTo(edgeSource)==0)和&(target.CompareTo(edgeTarget)==0))
{
如果(g.移除边缘(边缘))
{
IEdge newEdge=新边(newEdgeSource,newEdgeTarget);
g、 AddEdge(newEdge);
打破
}
其他的
{
WriteLine(“无法从图形中删除边。”);
}
}
edgenumeratoer.MoveNext();
}
graphLayout.Graph=g;

创建一个具有属性
名称的自定义顶点类。而不是创建新的顶点(因为graph.vertices[i]=“newstr”意味着您将第i个对象更改为一个全新的对象/字符串),而是更改现有顶点的内容(定义的
名称
属性)


如果使用自定义顶点类型,则应定义一个自定义数据模板,以便能够按预期渲染顶点。

创建一个具有属性
名称的自定义顶点类。而不是创建新的顶点(因为graph.vertices[i]=“newstr”意味着您将第i个对象更改为一个全新的对象/字符串),而是更改现有顶点的内容(定义的
名称
属性)


如果使用自定义顶点类型,则应定义一个自定义数据模板,以便能够按预期渲染顶点。

我以前看过此快速图的一些代码。是否需要将它们作为字符串添加?那么,graph.AddVertex(“string_x”);?不,图中已经显示了从xml读取的顶点和边。它只有它们的ID,比如(n0)->(n2)->(n6)等等。。。我想让它变成(n0-1)->(n2-2)->(n6-3)。。。所以它不是添加新的顶点,而是编辑已经存在的顶点,我不确定这一点。为什么你不能开始构建你想要的东西,直到你拥有它”(n0-1)->(n2-2)…“?从QuickGraph组件中我可以看到,您需要的这些属性是只读的。因此,除非您想更改源代码,否则它不会给您留下很多选择。我看不出有什么问题。我需要更多的代码(比如来自XML的代码)来澄清。我以前看过这个QuickGraph的一些代码。你需要什么