Exemplo n.º 1
0
        public void RemoveTestTwoChildrenNotRootRightmostIsNotLeft()
        {
            SGTree <int> sgt = new SGTree <int>(0.75);

            SGTNode <int> x = new SGTNode <int>(10);
            SGTNode <int> a = new SGTNode <int>(0);
            SGTNode <int> b = new SGTNode <int>(1);
            SGTNode <int> c = new SGTNode <int>(2);
            SGTNode <int> d = new SGTNode <int>(3);
            SGTNode <int> e = new SGTNode <int>(4);

            sgt.insertFirst(x);
            sgt.insertAfter(x, a);
            sgt.insertAfter(a, e);
            sgt.insertBefore(a, b);
            sgt.insertAfter(b, c);
            sgt.insertBefore(c, d);

            sgt.Remove(a);

            bool b1 = sgt.Query(c, d);
            bool b2 = sgt.Query(c, b);

            Assert.IsTrue(b1 && b2);
        }
Exemplo n.º 2
0
        public HKMSTV1(double alpha)
        {
            _nodeOrder = new SGTree<HKMSTNode>(alpha);
            _nodes = new List<SGTNode<HKMSTNode>>();

            f = new List<SGTNode<HKMSTNode>>();
            b = new List<SGTNode<HKMSTNode>>();
        }
Exemplo n.º 3
0
        public void insertTestBasic()
        {
            SGTree<int> sgt = new SGTree<int>(0.75);
            SGTNode<int> root = sgt.insertFirst(1);
            SGTNode<int> two = sgt.insertAfter(root, 2);

            Assert.IsTrue(sgt.Query(two, root));
        }
Exemplo n.º 4
0
        public void insertTestBasic()
        {
            SGTree <int>  sgt  = new SGTree <int>(0.75);
            SGTNode <int> root = sgt.insertFirst(1);
            SGTNode <int> two  = sgt.insertAfter(root, 2);

            Assert.IsTrue(sgt.Query(two, root));
        }
Exemplo n.º 5
0
        public HKMSTV1(double alpha)
        {
            _nodeOrder = new SGTree <HKMSTNode>(alpha);
            _nodes     = new List <SGTNode <HKMSTNode> >();


            f = new List <SGTNode <HKMSTNode> >();
            b = new List <SGTNode <HKMSTNode> >();
        }
Exemplo n.º 6
0
        public void RemoveTestNoChildrenIsRoot()
        {
            SGTree <int>  sgt = new SGTree <int>(0.75);
            SGTNode <int> a   = new SGTNode <int>(0);

            sgt.insertFirst(a);
            sgt.Remove(a);

            bool b1 = sgt.Root == null;

            Assert.IsTrue(b1);
        }
Exemplo n.º 7
0
        public void RemoveTestTwoChildrenIsRootRightmostIsLeft()
        {
            SGTree <int> sgt = new SGTree <int>(0.75);

            SGTNode <int> b = new SGTNode <int>(1);
            SGTNode <int> c = new SGTNode <int>(2);
            SGTNode <int> d = new SGTNode <int>(3);

            sgt.insertFirst(b);
            sgt.insertBefore(b, c);
            sgt.insertAfter(b, d);

            sgt.Remove(b);

            bool b1 = sgt.Query(d, c);

            Assert.IsTrue(b1);
        }
Exemplo n.º 8
0
        public void RemoveTestNoChildrenNotRoot()
        {
            SGTree <int> sgt = new SGTree <int>(0.75);

            SGTNode <int> a = new SGTNode <int>(0);
            SGTNode <int> b = new SGTNode <int>(1);
            SGTNode <int> c = new SGTNode <int>(2);

            sgt.insertFirst(a);
            sgt.insertBefore(a, b);
            sgt.insertBefore(b, c);

            sgt.Remove(c);

            bool b1 = sgt.Query(a, b);

            Assert.IsTrue(b1);
        }
Exemplo n.º 9
0
        public void RemoveTestRightmostIsLeft()
        {
            var sgt   = new SGTree <int>(0.15);
            var root  = sgt.insertFirst(1);
            var two   = sgt.insertAfter(root, 2);
            var three = sgt.insertAfter(root, 3);
            var four  = sgt.insertAfter(two, 4);

            sgt.insertAfter(root, 5);
            sgt.insertAfter(three, 6);
            sgt.insertAfter(two, 7);
            sgt.insertAfter(four, 8);

            // Test when Remove node has 2 children and the left child rightmost node is the left child
            //   1
            //    \
            //     6
            //    / \
            //   3   4  <--- Remove
            //  /   / \
            // 5   7   8
            //    /
            //   2
            //
            // should result in
            //   1
            //    \
            //     6
            //    / \
            //   3   7
            //  /   / \
            // 5   2   8
            //

            sgt.Remove(four);
            bool a = root.Value == 1;
            bool b = root.Right.Value == 6;
            bool c = root.Right.Left.Value == 3 && root.Right.Left.Left.Value == 5;
            bool d = root.Right.Right.Value == 7 && root.Right.Right.Left.Value == 2 && root.Right.Right.Right.Value == 8;


            Assert.IsTrue(a && b && c && d);
        }
Exemplo n.º 10
0
        public void insertBeforeTest()
        {
            // a < root
            // b < a
            // a < c
            // d < a && d < b

            SGTree<int> sgt = new SGTree<int>(0.75);
            SGTNode<int> root = sgt.insertFirst(1);
            SGTNode<int> a = sgt.insertBefore(root, 2);
            SGTNode<int> b = sgt.insertBefore(a, 3);
            SGTNode<int> c = sgt.insertBefore(root, 4);
            SGTNode<int> d = sgt.insertBefore(b, 5);

            bool aGTroot = sgt.Query(root, a);
            bool bGTa = sgt.Query(a, b);
            bool aGTc = sgt.Query(c, a);
            bool dGTa = sgt.Query(a, d);
            bool dGTb = sgt.Query(b, d);

            Assert.IsTrue(aGTroot && bGTa && aGTc && dGTa && dGTb);
        }
Exemplo n.º 11
0
        public void RemoveTestLeftChildIsRoot()
        {
            SGTree<int> sgt = new SGTree<int>(0.75);

            SGTNode<int> a = new SGTNode<int>(0);
            SGTNode<int> b = new SGTNode<int>(1);
            SGTNode<int> c = new SGTNode<int>(2);
            SGTNode<int> d = new SGTNode<int>(3);

            sgt.insertFirst(a);
            sgt.insertBefore(a, b);
            sgt.insertBefore(b, c);
            sgt.insertBefore(c, d);

            sgt.Remove(a);

            bool b1 = sgt.Query(c, d);
            bool b2 = sgt.Query(b, c);
            bool b3 = sgt.Query(b, d);

            Assert.IsTrue(b1 && b2 && b3);
        }
Exemplo n.º 12
0
        public void insertTestNotSequential()
        {
            // root > a
            // a > b
            // c > a
            // a > d && b > d

            SGTree<int> sgt = new SGTree<int>(0.75);
            SGTNode<int> root = sgt.insertFirst(1);
            SGTNode<int> a = sgt.insertAfter(root, 2);
            SGTNode<int> b = sgt.insertAfter(a, 3);
            SGTNode<int> c = sgt.insertAfter(root, 4);
            SGTNode<int> d = sgt.insertAfter(b, 5);

            bool aGTroot = sgt.Query(a, root);
            bool bGTa = sgt.Query(b, a);
            bool aGTc = sgt.Query(a, c);
            bool dGTa = sgt.Query(d, a);
            bool dGTb = sgt.Query(d, b);

            Assert.IsTrue(aGTroot && bGTa && aGTc && dGTa && dGTb);
        }
Exemplo n.º 13
0
        public void RemoveTestLeftChildIsRoot()
        {
            SGTree <int> sgt = new SGTree <int>(0.75);

            SGTNode <int> a = new SGTNode <int>(0);
            SGTNode <int> b = new SGTNode <int>(1);
            SGTNode <int> c = new SGTNode <int>(2);
            SGTNode <int> d = new SGTNode <int>(3);

            sgt.insertFirst(a);
            sgt.insertBefore(a, b);
            sgt.insertBefore(b, c);
            sgt.insertBefore(c, d);

            sgt.Remove(a);

            bool b1 = sgt.Query(c, d);
            bool b2 = sgt.Query(b, c);
            bool b3 = sgt.Query(b, d);

            Assert.IsTrue(b1 && b2 && b3);
        }
Exemplo n.º 14
0
        public void insertTestNotSequential()
        {
            // root > a
            // a > b
            // c > a
            // a > d && b > d

            SGTree <int>  sgt  = new SGTree <int>(0.75);
            SGTNode <int> root = sgt.insertFirst(1);
            SGTNode <int> a    = sgt.insertAfter(root, 2);
            SGTNode <int> b    = sgt.insertAfter(a, 3);
            SGTNode <int> c    = sgt.insertAfter(root, 4);
            SGTNode <int> d    = sgt.insertAfter(b, 5);

            bool aGTroot = sgt.Query(a, root);
            bool bGTa    = sgt.Query(b, a);
            bool aGTc    = sgt.Query(a, c);
            bool dGTa    = sgt.Query(d, a);
            bool dGTb    = sgt.Query(d, b);

            Assert.IsTrue(aGTroot && bGTa && aGTc && dGTa && dGTb);
        }
Exemplo n.º 15
0
        public void RemoveTestTwoChildrenNotRootRighstmostIsLeft()
        {
            SGTree <int> sgt = new SGTree <int>(0.75);

            SGTNode <int> a = new SGTNode <int>(0);
            SGTNode <int> b = new SGTNode <int>(1);
            SGTNode <int> c = new SGTNode <int>(2);
            SGTNode <int> d = new SGTNode <int>(3);

            sgt.insertFirst(a);
            sgt.insertBefore(a, b);
            sgt.insertBefore(b, c);
            sgt.insertAfter(b, d);

            sgt.Remove(b);

            bool b1 = sgt.Query(a, c);
            bool b2 = sgt.Query(a, d);
            bool b3 = sgt.Query(d, c);

            Assert.IsTrue(b1 && b2 && b3);
        }
Exemplo n.º 16
0
        public void insertBeforeTest()
        {
            // a < root
            // b < a
            // a < c
            // d < a && d < b

            SGTree <int>  sgt  = new SGTree <int>(0.75);
            SGTNode <int> root = sgt.insertFirst(1);
            SGTNode <int> a    = sgt.insertBefore(root, 2);
            SGTNode <int> b    = sgt.insertBefore(a, 3);
            SGTNode <int> c    = sgt.insertBefore(root, 4);
            SGTNode <int> d    = sgt.insertBefore(b, 5);

            bool aGTroot = sgt.Query(root, a);
            bool bGTa    = sgt.Query(a, b);
            bool aGTc    = sgt.Query(c, a);
            bool dGTa    = sgt.Query(a, d);
            bool dGTb    = sgt.Query(b, d);

            Assert.IsTrue(aGTroot && bGTa && aGTc && dGTa && dGTb);
        }
Exemplo n.º 17
0
        public void RemoveTestTwoChildrenNotRootRightmostIsNotLeft()
        {
            SGTree<int> sgt = new SGTree<int>(0.75);

            SGTNode<int> x = new SGTNode<int>(10);
            SGTNode<int> a = new SGTNode<int>(0);
            SGTNode<int> b = new SGTNode<int>(1);
            SGTNode<int> c = new SGTNode<int>(2);
            SGTNode<int> d = new SGTNode<int>(3);
            SGTNode<int> e = new SGTNode<int>(4);

            sgt.insertFirst(x);
            sgt.insertAfter(x, a);
            sgt.insertAfter(a, e);
            sgt.insertBefore(a, b);
            sgt.insertAfter(b, c);
            sgt.insertBefore(c, d);

            sgt.Remove(a);

            bool b1 = sgt.Query(c, d);
            bool b2 = sgt.Query(c, b);

            Assert.IsTrue(b1 && b2);
        }
Exemplo n.º 18
0
        public void RemoveTestTwoChildrenNotRootRighstmostIsLeft()
        {
            SGTree<int> sgt = new SGTree<int>(0.75);

            SGTNode<int> a = new SGTNode<int>(0);
            SGTNode<int> b = new SGTNode<int>(1);
            SGTNode<int> c = new SGTNode<int>(2);
            SGTNode<int> d = new SGTNode<int>(3);

            sgt.insertFirst(a);
            sgt.insertBefore(a, b);
            sgt.insertBefore(b, c);
            sgt.insertAfter(b, d);

            sgt.Remove(b);

            bool b1 = sgt.Query(a, c);
            bool b2 = sgt.Query(a, d);
            bool b3 = sgt.Query(d, c);

            Assert.IsTrue(b1 && b2 && b3);
        }
Exemplo n.º 19
0
        public void RemoveTestTwoChildrenIsRootRightmostIsLeft()
        {
            SGTree<int> sgt = new SGTree<int>(0.75);

            SGTNode<int> b = new SGTNode<int>(1);
            SGTNode<int> c = new SGTNode<int>(2);
            SGTNode<int> d = new SGTNode<int>(3);

            sgt.insertFirst(b);
            sgt.insertBefore(b, c);
            sgt.insertAfter(b, d);

            sgt.Remove(b);

            bool b1 = sgt.Query(d, c);

            Assert.IsTrue(b1);
        }
Exemplo n.º 20
0
        public void RemoveTestRightmostIsLeft()
        {
            var sgt = new SGTree<int>(0.15);
            var root = sgt.insertFirst(1);
            var two = sgt.insertAfter(root, 2);
            var three = sgt.insertAfter(root, 3);
            var four = sgt.insertAfter(two, 4);
            sgt.insertAfter(root, 5);
            sgt.insertAfter(three, 6);
            sgt.insertAfter(two, 7);
            sgt.insertAfter(four, 8);

            // Test when Remove node has 2 children and the left child rightmost node is the left child
            //   1
            //    \
            //     6
            //    / \
            //   3   4  <--- Remove
            //  /   / \
            // 5   7   8
            //    /
            //   2
            //
            // should result in
            //   1
            //    \
            //     6
            //    / \
            //   3   7
            //  /   / \
            // 5   2   8
            //

            sgt.Remove(four);
            bool a = root.Value == 1;
            bool b = root.Right.Value == 6;
            bool c = root.Right.Left.Value == 3 && root.Right.Left.Left.Value == 5;
            bool d = root.Right.Right.Value == 7 && root.Right.Right.Left.Value == 2 && root.Right.Right.Right.Value == 8;

            Assert.IsTrue(a && b && c && d);
        }
Exemplo n.º 21
0
 public HKMSTFinal(double alpha, SPickMethod spick)
 {
     _nodeOrder = new SGTree<HKMSTNodeFinal>(alpha);
     _nodes = new List<SGTNode<HKMSTNodeFinal>>();
     _sPickMethod = spick;
 }
Exemplo n.º 22
0
        // Compares the edges topological order
        private void TopologyCompare(IEnumerable<IStaticGraph> staticGraphs, IEnumerable<IDynamicGraph> dynamicGraphs)
        {
            Console.WriteLine("Starting topology comparer");
            // Find connected pairs to compare
            var connectivity = new ConnectivityGraph();

            for (var i = 0; i < _n; i++)
            {
                connectivity.AddVertex();
            }

            foreach (var edge in _edges)
            {
                connectivity.AddEdge(edge.Item1, edge.Item2);
            }

            // matrix of node connectivity
            Console.WriteLine("Generating connectivity matrix");
            var matrix = connectivity.GenerateConnectivityMatrix();
            var topologies = new List<Tuple<string, SGTree<int>, List<SGTNode<int>>>>();
            Console.WriteLine("Connectivity matrix completed");

            foreach (var algorithm in staticGraphs)
            {
                var sgt = new SGTree<int>(0.75);
                var top = algorithm.TopoSort();
                var items = new List<SGTNode<int>>();

                var prev = sgt.insertFirst(top[0]);
                items.Add(prev);
                for (var i = 1; i < top.Length; i++)
                {
                    prev = sgt.insertAfter(prev, top[i]);
                    items.Add(prev);
                }

                items.Sort(Comparer<SGTNode<int>>.Create((i, j) => i.Value.CompareTo(j.Value)));
                topologies.Add(new Tuple<string, SGTree<int>, List<SGTNode<int>>>
                    (algorithm.GetType().ToString(), sgt, items));
            }

            foreach (var algorithm in dynamicGraphs)
            {
                var sgt = new SGTree<int>(0.75);
                var top = algorithm.Topology();
                var items = new List<SGTNode<int>>();

                var prev = sgt.insertFirst(top[0]);
                items.Add(prev);
                for (var i = 1; i < top.Count; i++)
                {
                    prev = sgt.insertAfter(prev, top[i]);
                    items.Add(prev);
                }

                items.Sort(Comparer<SGTNode<int>>.Create((i, j) => i.Value.CompareTo(j.Value)));
                topologies.Add(new Tuple<string, SGTree<int>, List<SGTNode<int>>>(algorithm.GetType().ToString(), sgt,
                    items));
            }

            Console.Write("Performing topology compare");
            for (var i = 0; i < matrix.Count; i++)
            {
                for (var j = 0; j < matrix.Count; j++)
                {
                    if (matrix[i][j])
                    {
                        foreach (var algorithm in topologies)
                        {
                            //if(!algorithm.Item2.query(algorithm.Item3[i], algorithm.Item3[j]))
                            if (!algorithm.Item2.Query(algorithm.Item3[j], algorithm.Item3[i]))
                            {
                                WriteFile("TopoCompFail");
                                throw new Exception("Topological comparison failed for: " + algorithm.Item1);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        private int _nCount;//debug

        public HKMSTFinal(double alpha, SPickMethod spick)
        {
            _nodeOrder   = new SGTree <HKMSTNodeFinal>(alpha);
            _nodes       = new List <SGTNode <HKMSTNodeFinal> >();
            _sPickMethod = spick;
        }
Exemplo n.º 24
0
        public void RemoveTestNoChildrenIsRoot()
        {
            SGTree<int> sgt = new SGTree<int>(0.75);
            SGTNode<int> a = new SGTNode<int>(0);

            sgt.insertFirst(a);
            sgt.Remove(a);

            bool b1 = sgt.Root == null;

            Assert.IsTrue(b1);
        }
Exemplo n.º 25
0
        // Compares the edges topological order
        private void TopologyCompare(IEnumerable <IStaticGraph> staticGraphs, IEnumerable <IDynamicGraph> dynamicGraphs)
        {
            Console.WriteLine("Starting topology comparer");
            // Find connected pairs to compare
            var connectivity = new ConnectivityGraph();

            for (var i = 0; i < _n; i++)
            {
                connectivity.AddVertex();
            }

            foreach (var edge in _edges)
            {
                connectivity.AddEdge(edge.Item1, edge.Item2);
            }

            // matrix of node connectivity
            Console.WriteLine("Generating connectivity matrix");
            var matrix     = connectivity.GenerateConnectivityMatrix();
            var topologies = new List <Tuple <string, SGTree <int>, List <SGTNode <int> > > >();

            Console.WriteLine("Connectivity matrix completed");

            foreach (var algorithm in staticGraphs)
            {
                var sgt   = new SGTree <int>(0.75);
                var top   = algorithm.TopoSort();
                var items = new List <SGTNode <int> >();

                var prev = sgt.insertFirst(top[0]);
                items.Add(prev);
                for (var i = 1; i < top.Length; i++)
                {
                    prev = sgt.insertAfter(prev, top[i]);
                    items.Add(prev);
                }

                items.Sort(Comparer <SGTNode <int> > .Create((i, j) => i.Value.CompareTo(j.Value)));
                topologies.Add(new Tuple <string, SGTree <int>, List <SGTNode <int> > >
                                   (algorithm.GetType().ToString(), sgt, items));
            }

            foreach (var algorithm in dynamicGraphs)
            {
                var sgt   = new SGTree <int>(0.75);
                var top   = algorithm.Topology();
                var items = new List <SGTNode <int> >();

                var prev = sgt.insertFirst(top[0]);
                items.Add(prev);
                for (var i = 1; i < top.Count; i++)
                {
                    prev = sgt.insertAfter(prev, top[i]);
                    items.Add(prev);
                }

                items.Sort(Comparer <SGTNode <int> > .Create((i, j) => i.Value.CompareTo(j.Value)));
                topologies.Add(new Tuple <string, SGTree <int>, List <SGTNode <int> > >(algorithm.GetType().ToString(), sgt,
                                                                                        items));
            }

            Console.Write("Performing topology compare");
            for (var i = 0; i < matrix.Count; i++)
            {
                for (var j = 0; j < matrix.Count; j++)
                {
                    if (matrix[i][j])
                    {
                        foreach (var algorithm in topologies)
                        {
                            //if(!algorithm.Item2.query(algorithm.Item3[i], algorithm.Item3[j]))
                            if (!algorithm.Item2.Query(algorithm.Item3[j], algorithm.Item3[i]))
                            {
                                WriteFile("TopoCompFail");
                                throw new Exception("Topological comparison failed for: " + algorithm.Item1);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
        public void RemoveTestNoChildrenNotRoot()
        {
            SGTree<int> sgt = new SGTree<int>(0.75);

            SGTNode<int> a = new SGTNode<int>(0);
            SGTNode<int> b = new SGTNode<int>(1);
            SGTNode<int> c = new SGTNode<int>(2);

            sgt.insertFirst(a);
            sgt.insertBefore(a, b);
            sgt.insertBefore(b, c);

            sgt.Remove(c);

            bool b1 = sgt.Query(a, b);

            Assert.IsTrue(b1);
        }