public static IDictionary <int, int> GetDiscoverTimes(AdjacencyGraph <int, Edge <int> > g) { var dfs = new DepthFirstSearchAlgorithm <int, Edge <int> >(g); var recorder = new VertexTimeStamperObserver <int>(); using (recorder.Attach(dfs)) { dfs.Compute(); return(recorder.DiscoverTimes); } }
public static IDictionary <string, int> GetFinishTimes(AdjacencyGraph <string, TaggedEdge <string, string> > g) { var dfs = new DepthFirstSearchAlgorithm <string, TaggedEdge <string, string> >(g); var recorder = new VertexTimeStamperObserver <string>(); using (recorder.Attach(dfs)) { dfs.Compute(); return(recorder.FinishTimes); } }
public void Attach() { // DFS is used for tests but result may change if using another search algorithm // or another starting point { var recorder = new VertexTimeStamperObserver <int>(); var graph = new AdjacencyGraph <int, Edge <int> >(); var dfs = new DepthFirstSearchAlgorithm <int, Edge <int> >(graph); using (recorder.Attach(dfs)) { dfs.Compute(); CollectionAssert.IsEmpty(recorder.DiscoverTimes); CollectionAssert.IsEmpty(recorder.FinishTimes); } } { var recorder = new VertexTimeStamperObserver <int>(); var graph = new AdjacencyGraph <int, Edge <int> >(); graph.AddVertexRange(new[] { 1, 2 }); var dfs = new DepthFirstSearchAlgorithm <int, Edge <int> >(graph); using (recorder.Attach(dfs)) { dfs.Compute(); CollectionAssert.AreEqual( new Dictionary <int, int> { [1] = 0, [2] = 2 }, recorder.DiscoverTimes); CollectionAssert.AreEqual( new Dictionary <int, int> { [1] = 1, [2] = 3 }, recorder.FinishTimes); } } { var recorder = new VertexTimeStamperObserver <int>(); var graph = new AdjacencyGraph <int, Edge <int> >(); graph.AddVerticesAndEdgeRange(new[] { new Edge <int>(1, 2), new Edge <int>(2, 2), new Edge <int>(3, 4) }); var dfs = new DepthFirstSearchAlgorithm <int, Edge <int> >(graph); using (recorder.Attach(dfs)) { dfs.Compute(); CollectionAssert.AreEqual( new Dictionary <int, int> { [1] = 0, [2] = 1, [3] = 4, [4] = 5 }, recorder.DiscoverTimes); CollectionAssert.AreEqual( new Dictionary <int, int> { [1] = 3, [2] = 2, [3] = 7, [4] = 6 }, recorder.FinishTimes); } } }