本文整理汇总了C#中Vertex.AddDirectedEdge方法的典型用法代码示例。如果您正苦于以下问题:C# Vertex.AddDirectedEdge方法的具体用法?C# Vertex.AddDirectedEdge怎么用?C# Vertex.AddDirectedEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertex
的用法示例。
在下文中一共展示了Vertex.AddDirectedEdge方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TopologicalTest3
public void TopologicalTest3()
{
var graf = new Graf<char>();
var mVertex = new Vertex<char>('m');
var nVertex = new Vertex<char>('n');
var oVertex = new Vertex<char>('o');
var pVertex = new Vertex<char>('p');
var qVertex = new Vertex<char>('q');
var rVertex = new Vertex<char>('r');
var sVertex = new Vertex<char>('s');
var tVertex = new Vertex<char>('t');
var uVertex = new Vertex<char>('u');
var vVertex = new Vertex<char>('v');
var wVertex = new Vertex<char>('w');
var xVertex = new Vertex<char>('x');
var yVertex = new Vertex<char>('y');
var zVertex = new Vertex<char>('z');
mVertex.AddDirectedEdge(1, qVertex);
mVertex.AddDirectedEdge(1, rVertex);
mVertex.AddDirectedEdge(1, xVertex);
nVertex.AddDirectedEdge(1, qVertex);
nVertex.AddDirectedEdge(1, uVertex);
nVertex.AddDirectedEdge(1, oVertex);
oVertex.AddDirectedEdge(1, rVertex);
oVertex.AddDirectedEdge(1, sVertex);
pVertex.AddDirectedEdge(1, oVertex);
pVertex.AddDirectedEdge(1, sVertex);
pVertex.AddDirectedEdge(1, zVertex);
qVertex.AddDirectedEdge(1, tVertex);
rVertex.AddDirectedEdge(1, uVertex);
rVertex.AddDirectedEdge(1, yVertex);
sVertex.AddDirectedEdge(1, rVertex);
uVertex.AddDirectedEdge(1, tVertex);
vVertex.AddDirectedEdge(1, wVertex);
vVertex.AddDirectedEdge(1, xVertex);
wVertex.AddDirectedEdge(1, zVertex);
yVertex.AddDirectedEdge(1, vVertex);
graf.AddVertex(mVertex);
graf.AddVertex(nVertex);
graf.AddVertex(oVertex);
graf.AddVertex(pVertex);
graf.AddVertex(qVertex);
graf.AddVertex(rVertex);
graf.AddVertex(sVertex);
graf.AddVertex(tVertex);
graf.AddVertex(uVertex);
graf.AddVertex(vVertex);
graf.AddVertex(wVertex);
graf.AddVertex(xVertex);
graf.AddVertex(yVertex);
graf.AddVertex(zVertex);
graf.DFS();
var topologicalSort = graf.GetTopologicalSort().ToList();
Assert.NotNull(topologicalSort);
Assert.Equal(14, topologicalSort.Count);
Assert.Equal('p', topologicalSort.First().Key);
Assert.Equal(27, topologicalSort.First().DiscoveryTime);
Assert.Equal(28, topologicalSort.First().FinishingTime);
Assert.Equal('t', topologicalSort.Last().Key);
Assert.Equal(3, topologicalSort.Last().DiscoveryTime);
Assert.Equal(4, topologicalSort.Last().FinishingTime);
var grafT = graf.GetGrafT();
var components = grafT.GetStronglyConnectedComponents(topologicalSort);
Assert.Equal(14, components.Count);
}
示例2: SingleSourceTest3
public void SingleSourceTest3()
{
var graf = new Graf<char>();
var sVertex = new Vertex<char>('s');
var tVertex = new Vertex<char>('t');
var xVertex = new Vertex<char>('x');
var yVertex = new Vertex<char>('y');
var zVertex = new Vertex<char>('z');
sVertex.AddDirectedEdge(10, tVertex);
sVertex.AddDirectedEdge(5, yVertex);
tVertex.AddDirectedEdge(1, xVertex);
tVertex.AddDirectedEdge(2, yVertex);
xVertex.AddDirectedEdge(4, zVertex);
zVertex.AddDirectedEdge(6, xVertex);
zVertex.AddDirectedEdge(7, sVertex);
yVertex.AddDirectedEdge(3, tVertex);
yVertex.AddDirectedEdge(9, xVertex);
yVertex.AddDirectedEdge(2, zVertex);
graf.AddVertex(sVertex);
graf.AddVertex(tVertex);
graf.AddVertex(xVertex);
graf.AddVertex(yVertex);
graf.AddVertex(zVertex);
graf.DejkstraShortestPaths(sVertex);
Assert.Equal(0, sVertex.DiscoveryTime);
Assert.Equal(8, tVertex.DiscoveryTime);
Assert.Equal(9, xVertex.DiscoveryTime);
Assert.Equal(5, yVertex.DiscoveryTime);
Assert.Equal(7, zVertex.DiscoveryTime);
}
示例3: TopologicalTest1
public void TopologicalTest1()
{
var graf = new Graf<char>();
var qVertex = new Vertex<char>('q');
var rVertex = new Vertex<char>('r');
var sVertex = new Vertex<char>('s');
var tVertex = new Vertex<char>('t');
var uVertex = new Vertex<char>('u');
var vVertex = new Vertex<char>('v');
var wVertex = new Vertex<char>('w');
var xVertex = new Vertex<char>('x');
var yVertex = new Vertex<char>('y');
var zVertex = new Vertex<char>('z');
qVertex.AddDirectedEdge(1, sVertex);
qVertex.AddDirectedEdge(1, tVertex);
qVertex.AddDirectedEdge(1, wVertex);
sVertex.AddDirectedEdge(1, vVertex);
vVertex.AddDirectedEdge(1, wVertex);
wVertex.AddDirectedEdge(1, sVertex);
tVertex.AddDirectedEdge(1, xVertex);
tVertex.AddDirectedEdge(1, yVertex);
xVertex.AddDirectedEdge(1, zVertex);
yVertex.AddDirectedEdge(1, qVertex);
rVertex.AddDirectedEdge(1, uVertex);
rVertex.AddDirectedEdge(1, yVertex);
uVertex.AddDirectedEdge(1, yVertex);
graf.AddVertex(qVertex);
graf.AddVertex(rVertex);
graf.AddVertex(sVertex);
graf.AddVertex(tVertex);
graf.AddVertex(uVertex);
graf.AddVertex(vVertex);
graf.AddVertex(wVertex);
graf.AddVertex(xVertex);
graf.AddVertex(yVertex);
graf.AddVertex(zVertex);
graf.DFS();
Assert.Null(graf.GetTopologicalSort());
}
示例4: SingleSourceTest1
public void SingleSourceTest1()
{
var graf = new Graf<char>();
var sVertex = new Vertex<char>('s');
var tVertex = new Vertex<char>('t');
var xVertex = new Vertex<char>('x');
var yVertex = new Vertex<char>('y');
var zVertex = new Vertex<char>('z');
sVertex.AddDirectedEdge(6, tVertex);
sVertex.AddDirectedEdge(7, yVertex);
tVertex.AddDirectedEdge(-5, xVertex);
xVertex.AddDirectedEdge(2, tVertex);
tVertex.AddDirectedEdge(8, yVertex);
zVertex.AddDirectedEdge(7, xVertex);
zVertex.AddDirectedEdge(2, sVertex);
tVertex.AddDirectedEdge(-4, zVertex);
yVertex.AddDirectedEdge(-3, xVertex);
yVertex.AddDirectedEdge(9, zVertex);
graf.AddVertex(sVertex);
graf.AddVertex(tVertex);
graf.AddVertex(xVertex);
graf.AddVertex(yVertex);
graf.AddVertex(zVertex);
bool res = graf.BellmanFordShortestPaths(sVertex);
Assert.Equal(false, res);
}
示例5: SingleSourceTest2
public void SingleSourceTest2()
{
var graf = new Graf<char>();
var rVertex = new Vertex<char>('r');
var sVertex = new Vertex<char>('s');
var tVertex = new Vertex<char>('t');
var xVertex = new Vertex<char>('x');
var yVertex = new Vertex<char>('y');
var zVertex = new Vertex<char>('z');
rVertex.AddDirectedEdge(5, sVertex);
rVertex.AddDirectedEdge(3, tVertex);
sVertex.AddDirectedEdge(2, tVertex);
sVertex.AddDirectedEdge(6, xVertex);
tVertex.AddDirectedEdge(7, xVertex);
tVertex.AddDirectedEdge(4, yVertex);
tVertex.AddDirectedEdge(2, zVertex);
xVertex.AddDirectedEdge(-1, yVertex);
xVertex.AddDirectedEdge(-2, zVertex);
yVertex.AddDirectedEdge(-2, zVertex);
graf.AddVertex(rVertex);
graf.AddVertex(sVertex);
graf.AddVertex(tVertex);
graf.AddVertex(xVertex);
graf.AddVertex(yVertex);
graf.AddVertex(zVertex);
graf.TopologicalShortestPaths(sVertex);
var topologicalSort = graf.GetTopologicalSort().ToList();
Assert.NotNull(topologicalSort);
Assert.Equal(double.PositiveInfinity, rVertex.DiscoveryTime);
Assert.Equal(0, sVertex.DiscoveryTime);
Assert.Equal(2, tVertex.DiscoveryTime);
Assert.Equal(6, xVertex.DiscoveryTime);
Assert.Equal(5, yVertex.DiscoveryTime);
Assert.Equal(3, zVertex.DiscoveryTime);
}
示例6: ShortestsPathsTest2
public void ShortestsPathsTest2()
{
var graf = new Graf<char>();
var v1Vertex = new Vertex<char>('1');
var v2Vertex = new Vertex<char>('2');
var v3Vertex = new Vertex<char>('3');
var v4Vertex = new Vertex<char>('4');
var v5Vertex = new Vertex<char>('5');
v1Vertex.AddDirectedEdge(3, v2Vertex);
v1Vertex.AddDirectedEdge(-4, v5Vertex);
v2Vertex.AddDirectedEdge(1, v4Vertex);
v2Vertex.AddDirectedEdge(7, v5Vertex);
v3Vertex.AddDirectedEdge(4, v2Vertex);
v4Vertex.AddDirectedEdge(2, v1Vertex);
v4Vertex.AddDirectedEdge(-5, v3Vertex);
v5Vertex.AddDirectedEdge(6, v4Vertex);
graf.AddVertex(v1Vertex);
graf.AddVertex(v2Vertex);
graf.AddVertex(v3Vertex);
graf.AddVertex(v4Vertex);
graf.AddVertex(v5Vertex);
var res = graf.GetAllPairsShortestsPathsJohnson();
Assert.Equal(0, res[0, 0]);
Assert.Equal(3, res[1, 0]);
Assert.Equal(7, res[2, 0]);
Assert.Equal(2, res[3, 0]);
Assert.Equal(8, res[4, 0]);
Assert.Equal(1, res[0, 1]);
Assert.Equal(0, res[1, 1]);
Assert.Equal(4, res[2, 1]);
Assert.Equal(-1, res[3, 1]);
Assert.Equal(5, res[4, 1]);
Assert.Equal(-3, res[0, 2]);
Assert.Equal(-4, res[1, 2]);
Assert.Equal(0, res[2, 2]);
Assert.Equal(-5, res[3, 2]);
Assert.Equal(1, res[4, 2]);
Assert.Equal(2, res[0, 3]);
Assert.Equal(1, res[1, 3]);
Assert.Equal(5, res[2, 3]);
Assert.Equal(0, res[3, 3]);
Assert.Equal(6, res[4, 3]);
Assert.Equal(-4, res[0, 4]);
Assert.Equal(-1, res[1, 4]);
Assert.Equal(3, res[2, 4]);
Assert.Equal(-2, res[3, 4]);
Assert.Equal(0, res[4, 4]);
}
示例7: ShortestsPathsTest1
public void ShortestsPathsTest1()
{
var graf = new Graf<char>();
var v1Vertex = new Vertex<char>('1');
var v2Vertex = new Vertex<char>('2');
var v3Vertex = new Vertex<char>('3');
var v4Vertex = new Vertex<char>('4');
var v5Vertex = new Vertex<char>('5');
v1Vertex.AddDirectedEdge(3, v2Vertex);
v1Vertex.AddDirectedEdge(-4, v5Vertex);
v2Vertex.AddDirectedEdge(1, v4Vertex);
v2Vertex.AddDirectedEdge(7, v5Vertex);
v3Vertex.AddDirectedEdge(4, v2Vertex);
v4Vertex.AddDirectedEdge(2, v1Vertex);
v4Vertex.AddDirectedEdge(-5, v3Vertex);
v5Vertex.AddDirectedEdge(6, v4Vertex);
graf.AddVertex(v1Vertex);
graf.AddVertex(v2Vertex);
graf.AddVertex(v3Vertex);
graf.AddVertex(v4Vertex);
graf.AddVertex(v5Vertex);
var res = graf.GetAllPairsShortestsPathsFloydWarshall(graf.GetWeights());
Assert.Equal(0, res.Item1[0, 0]);
Assert.Equal(3, res.Item1[1, 0]);
Assert.Equal(7, res.Item1[2, 0]);
Assert.Equal(2, res.Item1[3, 0]);
Assert.Equal(8, res.Item1[4, 0]);
Assert.Equal(1, res.Item1[0, 1]);
Assert.Equal(0, res.Item1[1, 1]);
Assert.Equal(4, res.Item1[2, 1]);
Assert.Equal(-1, res.Item1[3, 1]);
Assert.Equal(5, res.Item1[4, 1]);
Assert.Equal(-3, res.Item1[0, 2]);
Assert.Equal(-4, res.Item1[1, 2]);
Assert.Equal(0, res.Item1[2, 2]);
Assert.Equal(-5, res.Item1[3, 2]);
Assert.Equal(1, res.Item1[4, 2]);
Assert.Equal(2, res.Item1[0, 3]);
Assert.Equal(1, res.Item1[1, 3]);
Assert.Equal(5, res.Item1[2, 3]);
Assert.Equal(0, res.Item1[3, 3]);
Assert.Equal(6, res.Item1[4, 3]);
Assert.Equal(-4, res.Item1[0, 4]);
Assert.Equal(-1, res.Item1[1, 4]);
Assert.Equal(3, res.Item1[2, 4]);
Assert.Equal(-2, res.Item1[3, 4]);
Assert.Equal(0, res.Item1[4, 4]);
Assert.Null(res.Item2[0, 0]);
Assert.Equal(3, res.Item2[1, 0].Value);
Assert.Equal(3, res.Item2[2, 0].Value);
Assert.Equal(3, res.Item2[3, 0].Value);
Assert.Equal(3, res.Item2[4, 0].Value);
Assert.Equal(2, res.Item2[0, 1].Value);
Assert.Null(res.Item2[1, 1]);
Assert.Equal(2, res.Item2[2, 1].Value);
Assert.Equal(2, res.Item2[3, 1].Value);
Assert.Equal(2, res.Item2[4, 1].Value);
Assert.Equal(3, res.Item2[0, 2].Value);
Assert.Equal(3, res.Item2[1, 2].Value);
Assert.Null(res.Item2[2, 2]);
Assert.Equal(3, res.Item2[3, 2].Value);
Assert.Equal(3, res.Item2[4, 2].Value);
Assert.Equal(4, res.Item2[0, 3].Value);
Assert.Equal(1, res.Item2[1, 3].Value);
Assert.Equal(1, res.Item2[2, 3].Value);
Assert.Null(res.Item2[3, 3]);
Assert.Equal(4, res.Item2[4, 3].Value);
Assert.Equal(0, res.Item2[0, 4].Value);
Assert.Equal(0, res.Item2[1, 4].Value);
Assert.Equal(0, res.Item2[2, 4].Value);
Assert.Equal(0, res.Item2[3, 4].Value);
Assert.Null(res.Item2[4, 4]);
}
示例8: DFSTest1
public void DFSTest1()
{
var graf = new Graf<char>();
var qVertex = new Vertex<char>('q');
var rVertex = new Vertex<char>('r');
var sVertex = new Vertex<char>('s');
var tVertex = new Vertex<char>('t');
var uVertex = new Vertex<char>('u');
var vVertex = new Vertex<char>('v');
var wVertex = new Vertex<char>('w');
var xVertex = new Vertex<char>('x');
var yVertex = new Vertex<char>('y');
var zVertex = new Vertex<char>('z');
qVertex.AddDirectedEdge(1, sVertex);
qVertex.AddDirectedEdge(1, tVertex);
qVertex.AddDirectedEdge(1, wVertex);
sVertex.AddDirectedEdge(1, vVertex);
vVertex.AddDirectedEdge(1, wVertex);
wVertex.AddDirectedEdge(1, sVertex);
tVertex.AddDirectedEdge(1, xVertex);
tVertex.AddDirectedEdge(1, yVertex);
xVertex.AddDirectedEdge(1, zVertex);
yVertex.AddDirectedEdge(1, qVertex);
rVertex.AddDirectedEdge(1, uVertex);
rVertex.AddDirectedEdge(1, yVertex);
uVertex.AddDirectedEdge(1, yVertex);
graf.AddVertex(qVertex);
graf.AddVertex(rVertex);
graf.AddVertex(sVertex);
graf.AddVertex(tVertex);
graf.AddVertex(uVertex);
graf.AddVertex(vVertex);
graf.AddVertex(wVertex);
graf.AddVertex(xVertex);
graf.AddVertex(yVertex);
graf.AddVertex(zVertex);
graf.DFS();
Assert.Equal(1, qVertex.DiscoveryTime);
Assert.Equal(16, qVertex.FinishingTime);
Assert.Equal(17, rVertex.DiscoveryTime);
Assert.Equal(20, rVertex.FinishingTime);
Assert.Equal(2, sVertex.DiscoveryTime);
Assert.Equal(7, sVertex.FinishingTime);
Assert.Equal(8, tVertex.DiscoveryTime);
Assert.Equal(15, tVertex.FinishingTime);
Assert.Equal(18, uVertex.DiscoveryTime);
Assert.Equal(19, uVertex.FinishingTime);
Assert.Equal(3, vVertex.DiscoveryTime);
Assert.Equal(6, vVertex.FinishingTime);
Assert.Equal(4, wVertex.DiscoveryTime);
Assert.Equal(5, wVertex.FinishingTime);
Assert.Equal(9, xVertex.DiscoveryTime);
Assert.Equal(12, xVertex.FinishingTime);
Assert.Equal(13, yVertex.DiscoveryTime);
Assert.Equal(14, yVertex.FinishingTime);
Assert.Equal(10, zVertex.DiscoveryTime);
Assert.Equal(11, zVertex.FinishingTime);
}
示例9: DifferenceTest0
public void DifferenceTest0()
{
var graf = new Graf<char>();
var v0Vertex = new Vertex<char>('0');
var v1Vertex = new Vertex<char>('1');
var v2Vertex = new Vertex<char>('2');
var v3Vertex = new Vertex<char>('3');
var v4Vertex = new Vertex<char>('4');
var v5Vertex = new Vertex<char>('5');
v0Vertex.AddDirectedEdge(0, v1Vertex);
v0Vertex.AddDirectedEdge(0, v2Vertex);
v0Vertex.AddDirectedEdge(0, v3Vertex);
v0Vertex.AddDirectedEdge(0, v4Vertex);
v0Vertex.AddDirectedEdge(0, v5Vertex);
v1Vertex.AddDirectedEdge(5, v3Vertex);
v1Vertex.AddDirectedEdge(4, v4Vertex);
v2Vertex.AddDirectedEdge(0, v1Vertex);
v3Vertex.AddDirectedEdge(-1, v4Vertex);
v3Vertex.AddDirectedEdge(-3, v5Vertex);
v4Vertex.AddDirectedEdge(-3, v5Vertex);
v5Vertex.AddDirectedEdge(-1, v1Vertex);
v5Vertex.AddDirectedEdge(1, v2Vertex);
graf.AddVertex(v0Vertex);
graf.AddVertex(v1Vertex);
graf.AddVertex(v2Vertex);
graf.AddVertex(v3Vertex);
graf.AddVertex(v4Vertex);
graf.AddVertex(v5Vertex);
bool res = graf.BellmanFordShortestPaths(v0Vertex);
Assert.Equal(true, res);
Assert.Equal(0, v0Vertex.DiscoveryTime);
Assert.Equal(-5, v1Vertex.DiscoveryTime);
Assert.Equal(-3, v2Vertex.DiscoveryTime);
Assert.Equal(0, v3Vertex.DiscoveryTime);
Assert.Equal(-1, v4Vertex.DiscoveryTime);
Assert.Equal(-4, v5Vertex.DiscoveryTime);
}
示例10: calc
public double calc(int amount, string fromUnit, string toUnit)
{
var from = (Units) Enum.Parse(typeof (Units), fromUnit.Replace("in", "inch"));
var to = (Units) Enum.Parse(typeof (Units), toUnit.Replace("in", "inch"));
var dgraf = new Graf<Units>();
var ftVertex = new Vertex<Units>(Units.ft);
var inVertex = new Vertex<Units>(Units.inch);
var ydVertex = new Vertex<Units>(Units.yd);
var miVertex = new Vertex<Units>(Units.mi);
ftVertex.AddDirectedEdge(12, inVertex);
inVertex.AddDirectedEdge(1D / 12, ftVertex);
ydVertex.AddDirectedEdge(3, ftVertex);
ftVertex.AddDirectedEdge(1D / 3, ydVertex);
miVertex.AddDirectedEdge(1760, ydVertex);
ydVertex.AddDirectedEdge(1D / 1760, miVertex);
dgraf.AddVertex(ftVertex);
dgraf.AddVertex(inVertex);
dgraf.AddVertex(ydVertex);
dgraf.AddVertex(miVertex);
var source = dgraf.Vertexes.FirstOrDefault(vertex => vertex.Key == from);
var target = dgraf.Vertexes.FirstOrDefault(vertex => vertex.Key == to);
var vertexPath = dgraf.GetBreadthPath(source, target).ToList();
var edgePath = new System.Collections.Generic.Stack<Edge<Units>>();
if (target.Color != Vertex<Units>.VertexColor.Black)
return 0;
var currentVertex = target;
while (currentVertex != null && currentVertex != source && currentVertex.Parent != null)
{
var currentEdge = currentVertex.Parent.Edges.FirstOrDefault(edge => edge.Target == currentVertex);
edgePath.Push(currentEdge);
currentVertex = currentVertex.Parent;
}
if (source == target)
return amount;
if (!edgePath.Any())
return 0;
double res = amount;
double weigth = 1;
foreach (var pathEdge in edgePath)
weigth *= pathEdge.Weigth;
return res * weigth;
}