本文整理汇总了C#中Graph.AddEdgeFromStartNode方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.AddEdgeFromStartNode方法的具体用法?C# Graph.AddEdgeFromStartNode怎么用?C# Graph.AddEdgeFromStartNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.AddEdgeFromStartNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetChangeGraphs
public IEnumerable<Graph<IFileReference>> GetChangeGraphs(IMultiFileSystemDiff diff)
{
foreach (var changeList in diff.FileChanges)
{
var graph = new Graph<IFileReference>(m_FileReferenceComparer);
foreach (var historyName in changeList.HistoryNames)
{
var changes = changeList.GetChanges(historyName).ToArray();
// add changes for the current history to the graph
if (changes.Any())
{
graph.AddEdgeFromStartNode(changes.First().FromVersion);
foreach (var change in changes)
{
graph.AddEdge(change.FromVersion, change.ToVersion);
}
}
// for histories without a change to the current file, add the current file version as node
else
{
var rootDirectory = diff.ToSnapshot.GetSnapshot(historyName).RootDirectory;
graph.AddEdgeFromStartNode(rootDirectory.GetFileReferenceOrDefault(changeList.Path));
}
}
yield return graph;
}
}
示例2: Graph_can_be_converted_to_acyclic_graph_02
public void Graph_can_be_converted_to_acyclic_graph_02()
{
// ARRANGE
var expectedValuesInOrder = new[] {0, 1, 2, 1};
var graph = new Graph<int>(EqualityComparer<int>.Default);
// ACT
graph.AddEdgeFromStartNode(0);
graph.AddEdge(0, 1);
graph.AddEdge(1, 2);
graph.AddEdge(2, 1);
var nodes = graph.ToAcyclicGraph().ValueNodes.ToArray();
// ASSERT
Assert.Equal(4, nodes.Length);
Assert.Equal(expectedValuesInOrder, nodes.Select(n => n.Value).ToArray());
// expected Graph 0 -> 1 -> 2 -> 1 (1 was added twice to prevent a cycle)
Assert.Equal(1, nodes[0].Successors.Single().Value);
Assert.Equal(2, nodes[1].Successors.Single().Value);
Assert.Equal(1, nodes[2].Successors.Single().Value);
Assert.Empty(nodes[3].Successors);
}
示例3: Graph_can_be_converted_to_acyclic_graph_01
public void Graph_can_be_converted_to_acyclic_graph_01()
{
var graph = new Graph<int>(EqualityComparer<int>.Default);
graph.AddEdgeFromStartNode(0);
graph.AddEdge(0,1);
graph.AddEdge(1,2);
graph.AddEdge(2,1);
Assert.Equal(4, graph.ToAcyclicGraph().ValueNodes.Count());
}
示例4: Graph_can_be_converted_to_acyclic_graph_03
public void Graph_can_be_converted_to_acyclic_graph_03()
{
// ARRANGE
var expectedValuesInOrder = new[] { 0, 1, 2, 0 };
var graph = new Graph<int>(EqualityComparer<int>.Default);
// ACT
graph.AddEdgeFromStartNode(0);
graph.AddEdge(0, 1);
graph.AddEdge(1, 0);
graph.AddEdge(2, 0);
var nodes = graph.ToAcyclicGraph().ValueNodes.ToArray();
// ASSERT
Assert.Equal(4, nodes.Length);
Assert.Equal(expectedValuesInOrder, nodes.Select(n => n.Value).ToArray());
// expected Graph
// 2
// |
// v
// 0 -> 1 -> 0
var node0_1 = nodes.First(n => n.Value == 0);
var node0_2 = nodes.Last(n => n.Value == 0);
var node1 = nodes.Single(n => n.Value == 1);
var node2 = nodes.Single(n => n.Value == 2);
Assert.Single(node2.Successors);
Assert.Equal(node0_2, node2.Successors.Single());
Assert.Single(node0_1.Successors);
Assert.Equal(node1, node0_1.Successors.Single());
Assert.Single(node1.Successors);
Assert.Equal(node0_2, node1.Successors.Single());
Assert.Empty(node0_2.Successors);
}