Ejemplo n.º 1
0
        public void ContractNodeWithCover(HasseNode Node)
        {
            // Node should have exactly one cover.
            // Edges from covered are moved to go to the cover = (break and form)
            // Finally Node is deleted


            HasseEdge[] EdgesDownToCovered = Node.EdgesToCovered.ToArray();
            HasseNode   TopNode            = Node.EdgesToCovering[0].UpperNode;

            System.Diagnostics.Debug.WriteLine("ContractNodeWithCover: " + Node.KeyString);
            System.Diagnostics.Debug.WriteLine("Covered by: " + TopNode.KeyString);

            foreach (HasseEdge EdgeToCovered in EdgesDownToCovered)
            {
                System.Diagnostics.Debug.WriteLine("Moving edge from : " + EdgeToCovered.LowerNode.KeyString);
                MakeEdgeIfNotExists(EdgeToCovered.LowerNode, TopNode);
                RemoveEdge(EdgeToCovered);
            }
            HasseDiagramNodes.Remove(Node.KeyString);
        }
Ejemplo n.º 2
0
        public static HasseNodeCollection FindLub(HasseNode ReferenceNode, HasseNodeCollection AllNodes)
        {
            bool dbg = Convert.ToBoolean(DEBUGLEVEL & LOG_DEBUG_MAKE_LUB);
            HasseNodeCollection lub = new HasseNodeCollection();
            //List<string> ToBeRemoved = new List<string>();
            HashSet <string> ToBeRemoved = new HashSet <string>();

            foreach (HasseNode Node in AllNodes.Values)
            {
                if (!ToBeRemoved.Contains(Node.KeyString))
                {
                    System.Diagnostics.Debug.WriteLineIf(dbg, "test if " + Node.KeyString + " is larger than " + ReferenceNode.KeyString);


                    // debug:
                    //HasseNode[] subobj = ReferenceNode.getElementarySubobjects().Values.ToArray();
                    //if (!Node.HasElements(subobj) &&
                    //    (Node.IsLargerThan(ReferenceNode)))
                    //{
                    //    System.Diagnostics.Debugger.Break();
                    //}


                    if (Node.IsLargerThan(ReferenceNode))
                    {
                        System.Diagnostics.Debug.WriteLineIf(dbg, " yes - is lub candidate, delete above...");
                        lub.Add(Node.KeyString, Node);
                        FindNodesAbove(Node, ToBeRemoved, 0);
                    }

                    /*
                     * else if (ReferenceNode.IsLargerThan(Node))
                     * {
                     *  DeleteNodesBelow(Node, ToBeRemoved, 0);
                     * }
                     */
                    else
                    {
                        ToBeRemoved.Add(Node.KeyString);
                    }
                }
            }

            foreach (string key in ToBeRemoved)
            {
                lub.Remove(key);
            }

            return(lub);
        }
Ejemplo n.º 3
0
        public static HasseNodeCollection BruteForceFindGlb(HasseNode @ref, HasseNodeCollection AllNodes)
        {
            if (@ref.KeyString.Equals("x"))
            {
                System.Diagnostics.Debugger.Break();
            }

            HasseNodeCollection glb         = new HasseNodeCollection();
            List <string>       ToBeRemoved = new List <string>();

            foreach (HasseNode Node in AllNodes.Values)
            {
                if (@ref.IsLargerThan(Node))
                {
                    glb.Add(Node.KeyString, Node);
                }
            }


            foreach (HasseNode Node in glb.Values)
            {
                foreach (HasseNode Node2 in glb.Values)
                {
                    if (Node != Node2)
                    {
                        if (Node.IsLargerThan(Node2))
                        {
                            ToBeRemoved.Add(Node2.KeyString);
                        }
                        //           break;
                    }
                }
            }
            foreach (string key in ToBeRemoved)
            {
                glb.Remove(key);
            }

            return(glb);
        }
Ejemplo n.º 4
0
        private void RemoveEdge(HasseEdge E)
        {
            //disconnect upper node
            E.UpperNode.EdgesToCovered.Remove(E);
            E.UpperNode = null;

            // disconnect lower node
            E.LowerNode.EdgesToCovering.Remove(E);
            E.LowerNode = null;


            // --------- deal with linked node(s) ------------------------------------------
            HasseNode[] LinkedNodes = E.LinkedNodes.ToArray(); // make copy to avoid changed collection error
            foreach (HasseNode LinkedNode in LinkedNodes)
            {
                // remove reference to this (E) from the linked node
                LinkedNode.linkedEdges.Remove(E);

                if (LinkedNode.linkedEdges.Count == 0) // possibly remove node completely..
                {
                    // ... if not MCS
                    if (false == Convert.ToBoolean(LinkedNode.NodeType &
                                                   HasseNode.HasseNodeTypes.MAX_COMMON_FRAGMENT))
                    {
                        // ... and not non-fragment
                        if (false == Convert.ToBoolean(LinkedNode.NodeType &
                                                       HasseNode.HasseNodeTypes.REAL))
                        {
                            // Remove node from list catalog of difference nodes
                            DifferenceNodes.Remove(LinkedNode.KeyString);
                            // Remove reference from this edge to linked node
                            E.LinkedNodes.Remove(LinkedNode); // disconnect to linked node

                            // by now E should point to nothing and nothing point to E
                        }
                    }
                }
            }// -----------------    loop until dealt with linked nodes --------------------
            E.Removed = true; // For debugging
        }
Ejemplo n.º 5
0
        public static HasseNodeCollection FindGlb(HasseNode ReferenceNode, HasseNodeCollection AllNodes)
        {
            bool dbg = Convert.ToBoolean(DEBUGLEVEL & LOG_DEBUG_MAKE_GLB);
            HasseNodeCollection glb = new HasseNodeCollection();
            //List<string> ToBeRemoved = new List<string>();
            HashSet <string> ToBeRemoved = new HashSet <string>();

            foreach (HasseNode Node in AllNodes.Values)
            {
                if (!ToBeRemoved.Contains(Node.KeyString))
                {
                    System.Diagnostics.Debug.WriteLineIf(dbg, "test if " + ReferenceNode.KeyString + " is larger than " + Node.KeyString);
                    if (ReferenceNode.IsLargerThan(Node))
                    {
                        System.Diagnostics.Debug.WriteLineIf(dbg, " yes - is glb candidate, delete below...");
                        glb.Add(Node.KeyString, Node);
                        FindNodesBelow(Node, ToBeRemoved, 0);
                    }

                    /*   else if (Node.IsLargerThan(ReferenceNode))
                     * {
                     *     DeleteNodesAbove(Node, ToBeRemoved, 0);
                     * }
                     */
                    else
                    {
                        ToBeRemoved.Add(Node.KeyString);
                    }
                }
            }

            foreach (string key in ToBeRemoved)
            {
                glb.Remove(key);
            }

            return(glb);
        }
Ejemplo n.º 6
0
        public static HasseNodeCollection BruteForceFindLub(HasseNode @ref, HasseNodeCollection AllNodes)
        {
#if DEBUG
            // if (@ref.UniqueString.Equals("*B*")) {
            //    System.Diagnostics.Debugger.Break();
            // }
#endif

            HasseNodeCollection lub         = new HasseNodeCollection();
            List <string>       ToBeRemoved = new List <string>();
            foreach (HasseNode Node in AllNodes.Values)
            {
                if (Node.IsLargerThan(@ref))
                {
                    lub.Add(Node.KeyString, Node);
                }
            }

            foreach (HasseNode Node in lub.Values)
            {
                foreach (HasseNode Node2 in lub.Values)
                {
                    if (Node2.IsLargerThan(Node))
                    {
                        ToBeRemoved.Add(Node2.KeyString);
                        //break;
                    }
                }
            }
            foreach (string key in ToBeRemoved)
            {
                lub.Remove(key);
            }

            return(lub);
        }