Exemplo n.º 1
0
        public void SizeTest()
        {
            Partition p = new Partition();

            p.AddCell(0, 1);
            p.AddCell(2, 3);
            Assert.AreEqual(2, p.Count);
            Assert.AreEqual(2, p.GetCell(0).Count);
            Assert.AreEqual(2, p.GetCell(1).Count);
        }
Exemplo n.º 2
0
        public void OrderTest()
        {
            Partition p = new Partition(new int[][] { new[] { 1, 3 }, new[] { 0, 2 } });

            p.Order();
            SortedSet <int> cell0 = p.GetCell(0);
            SortedSet <int> cell1 = p.GetCell(1);

            Assert.IsTrue(cell0.First() < cell1.First());
            Assert.IsTrue(cell0.Last() < cell1.Last());
        }
Exemplo n.º 3
0
        public void UnitStaticConstructor()
        {
            int       size = 5;
            Partition p    = Partition.Unit(size);

            Assert.AreEqual(1, p.Count);
            Assert.AreEqual(size, p.GetCell(0).Count);
        }
Exemplo n.º 4
0
        public void CopyBlockTest()
        {
            int[][]         cellData  = new int[][] { new[] { 0 }, new[] { 1 }, new[] { 2 } };
            Partition       p         = new Partition(cellData);
            int             cellIndex = 1;
            SortedSet <int> copyCell  = p.CopyBlock(cellIndex);
            SortedSet <int> refCell   = p.GetCell(cellIndex);

            Assert.IsTrue(copyCell != refCell);
        }
Exemplo n.º 5
0
        public void SplitAfterTest()
        {
            int[][]   cellData     = new int[][] { new[] { 0, 1 }, new[] { 2, 3, 4 }, new[] { 5, 6 } };
            Partition p            = new Partition(cellData);
            int       cellIndex    = 1;
            int       splitElement = 3;
            Partition q            = p.SplitAfter(cellIndex, splitElement);

            Assert.AreEqual(p.NumberOfElements(), q.NumberOfElements());
            Assert.AreEqual(p.Count + 1, q.Count);
            SortedSet <int> cell = q.GetCell(cellIndex + 1);

            Assert.IsTrue(cell.Count == 1);
            Assert.AreEqual(splitElement, (int)cell.First());
        }
Exemplo n.º 6
0
        public void GetCellTest()
        {
            int[][]   cellData = new int[][] { new[] { 0, 1 }, new[] { 2, 3, 4 }, new[] { 5, 6 } };
            Partition p        = new Partition(cellData);

            for (int i = 0; i < cellData.Length; i++)
            {
                int[] cell = p.GetCell(i).ToArray();
                Assert.AreEqual(cellData[i].Length, cell.Length);
                for (int j = 0; j < cell.Length; j++)
                {
                    Assert.AreEqual(cellData[i][j], (int)cell[j]);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the neighbor invariants for the block j as a map of
        /// |N<sub>g</sub>(v) ∩ T| to elements of the block j. That is, the
        /// size of the intersection between the set of neighbors of element v in
        /// the graph and the target block T.
        /// </summary>
        /// <param name="partition">the current partition</param>
        /// <param name="targetBlock">the current target block of the partition</param>
        /// <returns>a map of set intersection invariants to elements</returns>
        private Dictionary <IInvariant, SortedSet <int> > GetInvariants(Partition partition, SortedSet <int> targetBlock)
        {
            var setList = new Dictionary <IInvariant, SortedSet <int> >();

            foreach (int u in partition.GetCell(currentBlockIndex))
            {
                var h = refinable.NeighboursInBlock(targetBlock, u);
                if (setList.ContainsKey(h))
                {
                    setList[h].Add(u);
                }
                else
                {
                    var set = new SortedSet <int>
                    {
                        u
                    };
                    setList[h] = set;
                }
            }
            return(setList);
        }