public void ThreeVerticeGraphHasTwoBridges() { var sut = new BridgesInGraph(); var graph = new UndirectedGraph(3); graph.Connect(0, 1); graph.Connect(0, 2); Assert.Collection(sut.GetBridges(graph), arg => Assert.Equal(new Tuple <int, int>(0, 1), arg), arg => Assert.Equal(new Tuple <int, int>(0, 2), arg)); }
public void LinedUpGraphIsNotBiconnected() { var sut = new BiConnectedGraph(); var graph = new UndirectedGraph(3); graph.Connect(0, 1); graph.Connect(1, 2); Assert.False(sut.IsBiConnected(graph)); }
public void ThreeVerticeGraphHasNoBridges() { var sut = new BridgesInGraph(); var graph = new UndirectedGraph(3); graph.Connect(0, 1); graph.Connect(1, 2); graph.Connect(2, 0); Assert.Empty(sut.GetBridges(graph)); }
public void TriangularGraphIsBiconnected() { var sut = new BiConnectedGraph(); var graph = new UndirectedGraph(3); graph.Connect(0, 1); graph.Connect(1, 2); graph.Connect(2, 0); Assert.True(sut.IsBiConnected(graph)); }
public void ThreeVerticeGraphIsEulerian() { var sut = new EulerianPath(); var graph = new UndirectedGraph(3); graph.Connect(0, 1); graph.Connect(1, 2); graph.Connect(2, 0); var result = sut.IsEulerian(graph); Assert.True(result.hasEulerianCycle); }
public void DenseGraphWithoutBackedgeIsNotBiconnected() { var sut = new BiConnectedGraph(); var graph = new UndirectedGraph(5); graph.Connect(1, 0); graph.Connect(0, 2); graph.Connect(2, 1); graph.Connect(0, 3); graph.Connect(3, 4); Assert.False(sut.IsBiConnected(graph)); }
public void Baseline() { var sut = new MColoringProblem(); var graph = new UndirectedGraph(4); graph.Connect(0, 1); graph.Connect(0, 2); graph.Connect(0, 3); graph.Connect(1, 2); graph.Connect(2, 3); var result = sut.CanColor(graph, 3); Assert.True(result); }
public void SemiEulerianGraph() { var sut = new EulerianPath(); var graph = new UndirectedGraph(5); graph.Connect(1, 0); graph.Connect(0, 2); graph.Connect(2, 1); graph.Connect(0, 3); graph.Connect(3, 4); var result = sut.IsEulerian(graph); Assert.False(result.hasEulerianCycle); Assert.True(result.hasEulerianPath); }
public void BaselineWithNoPath() { var sut = new HamiltonPath(); var graph = new UndirectedGraph(5); graph.Connect(0, 1); graph.Connect(0, 3); graph.Connect(1, 2); graph.Connect(1, 4); graph.Connect(2, 4); var(hasPath, hasCycle, _) = sut.HasHamiltonPath(graph); Assert.False(hasCycle); Assert.False(hasPath); }
public void Baseline() { var sut = new HamiltonPath(); var graph = new UndirectedGraph(5); graph.Connect(0, 1); graph.Connect(0, 3); graph.Connect(1, 2); graph.Connect(1, 3); graph.Connect(1, 4); graph.Connect(2, 4); graph.Connect(3, 4); var(hasPath, hasCycle, path) = sut.HasHamiltonPath(graph); Assert.True(hasCycle); Assert.True(hasPath); #pragma warning disable HAA0101 // Array allocation for params parameter Assert.Collection(path, arg => Assert.Equal(0, arg), arg => Assert.Equal(1, arg), arg => Assert.Equal(2, arg), arg => Assert.Equal(4, arg), arg => Assert.Equal(3, arg), arg => Assert.Equal(0, arg)); #pragma warning restore HAA0101 // Array allocation for params parameter }
public void TwoVerticesGraphIsBiconnected() { var sut = new BiConnectedGraph(); var graph = new UndirectedGraph(2); graph.Connect(0, 1); Assert.True(sut.IsBiConnected(graph)); }
public void ThreeVerticeGraphHasOneEdgeEulerianTrail() { var sut = new FleurysAlgorithm(); var graph = new UndirectedGraph(3); graph.Connect(0, 1); graph.Connect(1, 2); Assert.Collection(sut.GetEulerianTrail(graph), arg => { Assert.Equal(2, arg.Item1); Assert.Equal(1, arg.Item2); }, arg => { Assert.Equal(1, arg.Item1); Assert.Equal(0, arg.Item2); }); }
public void Baseline() { var sut = new KargersAlgorithmForMinimumCut(); var graph = new UndirectedGraph(4); graph.Connect(0, 1); graph.Connect(0, 2); graph.Connect(1, 3); graph.Connect(1, 2); graph.Connect(2, 3); var minCut = int.MaxValue; while (minCut > 2) { minCut = sut.MinCut(graph); Assert.NotInRange(minCut, 0, 1); } }
public void TwoVerticeGraphIsSemiEulerian() { var sut = new EulerianPath(); var graph = new UndirectedGraph(2); graph.Connect(0, 1); var result = sut.IsEulerian(graph); Assert.False(result.hasEulerianCycle); Assert.True(result.hasEulerianPath); }
public void DenseGraphIsBiconnected() { var sut = new BiConnectedGraph(); var graph = new UndirectedGraph(5); graph.Connect(1, 0); graph.Connect(0, 2); graph.Connect(2, 1); graph.Connect(0, 3); graph.Connect(3, 4); graph.Connect(2, 4); Assert.True(sut.IsBiConnected(graph)); }
static void Main(string[] args) { UndirectedGraph<int> lGraph = new UndirectedGraph<int>(); lGraph.AddVertex(1); lGraph.AddVertex(2); lGraph.AddVertex(3); lGraph.AddVertex(4); lGraph.AddVertex(5); lGraph.AddVertex(6); lGraph.AddVertex(7); lGraph.AddVertex(8); lGraph.Connect(lGraph[1], lGraph[2]); lGraph.Connect(lGraph[2], lGraph[3]); lGraph.Connect(lGraph[7], lGraph[3]); lGraph.Connect(lGraph[5], lGraph[7]); lGraph.Connect(lGraph[2], lGraph[6]); lGraph.Connect(lGraph[5], lGraph[4]); lGraph.Connect(lGraph[4], lGraph[3]); lGraph.Connect(lGraph[7], lGraph[8]); lGraph.Connect(lGraph[7], lGraph[1]); foreach (var lVertex in lGraph.GetVertices()) { Console.WriteLine("Stupeň uzlu {0} = {1}",lVertex.Value, lGraph.GetVertexDegree(lVertex)); } ISequence<int> lSeq = new Sequence<int>(); lSeq.MakeSequence(new Edge<int>(8, 2), new Edge<int>(2, 5), new Edge<int>(5, 1), new Edge<int>(1, 3)); //Console.WriteLine("Is Closed Sequence: " + lSeq.IsClosedSquence()); Console.WriteLine("Is Graph Sequence: " + lSeq.IsGraphSequence(lGraph)); Console.WriteLine("Is Move: " + lSeq.IsMove()); Console.WriteLine("Is Path: " + lSeq.IsPath()); foreach (var lVertex in lGraph.GetVertices()) { var lSousedi = lGraph.GetVertices(lVertex); Console.Write("Sousedé uzlu {0} = ", lVertex.Value); foreach (var nVertex in lSousedi) { Console.Write("{0}, ", nVertex.Value); } Console.WriteLine(""); } var lGr = new UndirectedGraph<int>(); lGr.AddVertex(18); lGr.AddVertex(20); lGr.AddVertex(13); lGr.AddVertex(11); lGr.AddVertex(20); lGr.Connect(lGr[13], lGr[11]); lGr.Connect(lGr[20], lGr[11]); lGr.Connect(lGr[13], lGr[18]); lGr.Connect(lGr[18], lGr[13]); lGr.Connect(lGr[11], lGr[18]); lGr.Connect(lGr[20], lGr[13]); lGraph.Join(lGr, new Edge<int>(1, 11)); foreach (var lVertex in lGraph.GetVertices()) { var lSousedi = lGraph.GetVertices(lVertex); Console.Write("Sousedé uzlu {0} = ", lVertex.Value); foreach (var nVertex in lSousedi) { Console.Write("{0}, ", nVertex.Value); } Console.WriteLine(""); } var lGraf = new UndirectedValuedGraph<int>(); lGraf.AddVertex(1); lGraf.AddVertex(2); lGraf.AddVertex(3); lGraf.AddVertex(4); lGraf.AddVertex(5); lGraf.AddVertex(6); lGraf.Connect(lGraf[1], lGraf[2], 2); lGraf.Connect(lGraf[1], lGraf[3], 2); lGraf.Connect(lGraf[1], lGraf[4], 1); lGraf.Connect(lGraf[1], lGraf[5], 2); lGraf.Connect(lGraf[1], lGraf[6], 3); lGraf.Connect(lGraf[2], lGraf[3], 3); lGraf.Connect(lGraf[2], lGraf[4], 4); lGraf.Connect(lGraf[2], lGraf[5], 1); lGraf.Connect(lGraf[2], lGraf[6], 3); lGraf.Connect(lGraf[3], lGraf[4], 1); lGraf.Connect(lGraf[3], lGraf[5], 2); lGraf.Connect(lGraf[3], lGraf[6], 1); lGraf.Connect(lGraf[4], lGraf[5], 2); lGraf.Connect(lGraf[4], lGraf[6], 3); lGraf.Connect(lGraf[5], lGraf[6], 3); var lVys = lGraf.GetSpanningTree(); var lSeznam = lVys.WideSearch(lGraf[6]); Console.ReadKey(); }