Exemple #1
0
        // Returns a list of partitions represented by SetPartition<T>
        // An old reference to the set is hold by SetPartition<T>::Difference
        // An intersection is given by SetPartition<T>::Intersection which can
        // be invalidaded with further actions on the instance of ProductRefinement
        public List <SetPartition <T> > Refine(ICollection <T> elements)
        {
            var changedNodes = new List <LinkedListNode <SetPartition <T> > > ();

            foreach (var el in elements)
            {
                pointers [el].ToSet.Value.CloseIntersection();
            }

            foreach (var el in elements)
            {
                var p = pointers [el];
                if (!p.ToSet.Value.HasIntersection())
                {
                    p.ToSet.Value.InitIntersection();
                    changedNodes.Add(p.ToSet);
                }
                var newIt = p.ToSet.Value.Intersect(p.ToIterator);
                p.ToIterator = newIt;
            }

            foreach (var partNode in changedNodes)
            {
                if (!partNode.Value.Difference.Any())
                {
                    foreach (T el in partNode.Value.Intersection)
                    {
                        var backIt = partNode.Value.Difference.AddLast(el);
                        pointers[el].ToIterator = backIt;
                    }
                    partNode.Value.Intersection.Clear();
                    continue;
                }

                var intersectionPart = new SetPartition <T> (partNode.Value.Intersection);
                var node             = partition.AddLast(intersectionPart);

                foreach (T el in partNode.Value.Intersection)
                {
                    pointers [el].ToSet = node;
                }
            }

            var changes = new List <SetPartition <T> > ();

            foreach (var node in changedNodes)
            {
                if (node.Value.Intersection.Any())
                {
                    changes.Add(node.Value);
                }
            }

            return(changes);
        }
Exemple #2
0
        // list of sets depicting initial partition
        public PartitionRefinement(IList <LinkedList <T> > sets)
        {
            foreach (var elements in sets)
            {
                var newSet = new SetPartition <T> (elements);
                var node   = partition.AddLast(newSet);

                var iterator = elements.First;
                while (iterator != null)
                {
                    pointers [iterator.Value] = new Pointer(node, iterator);
                    iterator = iterator.Next;
                }
            }
        }