public void Long() { var gb = new WLongGraphBuilder(5, true); gb.Add(0, 1, 1); gb.Add(0, 2, 10); gb.Add(0, 3, 30); gb.Add(0, 4, 40); gb.Add(1, 2, 5); gb.Add(2, 3, 605); gb.Add(2, 4, 6); gb.Add(4, 3, 6); gb.Add(4, 0, 1); var graph = gb.ToMFGraph(); graph.Flow(0, 1).Should().Be(1); graph.Flow(0, 3).Should().Be(46); }
public void Long() { var gb = new WLongGraphBuilder(5, true); gb.Add(0, 1, 1); gb.Add(0, 2, 0); gb.Add(0, 3, 1); gb.Add(0, 4, 1); gb.Add(1, 2, 0); gb.Add(2, 3, 1); gb.Add(2, 4, 0); gb.Add(4, 3, 1); gb.Add(4, 0, 1); var graph = gb.ToGraph(); graph.ShortestPath01BFS(0).Should().Equal(new long[] { 0, 1, 0, 1, 0 }); graph.ShortestPath01BFS(1).Should().Equal(new long[] { 1, 0, 0, 1, 0 }); graph.ShortestPath01BFS(2).Should().Equal(new long[] { 1, 2, 0, 1, 0 }); graph.ShortestPath01BFS(3).Should().Equal(new long[] { long.MaxValue, long.MaxValue, long.MaxValue, 0, long.MaxValue }); graph.ShortestPath01BFS(4).Should().Equal(new long[] { 1, 2, 1, 1, 0 }); }
public void Long() { var gb = new WLongGraphBuilder(5, true); gb.Add(0, 1, 1); gb.Add(0, 2, 10); gb.Add(0, 3, 30); gb.Add(0, 4, 40); gb.Add(1, 2, 5); gb.Add(2, 3, 605); gb.Add(2, 4, 6); gb.Add(4, 3, 6); gb.Add(4, 0, 1); var res = gb.ToGraph().WarshallFloyd(); res[0].Should().Equal(new long[] { 0, 1, 6, 18, 12 }); res[1].Should().Equal(new long[] { 12, 0, 5, 17, 11 }); res[2].Should().Equal(new long[] { 7, 8, 0, 12, 6 }); res[3].Should().Equal(new long[] { 4611686018427387903, 4611686018427387903, 4611686018427387903, 0, 4611686018427387903 }); res[4].Should().Equal(new long[] { 1, 2, 7, 6, 0 }); }
public void Long() { var gb = new WLongGraphBuilder(5, false); gb.Add(0, 1, 1); gb.Add(0, 2, 10); gb.Add(0, 3, 30); gb.Add(0, 4, 40); gb.Add(1, 2, 5); gb.Add(2, 3, 605); gb.Add(2, 4, 6); gb.Add(4, 3, 6); gb.Add(4, 0, 1); var graph = gb.ToGraph(); graph.Prim().Should().Equal( (0, new WEdge <long>(1, 1)), (0, new WEdge <long>(4, 1)), (1, new WEdge <long>(2, 5)), (4, new WEdge <long>(3, 6))); }
public void NegativeCycle() { var gb = new WLongGraphBuilder(5, true); gb.Add(0, 1, 1); gb.Add(0, 2, 10); gb.Add(0, 3, 30); gb.Add(0, 4, 40); gb.Add(1, 2, -5); gb.Add(2, 3, -605); gb.Add(2, 4, -6); gb.Add(4, 3, 6); gb.Add(4, 0, -1); var graph = gb.ToGraph(); graph.Invoking(graph => graph.BellmanFord(0)).Should().Throw <InvalidOperationException>(); graph.Invoking(graph => graph.BellmanFord(1)).Should().Throw <InvalidOperationException>(); graph.Invoking(graph => graph.BellmanFord(2)).Should().Throw <InvalidOperationException>(); graph.Invoking(graph => graph.BellmanFord(3)).Should().Throw <InvalidOperationException>(); graph.Invoking(graph => graph.BellmanFord(4)).Should().Throw <InvalidOperationException>(); }
public void NegativeLength() { var gb = new WLongGraphBuilder(5, true); gb.Add(0, 1, 1); gb.Add(0, 2, 10); gb.Add(0, 3, 30); gb.Add(0, 4, 40); gb.Add(1, 2, 5); gb.Add(2, 3, -605); gb.Add(2, 4, 6); gb.Add(4, 3, 6); gb.Add(4, 0, 1); var graph = gb.ToGraph(); graph.BellmanFord(0).Should().Equal(new long[] { 0, 1, 6, -599, 12 }); graph.BellmanFord(1).Should().Equal(new long[] { 12, 0, 5, -600, 11 }); graph.BellmanFord(2).Should().Equal(new long[] { 7, 8, 0, -605, 6 }); graph.BellmanFord(3).Should().Equal(new long[] { 4611686018427387903, 4611686018427387903, 4611686018427387903, 0, 4611686018427387903 }); graph.BellmanFord(4).Should().Equal(new long[] { 1, 2, 7, -598, 0 }); }
public void Long() { var gb = new WLongGraphBuilder(5, true); gb.Add(0, 1, 1); gb.Add(0, 2, 10); gb.Add(0, 3, 30); gb.Add(0, 4, 40); gb.Add(1, 2, 5); gb.Add(2, 3, 605); gb.Add(2, 4, 6); gb.Add(4, 3, 6); gb.Add(4, 0, 1); var graph = gb.ToGraph(); graph.Dijkstra(0).Should().Equal(new long[] { 0, 1, 6, 18, 12 }); graph.Dijkstra(1).Should().Equal(new long[] { 12, 0, 5, 17, 11 }); graph.Dijkstra(2).Should().Equal(new long[] { 7, 8, 0, 12, 6 }); graph.Dijkstra(3).Should().Equal(new long[] { long.MaxValue, long.MaxValue, long.MaxValue, 0, long.MaxValue }); graph.Dijkstra(4).Should().Equal(new long[] { 1, 2, 7, 6, 0 }); }
public void Long() { var gb = new WLongGraphBuilder(5, false); gb.Add(0, 1, 1); gb.Add(0, 2, 10); gb.Add(0, 3, 30); gb.Add(0, 4, 40); gb.Add(1, 2, 5); gb.Add(2, 3, 605); gb.Add(2, 4, 6); gb.Add(4, 3, 6); gb.Add(4, 0, 1); var graph = gb.ToGraph(); var res = graph.Kruskal(); res.Should().HaveCount(1); res[0].Should().Equal( (0, new WEdge <long>(1, 1)), (0, new WEdge <long>(4, 1)), (1, new WEdge <long>(2, 5)), (4, new WEdge <long>(3, 6))); }