/// <summary>
    /// 有向无回路图中的单源最短路径算法
    /// </summary>
    public class DAG_Shortest_Paths
    {
        /// <summary>
        /// 有向无回路图中的单源最短路径
        /// </summary>
        /// <param name="g">有向无回路图</param>
        /// <param name="s">源点s</param>
        public void DAGShortestPaths(Graphic g, Node s)
        {
            GraphicSearchAlg theGS = new GraphicSearchAlg();
            //获取拓扑排序
            var theNodes = theGS.TopoLogicalSort(g);
            SingleSourcePath theSSP = new SingleSourcePath();
            //初始化图
            theSSP.InitializeGraphic(g, s);
            foreach (Node theNode in theNodes)
            {
                foreach (var theAdjNode in theNode.AdjNodes)
                {
                    //利用松弛技术.
                    theSSP.Relax(theAdjNode.Value);
                }
            }
        }
    }

在图的算法中,邻接表表示确实可以改善时间复杂度,但邻接矩阵表示却有利于规模计算。两者如何选择,需根据实际情况来选择,后面的最大流等算法中,可以两者结合来发挥各自的优势。

相关文章:

  • 2022-01-04
  • 2021-05-04
  • 2021-08-24
  • 2021-11-14
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-03-31
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2021-06-11
相关资源
相似解决方案