コード例 #1
0
ファイル: MyListGraph.cs プロジェクト: hieuntp2/MyGraph
        /// <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
ファイル: MyListGraph.cs プロジェクト: hieuntp2/MyGraph
        /// <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
ファイル: MySparseGraph.cs プロジェクト: hieuntp2/MyGraph
        /// <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;
            }
        }
コード例 #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
ファイル: MyListGraph.cs プロジェクト: hieuntp2/MyGraph
 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();
             }
         }
     }
 }
コード例 #6
0
ファイル: MyListGraph.cs プロジェクト: hieuntp2/MyGraph
        /// <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
ファイル: MyListGraph.cs プロジェクト: hieuntp2/MyGraph
 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
ファイル: MyListGraph.cs プロジェクト: hieuntp2/MyGraph
        /// <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;
        }