本文整理汇总了C#中Graph.IsStronglyConnected方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.IsStronglyConnected方法的具体用法?C# Graph.IsStronglyConnected怎么用?C# Graph.IsStronglyConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.IsStronglyConnected方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Undirected
public void Undirected()
{
var graph = new Graph<int>(false);
var vertex1 = new Vertex<int>(1);
var vertex2 = new Vertex<int>(2);
var vertex3 = new Vertex<int>(3);
var vertex4 = new Vertex<int>(4);
graph.AddVertex(vertex1);
graph.AddVertex(vertex2);
graph.AddVertex(vertex3);
graph.AddVertex(vertex4);
graph.AddEdge(vertex1, vertex2);
graph.AddEdge(vertex3, vertex2);
graph.AddEdge(vertex1, vertex3);
Assert.IsFalse(graph.IsStronglyConnected());
graph.AddEdge(vertex2, vertex4);
Assert.IsTrue(graph.IsStronglyConnected());
graph.RemoveEdge(vertex2, vertex3);
Assert.IsTrue(graph.IsStronglyConnected());
graph.RemoveEdge(vertex1, vertex3);
Assert.IsFalse(graph.IsStronglyConnected());
}
示例2: IsStronglyConnectedExample
public void IsStronglyConnectedExample()
{
// Initialize a new directed graph instance
var graph = new Graph<int>(false);
// Add 4 vertices to the graph
var vertex1 = graph.AddVertex(1);
var vertex2 = graph.AddVertex(2);
var vertex3 = graph.AddVertex(3);
var vertex4 = graph.AddVertex(4);
// Add edges to the vertices
graph.AddEdge(vertex1, vertex2);
graph.AddEdge(vertex3, vertex2);
graph.AddEdge(vertex1, vertex3);
// The graph will not be strongly connected, since
// vertex vertex4 is not reachable from every other vertex
Assert.IsFalse(graph.IsStronglyConnected());
// Add an edge from vertex vertex2 to vertex vertex4
graph.AddEdge(vertex2, vertex4);
// Now the graph is strongly connected
Assert.IsTrue(graph.IsStronglyConnected());
}
示例3: ExceptionEmptyUndirected
public void ExceptionEmptyUndirected()
{
var graph = new Graph<int>(false);
graph.IsStronglyConnected();
}
示例4: ExceptionEmptyDirected
public void ExceptionEmptyDirected()
{
var graph = new Graph<int>(true);
graph.IsStronglyConnected();
}