private static void AssertMinimumSpanningTree <TVertex, TEdge>( [NotNull] IUndirectedGraph <TVertex, TEdge> graph, [NotNull] IMinimumSpanningTreeAlgorithm <TVertex, TEdge> algorithm) where TEdge : IEdge <TVertex> { var edgeRecorder = new EdgeRecorderObserver <TVertex, TEdge>(); using (edgeRecorder.Attach(algorithm)) algorithm.Compute(); AssertSpanningTree(graph, edgeRecorder.Edges); }
private static void AssertMinimumSpanningTree<TVertex, TEdge>( IUndirectedGraph<TVertex, TEdge> g, IMinimumSpanningTreeAlgorithm<TVertex, TEdge> algorithm) where TEdge : IEdge<TVertex> { var edgeRecorder = new EdgeRecorderObserver<TVertex, TEdge>(); using (edgeRecorder.Attach(algorithm)) algorithm.Compute(); TestConsole.WriteLine("tree cost: {0}", edgeRecorder.Edges.Count); AssertSpanningTree<TVertex, TEdge>(g, edgeRecorder.Edges); }
/// <summary> /// Collect edges /// ToDo Change To Prim.Compute() or Kruskal.Compute() look at AssertMinimumSpanningTree<TVertex, TEdge>(g, prim, ref resultEdges); /// </summary> /// <typeparam name="TVertex"></typeparam> /// <typeparam name="TEdge"></typeparam> /// <param name="g"></param> /// <param name="algorithm"></param> /// <param name="resultEdges"></param> private static void AssertMinimumSpanningTree <TVertex, TEdge>(IUndirectedGraph <TVertex, TEdge> g, IMinimumSpanningTreeAlgorithm <TVertex, TEdge> algorithm, ref int[][] resultEdges) where TEdge : IEdge <TVertex> { EdgeRecorderObserver <TVertex, TEdge> edgeRecorder = new EdgeRecorderObserver <TVertex, TEdge>(); using (edgeRecorder.Attach(algorithm)) algorithm.Compute(); resultEdges = new int[edgeRecorder.Edges.Count][]; for (int i = 0; i < edgeRecorder.Edges.Count; i++) { resultEdges[i] = new int[] { Convert.ToInt32(edgeRecorder.Edges[i].Source), Convert.ToInt32(edgeRecorder.Edges[i].Target) } } ; } }