コード例 #1
0
        public void CaculateNonWeightMinDistanceToEachVertex(NonWeightVertex origin)
        {
            float INFINITY = float.MaxValue;

            for (int i = 0; i < m_vertices.Count; ++i)
            {
                m_vertices[i].m_min_dist = INFINITY;
            }
            origin.m_min_dist = 0;

            Queue <NonWeightVertex> queue = new Queue <NonWeightVertex>();

            queue.Enqueue(origin);

            NonWeightVertex vert = null;

            while (queue.Count > 0)
            {
                vert = queue.Dequeue();
                for (int i = 0; i < vert.m_neighbours.Count; ++i)
                {
                    if (vert.m_neighbours[i].m_min_dist == INFINITY)
                    {
                        vert.m_neighbours[i].m_min_dist = vert.m_min_dist + 1;
                        queue.Enqueue(vert.m_neighbours[i]);
                        vert.m_neighbours[i].m_path_vertex = vert;
                    }
                }
            }
        }
コード例 #2
0
        public void Test()
        {
            NonWeightVertex v1 = new NonWeightVertex(1);
            NonWeightVertex v2 = new NonWeightVertex(2);
            NonWeightVertex v3 = new NonWeightVertex(3);
            NonWeightVertex v4 = new NonWeightVertex(4);
            NonWeightVertex v5 = new NonWeightVertex(5);
            NonWeightVertex v6 = new NonWeightVertex(6);
            NonWeightVertex v7 = new NonWeightVertex(7);

            v1.m_neighbours.Add(v4);
            v1.m_neighbours.Add(v2);

            v2.m_neighbours.Add(v4);
            v2.m_neighbours.Add(v5);

            v3.m_neighbours.Add(v1);
            v3.m_neighbours.Add(v6);

            v4.m_neighbours.Add(v5);
            v4.m_neighbours.Add(v6);
            v4.m_neighbours.Add(v7);

            v5.m_neighbours.Add(v7);

            v7.m_neighbours.Add(v6);

            m_vertices.Add(v1);
            m_vertices.Add(v2);
            m_vertices.Add(v3);
            m_vertices.Add(v4);
            m_vertices.Add(v5);
            m_vertices.Add(v6);
            m_vertices.Add(v7);
            CaculateNonWeightMinDistanceToEachVertex(v3);
        }