/// <summary> /// Computes maximum cost in <see cref="graph"/> using topological sort. /// </summary> /// <param name="graph">Graph from which the maximum cost will be calculated. It needs to be acyclic.</param> /// <returns></returns> public double GetMaximumCost(DiGraph <Operation> graph) { // topologically sort the graph => returns topologically sorted operations var topologicallySortedOperations = new DepthFirstTopSort <Operation>().GetTopSort(graph); return(GetMaximumCost(graph, topologicallySortedOperations)); }
public void Top_Sort_Smoke_Test() { var graph = new DiGraph <char>(); graph.AddVertex('A'); graph.AddVertex('B'); graph.AddVertex('C'); graph.AddVertex('D'); graph.AddVertex('E'); graph.AddVertex('F'); graph.AddVertex('G'); graph.AddVertex('H'); graph.AddEdge('A', 'B'); graph.AddEdge('B', 'C'); graph.AddEdge('C', 'D'); graph.AddEdge('E', 'D'); graph.AddEdge('E', 'F'); graph.AddEdge('F', 'G'); graph.AddEdge('F', 'H'); var algo = new DepthFirstTopSort <char>(); var result = algo.GetTopSort(graph); Assert.AreEqual(result.Count, 8); }
public void DFS_Topological_Sort_AdjancencyListGraph_Smoke_Test() { var graph = new Advanced.Algorithms.DataStructures.Graph.AdjacencyList.DiGraph <char>(); graph.AddVertex('A'); graph.AddVertex('B'); graph.AddVertex('C'); graph.AddVertex('D'); graph.AddVertex('E'); graph.AddVertex('F'); graph.AddVertex('G'); graph.AddVertex('H'); graph.AddEdge('A', 'B'); graph.AddEdge('B', 'C'); graph.AddEdge('C', 'D'); graph.AddEdge('E', 'D'); graph.AddEdge('E', 'F'); graph.AddEdge('F', 'G'); graph.AddEdge('F', 'H'); var algorithm = new DepthFirstTopSort <char>(); var result = algorithm.GetTopSort(graph); Assert.AreEqual(result.Count, 8); }