示例#1
0
        /// <summary>
        /// Add Node to Graphs
        /// </summary>
        /// <param name="node"></param>
        /// <returns>Return Index of Node. If fail to add node, return -1</returns>
        public int AddNode(MyGraphNode node)
        {
            if (node.getIndex() == 0)
            {
                node.setIndex(index: GetNextFreeNodeIndex());
            }

            if (!isPresent(node.getIndex()))
            {
                m_Nodes.Add(node);
            }
            return(node.getIndex());
        }
示例#2
0
        /// <summary>
        /// Add Node to Graphs
        /// </summary>
        /// <param name="node"></param>
        /// <returns>Return Index of Node. If fail to add node, return -1</returns>
        public int AddNode(MyGraphNode node)
        {
            if (node.getIndex() == 0)
                node.setIndex(index: GetNextFreeNodeIndex());

            if (!isPresent(node.getIndex()))
            {
                m_Nodes.Add(node);
            }
            return node.getIndex();
        }
示例#3
0
 protected void Visit(MyGraphNode node, ref int lable)
 {
     node.SetLable(lable);
     if (m_DListNode.ContainsKey(node.getIndex()))
     {
         for (int i = 0; i < m_DListNode[node.getIndex()].Count; i++)
         {
             int from = node.getIndex();
             int to   = m_DListNode[from][i].GetTo();
             if (m_Nodes[to].GetLable() == 0)
             {
                 Visit(m_Nodes[to], ref lable);
             }
             else
             {
                 //  UpdateLable(lable, m_Nodes[to].GetLable());
                 lable = m_Nodes[to].GetLable();
             }
         }
     }
 }
示例#4
0
        /// <summary>
        /// Add Node to Graphs
        /// </summary>
        /// <param name="node"></param>
        /// <returns>Return Index of Node. If fail to add node, return -1</returns>
        public int AddNode(MyGraphNode node)
        {
            node.setIndex(index: GetNextFreeNodeIndex());
            m_iNextNodeIndex += 1;

            if (true)
            {
                m_Nodes.Add(node);
                return node.getIndex();
            }
            else
            {
                return -1;
            }
        }
示例#5
0
        /// <summary>
        /// Add Node to Graphs
        /// </summary>
        /// <param name="node"></param>
        /// <returns>Return Index of Node. If fail to add node, return -1</returns>
        public int AddNode(MyGraphNode node)
        {
            node.setIndex(index: GetNextFreeNodeIndex());
            m_iNextNodeIndex += 1;

            if (true)
            {
                m_Nodes.Add(node);
                return(node.getIndex());
            }
            else
            {
                return(-1);
            }
        }
示例#6
0
        /// <summary>
        /// Tìm cây khung có trọng số nhỏ nhất
        /// </summary>
        /// <returns></returns>
        public MyListGraph PrimAlgo(MyGraphNode startNode)
        {
            MyListGraph result = new MyListGraph(this.m_bDigraph);

            List <int>         p_fNodes = new List <int>();
            List <MyGraphEdge> p_fEdges = new List <MyGraphEdge>();


            p_fNodes.Add(startNode.getIndex());

            while (p_fEdges.Count < this.m_Nodes.Count)
            {
                MyGraphEdge edge = PrimFindEdge(p_fNodes, p_fEdges);
                if (edge != null)
                {
                    p_fNodes.Add(edge.GetTo());
                    p_fEdges.Add(edge);
                }
                else
                {
                    // Đồ thị không liên thông
                    break;
                }
            }

            for (int i = 0; i < p_fNodes.Count; i++)
            {
                result.AddNode(new MyGraphNode(p_fNodes[i]));
            }
            for (int i = 0; i < p_fEdges.Count; i++)
            {
                result.AddEdge(p_fEdges[i]);
            }

            return(result);
        }
示例#7
0
 protected void Visit(MyGraphNode node, ref int lable)
 {
     node.SetLable(lable);
     if (m_DListNode.ContainsKey(node.getIndex()))
     {
         for (int i = 0; i < m_DListNode[node.getIndex()].Count; i++)
         {
             int from = node.getIndex();
             int to = m_DListNode[from][i].GetTo();
             if (m_Nodes[to].GetLable() == 0)
             {
                 Visit(m_Nodes[to], ref lable);
             }
             else
             {
                 //  UpdateLable(lable, m_Nodes[to].GetLable());
                 lable = m_Nodes[to].GetLable();
             }
         }
     }
 }
示例#8
0
        /// <summary>
        /// Tìm cây khung có trọng số nhỏ nhất
        /// </summary>
        /// <returns></returns>
        public MyListGraph PrimAlgo(MyGraphNode startNode)
        {
            MyListGraph result = new MyListGraph(this.m_bDigraph);

            List<int> p_fNodes = new List<int>();
            List<MyGraphEdge> p_fEdges = new List<MyGraphEdge>();

            p_fNodes.Add(startNode.getIndex());

            while (p_fEdges.Count < this.m_Nodes.Count)
            {
                MyGraphEdge edge = PrimFindEdge(p_fNodes, p_fEdges);
                if (edge != null)
                {
                    p_fNodes.Add(edge.GetTo());
                    p_fEdges.Add(edge);
                }
                else
                {
                    // Đồ thị không liên thông
                    break;
                }
            }

            for (int i = 0; i < p_fNodes.Count; i++)
            {
                result.AddNode(new MyGraphNode(p_fNodes[i]));
            }
            for (int i = 0; i < p_fEdges.Count; i++)
            {
                result.AddEdge(p_fEdges[i]);
            }

            return result;
        }