public void ThreePointsTest()
        {
            var node1 = new GraphElement(new[] { 15.0 }, "node1");
            var node2 = new GraphElement(new[] { 10.0 }, "node2");
            var node3 = new GraphElement(new[] { -3.0 }, "node3");

            var el = new List<GraphElement> { node1, node2, node3 };

            var conn1 = new Connection(0, 1);
            var conn2 = new Connection(0, 2);
            var conn3 = new Connection(1, 2);

            var graph = new List<Connection> { conn1, conn2, conn3 };

            var gm = new GraphManager(graph, el);

            ICalculator calculator = new LinearCalculator();
            calculator.Calculate(gm);
            calculator = new NormalizedLinearCalculator();
            calculator.Calculate(gm);
            calculator = new TauStarCalculator();
            calculator.Calculate(gm);
            calculator = new TauCalculator();
            calculator.Calculate(gm);
            Assert.AreEqual(107, Math.Round(gm.Connections[0].Tau * 1000));
            Assert.AreEqual(722, Math.Round(gm.Connections[2].Tau * 1000));
            Assert.AreEqual(1, gm.Connections[1].Tau);
        }
        public void ThreePoints3DTest()
        {
            var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1");
            var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2");
            var node3 = new GraphElement(new[] { 15.0, 1.0, -25.0 }, "node3");

            var el = new List<GraphElement> { node1, node2, node3 };

            var conn1 = new Connection(0, 1);
            var conn2 = new Connection(0, 2);
            var conn3 = new Connection(1, 2);

            var graph = new List<Connection> { conn1, conn2, conn3 };

            var gm = new GraphManager(graph, el);

            ICalculator calculator = new LinearCalculator();
            calculator.Calculate(gm);
            calculator = new NormalizedLinearCalculator();
            calculator.Calculate(gm);
            calculator = new TauStarCalculator();
            calculator.Calculate(gm);
            calculator = new TauCalculator();
            calculator.Calculate(gm);
            var lambdaCalculator = new LambdaCalculator();
            lambdaCalculator.Calculate(gm, 2, 1);
            Assert.AreEqual(1625, Math.Round(gm.Connections[0].Lambda * 100));
            Assert.AreEqual(9, Math.Round(gm.Connections[1].Lambda * 1000));
            Assert.AreEqual(2612, Math.Round(gm.Connections[2].Lambda * 100));
        }
        public void NodeTest()
        {
            var node = new GraphElement(new[] { 15.0 }, "node");

            Assert.AreEqual(15, node.Content[0]);
            Assert.AreEqual(0, node.TaxonNumber);
        }
 public void CloneTest()
 {
     var node = new GraphElement(new[] { 15.0 }, "node");
     var nodeClone = node.Clone();
     Assert.AreEqual(node.Content, nodeClone.Content);
     Assert.AreEqual(node.Id, nodeClone.Id);
     Assert.AreNotSame(node, nodeClone);
     Assert.IsInstanceOf(typeof(GraphElement), nodeClone);
 }
        public void TwoIntPointsTest()
        {
            var node1 = new GraphElement(new[] { 15.0 }, "node1");
            var node2 = new GraphElement(new[] { 15.0 }, "node2");
            var el = new List<GraphElement> { node1, node2 };

            var conn1 = new Connection(0, 1);
            var con = new List<Connection> { conn1 };

            var gm = new GraphManager(con, el);

            var calculator = new LinearCalculator();
            calculator.Calculate(gm);
            Assert.AreEqual(0, gm.Connections[0].Distance);
        }
        public void NodeTwoTest()
        {
            var node = new GraphElement(new[] { 15.0 }, 1) { TaxonNumber = 5 };

            Assert.AreEqual(15, node.Content[0]);

            node.Content = new[] { -8.0 };

            Assert.AreEqual(-8, node.Content[0]);

            Assert.AreEqual(5, node.TaxonNumber);

            node.TaxonNumber = -5;
            Assert.AreEqual(5, node.TaxonNumber);
        }
        public void ThreePoints3DTest()
        {
            var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1");
            var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2");
            var node3 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node3");

            var el = new List<GraphElement> { node1, node2, node3 };

            var conn1 = new Connection(0, 1);
            var conn2 = new Connection(0, 2);
            var conn3 = new Connection(1, 2);
            var con = new List<Connection> { conn1, conn2, conn3 };

            var gm = new GraphManager(con, el);

            var calculator = new LinearCalculator();
            calculator.Calculate(gm);
            Assert.AreEqual(22293, Math.Round(gm.Connections[0].Distance * 1000));
            Assert.AreEqual(0, Math.Round(gm.Connections[1].Distance * 1000));
            Assert.AreEqual(22293, Math.Round(gm.Connections[2].Distance * 1000));
        }
        public void ThreePointsTest()
        {
            var node1 = new GraphElement(new[] { 15.0 }, "node1");
            var node2 = new GraphElement(new[] { 10.0 }, "node2");
            var node3 = new GraphElement(new[] { -3.0 }, "node3");

            var el = new List<GraphElement> { node1, node2, node3 };

            var conn1 = new Connection(0, 1);
            var conn2 = new Connection(1, 2);
            var conn3 = new Connection(0, 2);

            var con = new List<Connection> { conn1, conn2, conn3 };

            var gm = new GraphManager(con, el);

            var calculator = new LinearCalculator();
            calculator.Calculate(gm);
            Assert.AreEqual(5, gm.Connections[0].Distance);
            Assert.AreEqual(13, gm.Connections[1].Distance);
            Assert.AreEqual(18, gm.Connections[2].Distance);
        }
        public void ThreePoints3DTest()
        {
            var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1");
            var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2");
            var node3 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node3");

            var el = new List<GraphElement> { node1, node2, node3 };

            var conn1 = new Connection(0, 1);
            var conn2 = new Connection(0, 2);
            var conn3 = new Connection(1, 2);

            var graph = new List<Connection> { conn1, conn2, conn3 };

            var gm = new GraphManager(graph, el);

            ICalculator calculator = new LinearCalculator();
            calculator.Calculate(gm);
            calculator = new NormalizedLinearCalculator();
            calculator.Calculate(gm);
            Assert.AreEqual(1, gm.Connections[0].NormalizedDistance);
            Assert.AreEqual(0, gm.Connections[1].NormalizedDistance);
            Assert.AreEqual(1, gm.Connections[2].NormalizedDistance);
        }
        /// <summary>
        /// Searches connection index for pair of nodes.
        /// </summary>
        /// <param name="firstElement">
        /// First node.
        /// </param>
        /// <param name="secondElement">
        /// Second node.
        /// </param>
        /// <returns>
        /// Index of connection in graph as.
        /// </returns>
        public int SearchConnection(GraphElement firstElement, GraphElement secondElement)
        {
            for (int i = 0; i < Connections.Count; i++)
            {
                bool normalOrder = firstElement.Id.Equals(Elements[Connections[i].FirstElementIndex].Id) &&
                                   secondElement.Id.Equals(Elements[Connections[i].SecondElementIndex].Id);

                bool inverseOrder = secondElement.Id.Equals(Elements[Connections[i].FirstElementIndex].Id) &&
                                    firstElement.Id.Equals(Elements[Connections[i].SecondElementIndex].Id);
                if (normalOrder || inverseOrder)
                {
                    return i;
                }
            }

            return -1;
        }
 /// <summary>
 /// Removes connection between given nodes.
 /// Also renumbers groups emerging as result of disconnection.
 /// </summary>
 /// <param name="firstElement">
 /// First node.
 /// </param>
 /// <param name="secondElement">
 /// Second node.
 /// </param>
 public void Cut(GraphElement firstElement, GraphElement secondElement)
 {
     Connection connection = Connections[SearchConnection(firstElement, secondElement)];
     Cut(connection);
 }
        public void TwoPointsTest()
        {
            var node1 = new GraphElement(new[] { 15.0 }, "node1");
            var node2 = new GraphElement(new[] { 20.0 }, "node2");

            var el = new List<GraphElement> { node1, node2 };

            var conn1 = new Connection(0, 1);
            var graph = new List<Connection> { conn1 };

            var gm = new GraphManager(graph, el);

            ICalculator calculator = new LinearCalculator();

            calculator.Calculate(gm);
            calculator = new NormalizedLinearCalculator();
            calculator.Calculate(gm);
            Assert.AreEqual(1, gm.Connections[0].NormalizedDistance);
        }