Exemple #1
0
 public bool ReplaceNode(Node replacement, Node toBeReplaced)
 {
     if (nodeMap.ContainsKey(replacement.Guid))
     {
         foreach (Node dad in toBeReplaced.GetParents())
         {
             //rem.RemoveEdgeTo(child);
             dad.ReplaceChild(toBeReplaced, replacement);
         }
         nodeList.Remove(toBeReplaced);
         nodeMap[replacement.Guid] = replacement;
         nodeList.Add(replacement);
         return(true);
     }
     return(false);
 }
Exemple #2
0
 /// <summary>
 /// Remove all edges from or to the node passed as parameter.
 /// </summary>
 /// <param name="rem"></param>
 /// <returns></returns>
 public bool RemoveAllEdges(Node rem)
 {
     if (nodeMap.ContainsKey(rem.Guid))
     {
         IEnumerable iter = rem.GetChildren();
         foreach (Node child in iter)
         {
             rem.RemoveChild(child);
             child.RemoveParent(rem);
         }
         iter = rem.GetParents();
         foreach (Node dad in iter)
         {
             rem.RemoveChild(dad);
             dad.RemoveChild(rem);
         }
         return(true);
     }
     return(false);
 }
Exemple #3
0
        /// <summary>
        /// Removes the node passed as parameter from the graph(represented using NodeMap)
        /// </summary>
        /// <param name="rem"></param>
        /// <returns></returns>
        public bool RemoveNode(Node rem)
        {
            if (nodeMap.ContainsKey(rem.Guid))
            {
                IEnumerable iter = rem.GetChildren();
                foreach (Node child in iter)
                {
                    child.RemoveParent(rem);
                }
                iter = rem.GetParents();
                foreach (Node dad in iter)
                {
                    dad.RemoveChild(rem);
                }

                nodeMap.Remove(rem.Guid);
                nodeList.Remove(rem);
                return(true);
            }
            return(false);
        }
Exemple #4
0
 public bool ReplaceNode(Node replacement,Node toBeReplaced)
 {
     if (nodeMap.ContainsKey(replacement.Guid))
     {
         
         foreach (Node dad in toBeReplaced.GetParents())
         {
             //rem.RemoveEdgeTo(child); 
             dad.ReplaceChild(toBeReplaced,replacement);
         }
         nodeList.Remove(toBeReplaced);
         nodeMap[replacement.Guid]=replacement;
         nodeList.Add(replacement);
         return true;
     }
     return false;
 }
Exemple #5
0
        /// <summary>
        /// Removes the node passed as parameter from the graph(represented using NodeMap)
        /// </summary>
        /// <param name="rem"></param>
        /// <returns></returns>
        public bool RemoveNode(Node rem)
        {
            if (nodeMap.ContainsKey(rem.Guid))
            {
                IEnumerable iter = rem.GetChildren();
                foreach (Node child in iter)
                {
                    child.RemoveParent(rem);
                }
                iter = rem.GetParents();
                foreach (Node dad in iter)
                {
                    dad.RemoveChild(rem);
                }

                nodeMap.Remove(rem.Guid); 
                nodeList.Remove(rem); 
                return true;
            }
            return false;
        }
Exemple #6
0
 /// <summary>
 /// Remove all edges from or to the node passed as parameter.
 /// </summary>
 /// <param name="rem"></param>
 /// <returns></returns>
 public bool RemoveAllEdges(Node rem)
 {
     if (nodeMap.ContainsKey(rem.Guid))
     {
         IEnumerable iter = rem.GetChildren();
         foreach (Node child in iter)
         {
             rem.RemoveChild(child); 
             child.RemoveParent(rem);
         }
         iter = rem.GetParents();
         foreach (Node dad in iter)
         {
             rem.RemoveChild(dad); 
             dad.RemoveChild(rem);
         }
         return true;
     }
     return false;
 }
Exemple #7
0
        private List<Node> DFS(Node node, AST graph, List<Node> input)
        {
            List<Node> result = new List<Node>();
            //foreach (Node neighborNode in node.GetParents())
            for (int i=0; i<node.GetParents().Count; i++)
            {
                Node neighborNode = node.GetParents()[i];
                KeyValuePair<int, Node> item = neighborNode.children.FirstOrDefault(x => x.Value == node);
                {
                    neighborNode.children.Remove(item.Key);
                    //item.Value.GetParents().Remove(neighborNode);
                    item.Value.GetParents().RemoveAll(x => x == neighborNode);
                    result.AddRange(DFS(neighborNode, graph, input));
                    item.Value.GetParents().Add(neighborNode);
                    neighborNode.children.Add(item.Key, item.Value);
                }
            }
            //foreach (KeyValuePair<int, Node> neighborNode in node.children)
            for (int i=0; i<node.children.Count; i++)
            {
                KeyValuePair<int, Node> neighborNode = node.children.ElementAt(i);
                neighborNode.Value.GetParents().Remove(neighborNode.Value);
                List<Node> parentNodeList = new List<Node>(neighborNode.Value.GetParents());
                foreach (Node parentNode in parentNodeList)
                {
                    parentNode.RemoveChild(neighborNode.Value);
                }
                result.AddRange(DFS(neighborNode.Value, graph, input));
                foreach (Node parentNode in parentNodeList)
                {
                    parentNode.children.Add(neighborNode.Key, neighborNode.Value);
                }
                neighborNode.Value.GetParents().Add(neighborNode.Value);

            }
            result.Add(node);
            return result;
        }
Exemple #8
0
 private List<Node> BFS(Node node, AST graph, List<Node> input)
 {
     List<uint> UIDlist = this.nodesToGuid(input);
     List<Node> result = new List<Node>();
     Queue<Node> mainQ = new Queue<Node>();
     mainQ.Enqueue(node);
     result.Add(node);
     foreach (Node parentNode in node.GetParents())
     {
         if (UIDlist.Contains(parentNode.Guid))
         {
             mainQ.Enqueue(parentNode);
             if (!result.Contains(parentNode))
             {
                 result.Add(parentNode);
             }
             input.Remove(parentNode);
         }
     }
     foreach (KeyValuePair<int, Node> childPair in node.children)
     {
         if (UIDlist.Contains(childPair.Value.Guid))
         {
             mainQ.Enqueue(childPair.Value);
             if (!result.Contains(childPair.Value))
             {
                 result.Add(childPair.Value);
             }
             input.Remove(childPair.Value);
         }                
     }
     while (mainQ.Count != 0)
     {
         Node topNode = mainQ.Dequeue();
         foreach (Node parentNode in topNode.GetParents())
         {
             if (!result.Contains(parentNode) && UIDlist.Contains(parentNode.Guid))
             {
                 mainQ.Enqueue(parentNode);
                 if (UIDlist.Contains(parentNode.Guid))
                 {
                     result.Add(parentNode);
                     input.Remove(parentNode);
                 }
             }
         }
         foreach (KeyValuePair<int, Node> sonNodePair in topNode.children)
         {
             if (!result.Contains(sonNodePair.Value) && UIDlist.Contains(sonNodePair.Value.Guid))
             {
                 mainQ.Enqueue(sonNodePair.Value);
                 if (UIDlist.Contains(sonNodePair.Value.Guid))
                 {
                     result.Add(sonNodePair.Value);
                     input.Remove(sonNodePair.Value);
                 }
             }
         }
     }
     return result;
 }
Exemple #9
0
 private List<Node> DFS_Parent(Node node, AST graph, List<Node> input)
 {
     List<Node> result = new List<Node>();
     if (input.Count == 0)
         return result;
     //if (input.Contains(node))
     if (nodesToGuid(input).Contains(node.Guid))
         result.Add(node);
     foreach (Node parentNode in node.GetParents())
         result.AddRange(DFS_Parent(parentNode, graph, input));
     return result;
 }