Exemplo n.º 1
0
        private void checkLinksTowardsMin(PosetNode <T> node, HashSet <PosetNode <T> > links)
        {
            if (node != null)
            {
                if (FindEqual(node.Elements[0]) == null)
                {
                    throw new InternalErrorException("Not findable!");
                }
                if (findEqualDownwards(node.Elements[0]) == null)
                {
                    throw new InternalErrorException("Not findable!");
                }
                foreach (var l in links)
                {
                    if (!l._largers.Contains(node))
                    {
                        throw new InternalErrorException("Links inconsistent");
                    }
                }
            }

            foreach (var pair in links.UniquePairs())
            {
                if (pair.Item1 == pair.Item2)
                {
                    throw new InternalErrorException("Duplicate link");
                }
            }
            foreach (var l in links)
            {
                checkLinksTowardsMin(l, l._smallers);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds an element to the poset. If available, the element will be added to an existing
        /// equivalence class (node), otherwise a new one will be created, and the DAGs will be
        /// updated as appropriate.
        /// </summary>
        public void Add(T element)
        {
            PosetNode <T> node;

            node = FindEqual(element);
            if (node != null)
            {
                node.AddElement(element);
                return;
            }

            node = new PosetNode <T>(element);
            add(true, node, _minimals, null);
            add(false, node, _maximals, null);
        }
Exemplo n.º 3
0
        private void add(bool upwards, PosetNode <T> toadd, HashSet <PosetNode <T> > links, PosetNode <T> linkfrom)
        {
            bool any = false;
            List <PosetNode <T> > links_add = null;
            List <PosetNode <T> > links_del = null;

            foreach (var linkto in links)
            {
                var partcmp = toadd.PartialCompareTo(linkto);
                if (partcmp == PartialComparisonResult.Equal)
                {
                    any = true;
                    if (!object.ReferenceEquals(linkto, toadd))
                    {
                        throw new InternalErrorException("Equal poset nodes are not the same instance");
                    }
                }
                else if ((upwards && partcmp == PartialComparisonResult.Greater) || (!upwards && partcmp == PartialComparisonResult.Less))
                {
                    any = true;
                    add(upwards, toadd, upwards ? linkto._largers : linkto._smallers, linkto);
                }
                else if ((upwards && partcmp == PartialComparisonResult.Less) || (!upwards && partcmp == PartialComparisonResult.Greater))
                {
                    any = true;
                    if (links_add == null)
                    {
                        links_add = new List <PosetNode <T> >();
                    }
                    links_add.Add(toadd);
                    if (links_del == null)
                    {
                        links_del = new List <PosetNode <T> >();
                    }
                    links_del.Add(linkto);
                    if (linkfrom != null)
                    {
                        (upwards ? toadd._smallers : toadd._largers).Add(linkfrom);
                        (upwards ? linkto._smallers : linkto._largers).Remove(linkfrom);
                    }
                    (upwards ? toadd._largers : toadd._smallers).Add(linkto);
                    (upwards ? linkto._smallers : linkto._largers).Add(toadd);
                }
            }
            if (links_add != null)
            {
                foreach (var link in links_add)
                {
                    links.Add(link);
                }
            }
            if (links_del != null)
            {
                foreach (var link in links_del)
                {
                    links.Remove(link);
                }
            }
            if (!any)
            {
                links.Add(toadd);
                if (linkfrom != null)
                {
                    (upwards ? toadd._smallers : toadd._largers).Add(linkfrom);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Compares this node to the other node, using the partial comparison implemented
 /// by the elements stored in the two nodes.
 /// </summary>
 public PartialComparisonResult PartialCompareTo(PosetNode <T> other)
 {
     return(_elements[0].PartialCompareTo(other._elements[0]));
 }