Exemple #1
0
        // Need Retrieval the Whole Graph!        --------TODO: Improve?   NEED TESTED
        /// <summary>
        /// Delete a node from graph
        /// </summary>
        /// <param name="node">The node to be deleted</param>
        /// <returns></returns>
        public bool Delete(GraphNode node)
        {
            //Delete from NodeTable
            Hashtable table = AddrSet.AddrGraph.NodeTable;
            TableNode tnodelist = table[node.Name] as TableNode;

            //find the relevant node in NodeList
            TableNode tnode = tnodelist;
            while (tnode.Next != null)
            {
                if (tnode.GNode.ID == node.ID)
                {
                    break;
                }
                tnode = tnode.Next;
            }
            if (tnode.GNode.ID != node.ID)
            {
                //Not found in NodeList
                return false;
            }

            if (tnode.Prev == null)          // this node is head
            {
                tnode.Next.Prev = null;
                table.Remove(node.Name);
                table.Add(node.Name,tnode.Next);
            }
            else if(tnode.Next == null)   //this node is tail
            {
                tnode.Prev.Next = null;
            }
            else
            {
                tnode.Prev.Next = tnode.Next;
                tnode.Next.Prev = tnode.Prev;
            }

            //Delete from Graph
            List<GraphNode> gnodelist = RetrievalGraph(delegate(GraphNode p)
            {
                if (p.NextNodeList.Contains(node))
                {
                    return true;
                }
                else
                {
                    return false;
                }

            });

            foreach (GraphNode resultnode in gnodelist)
            {
                resultnode.NextNodeList.Remove(node);
                AddrGraph.NodeCount--;
            }

            return true;
        }
Exemple #2
0
 public TableNode(GraphNode gnode)
 {
     _gNode = gnode;
     _next = null;
     _prev = null;
     _name = gnode.Name;
 }
Exemple #3
0
 private bool defualtRule(State state, GraphNode nextNode)
 {
     if (nextNode.NodeLEVEL == LEVEL.Uncertainty || state.MinStateLEVEL == LEVEL.Uncertainty)
     {
         return true;
     }
     if (nextNode.NodeLEVEL > state.MinStateLEVEL)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemple #4
0
 private void MultiMatchInNext(Predicate<GraphNode> p, GraphNode node, ref List<GraphNode> result)
 {
     if (p(node) && !result.Contains(node))
     {
         result.Add(node);
     }
     if (node.NextNodeList == null || node.NextNodeList.Count == 0)
     {
         return;
     }
     foreach (GraphNode nxt_node in node.NextNodeList)
     {
         MultiMatchInNext(p, nxt_node, ref result);
     }
 }
Exemple #5
0
        /// <summary>
        /// Rename a node in graph
        /// </summary>
        /// <param name="node">The node to be renamed</param>
        /// <param name="name">new name</param>
        /// <returns></returns>
        public bool ReName(GraphNode node, string name)
        {
            List<GraphNode> gnodelist = FindGNodeListInHashTable(node.Name);
            foreach (GraphNode gnode in gnodelist)
            {
                if (gnode.ID == node.ID)
                {
                    gnode.Name = name;
                }
            }

            return true;
        }
Exemple #6
0
        /// <summary>
        /// Insert a node into graph
        /// </summary>
        /// <param name="NewNode">The node to be inserted</param>
        /// <param name="FatherNode">The node's father node</param>
        /// <returns></returns>
        public bool Insert(GraphNode NewNode,GraphNode FatherNode)
        {
            if (NewNode == null || FatherNode ==null || FatherNode.NextNodeList == null)
            {
                return false;
            }
            if (NewNode.NodeLEVEL <= FatherNode.NodeLEVEL && NewNode.NodeLEVEL != LEVEL.Uncertainty)
            {
                return false;
            }

            TableNode tnode = new TableNode(NewNode);
            Hashtable table = AddrSet.AddrGraph.NodeTable;

            //Add to NodeTable
            if (table.Contains(tnode.Name))
            {
                AppendTableNodeList((TableNode)table[tnode.Name], tnode);
            }
            else
            {
                table.Add(tnode.Name, tnode);
            }

            //Linked to Graph
            FatherNode.NextNodeList.Add(NewNode);

            AddrGraph.NodeCount++;

            return true;
        }
Exemple #7
0
        /// <summary>
        /// Search matched node with single source node through specific delegate, from up to bottom.
        /// </summary>
        /// <param name="p">find matched node in condition supported predicate delegate</param>
        /// <param name="sourceNode"></param>
        /// <returns>collections of result</returns>
        public List<GraphNode> ForwardSearchNode(Predicate<GraphNode> p, GraphNode sourceNode)
        {
            List<GraphNode> result = new List<GraphNode>();

            MultiMatchInNext(p, sourceNode, ref result);

            return result;
        }