Exemplo n.º 1
0
        //内嵌于step3 需要递归
        //注意array2初始值为-1 表示未计算
        private int CalculateFlowAccumulationFromPoint(int i, int j)
        {
            if (array2[i, j] == -1)
            {
                int count = array1[i, j].GetPointCounts();
                if (count == 0)
                {
                    array2[i, j] = 0;//没有人指向我 流量为0
                }
                else//有指向的人
                {
                    array2[i, j] = count;
                    //遍历每一个指向我的人
                    for (int k = 0; k < count; k++)
                    {
                        Point point = array1[i, j].GetOnePoint(k);
                        if (array2[point.GetI(), point.GetJ()] == -1)//指向我的人 尚未计算
                        {
                            //递归计算该值
                            array2[point.GetI(), point.GetJ()] = CalculateFlowAccumulationFromPoint(point.GetI(), point.GetJ());//计算指向我的人
                            array2[i, j] += array2[point.GetI(), point.GetJ()];
                        }
                        else
                        {
                            array2[i, j] += array2[point.GetI(), point.GetJ()];//指向我的人已经计算
                        }
                    }
                }
            }

            return(array2[i, j]);
        }