本文整理汇总了C#中Vertex.AddUnDirectedEdge方法的典型用法代码示例。如果您正苦于以下问题:C# Vertex.AddUnDirectedEdge方法的具体用法?C# Vertex.AddUnDirectedEdge怎么用?C# Vertex.AddUnDirectedEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertex
的用法示例。
在下文中一共展示了Vertex.AddUnDirectedEdge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TopologicalTest4
public void TopologicalTest4()
{
var graf = new Graf<char>();
var bVertex = new Vertex<char>('b');
var cVertex = new Vertex<char>('c');
var dVertex = new Vertex<char>('d');
var aVertex = new Vertex<char>('a');
var iVertex = new Vertex<char>('i');
var eVertex = new Vertex<char>('e');
var hVertex = new Vertex<char>('h');
var gVertex = new Vertex<char>('g');
var fVertex = new Vertex<char>('f');
aVertex.AddUnDirectedEdge(4, bVertex);
bVertex.AddUnDirectedEdge(8, cVertex);
cVertex.AddUnDirectedEdge(7, dVertex);
dVertex.AddUnDirectedEdge(9, eVertex);
dVertex.AddUnDirectedEdge(14, fVertex);
eVertex.AddUnDirectedEdge(10, fVertex);
aVertex.AddUnDirectedEdge(8, hVertex);
bVertex.AddUnDirectedEdge(11, hVertex);
cVertex.AddUnDirectedEdge(2, iVertex);
cVertex.AddUnDirectedEdge(4, fVertex);
iVertex.AddUnDirectedEdge(7, hVertex);
iVertex.AddUnDirectedEdge(6, gVertex);
hVertex.AddUnDirectedEdge(1, gVertex);
gVertex.AddUnDirectedEdge(2, fVertex);
graf.AddVertex(aVertex);
graf.AddVertex(bVertex);
graf.AddVertex(cVertex);
graf.AddVertex(dVertex);
graf.AddVertex(iVertex);
graf.AddVertex(eVertex);
graf.AddVertex(hVertex);
graf.AddVertex(gVertex);
graf.AddVertex(fVertex);
var components = graf.GetStronglyConnectedComponentsWithUnions();
Assert.Equal(1, components.Count);
}
示例2: MSTTest1
public void MSTTest1()
{
var graf = new Graf<char>();
var bVertex = new Vertex<char>('b');
var cVertex = new Vertex<char>('c');
var dVertex = new Vertex<char>('d');
var aVertex = new Vertex<char>('a');
var iVertex = new Vertex<char>('i');
var eVertex = new Vertex<char>('e');
var hVertex = new Vertex<char>('h');
var gVertex = new Vertex<char>('g');
var fVertex = new Vertex<char>('f');
aVertex.AddUnDirectedEdge(4, bVertex);
bVertex.AddUnDirectedEdge(8, cVertex);
cVertex.AddUnDirectedEdge(7, dVertex);
dVertex.AddUnDirectedEdge(9, eVertex);
dVertex.AddUnDirectedEdge(14, fVertex);
eVertex.AddUnDirectedEdge(10, fVertex);
aVertex.AddUnDirectedEdge(8, hVertex);
bVertex.AddUnDirectedEdge(11, hVertex);
cVertex.AddUnDirectedEdge(2, iVertex);
cVertex.AddUnDirectedEdge(4, fVertex);
iVertex.AddUnDirectedEdge(7, hVertex);
iVertex.AddUnDirectedEdge(6, gVertex);
hVertex.AddUnDirectedEdge(1, gVertex);
gVertex.AddUnDirectedEdge(2, fVertex);
graf.AddVertex(aVertex);
graf.AddVertex(bVertex);
graf.AddVertex(cVertex);
graf.AddVertex(dVertex);
graf.AddVertex(iVertex);
graf.AddVertex(eVertex);
graf.AddVertex(hVertex);
graf.AddVertex(gVertex);
graf.AddVertex(fVertex);
var mstGraf = graf.GetMSTGrafKruskal();
double weigth = 0;
for (int i = 0; i < mstGraf.Vertexes.Count; i++)
{
for (int j = 0; j < mstGraf.Vertexes[i].Edges.Count; j++)
{
mstGraf.Vertexes[i].Edges[j].Marked = false;
}
}
for (int i = 0; i < mstGraf.Vertexes.Count; i++)
{
for (int j = 0; j < mstGraf.Vertexes[i].Edges.Count; j++)
{
var adjacentVertex = mstGraf.Vertexes[i].Edges[j].Other(mstGraf.Vertexes[i]);
if (!mstGraf.Vertexes[i].Edges[j].Marked)
{
weigth += mstGraf.Vertexes[i].Edges[j].Weigth;
mstGraf.Vertexes[i].Edges[j].Marked = true;
}
}
}
Assert.Equal(37, weigth);
}