Class-container for pair of points and their distances.
        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 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 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 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 CloneTwoTest()
 {
     var conn1 = new Connection(2, 3)
                     {
                         Connected = true,
                         Distance = 1,
                         NormalizedDistance = 0.1,
                         Tau = 44,
                         TauStar = 0,
                         Lambda = 5
                     };
     var conn2 = conn1.Clone();
     Assert.AreEqual(conn1.Connected, conn2.Connected);
     Assert.AreEqual(conn1.FirstElementIndex, conn2.FirstElementIndex);
     Assert.AreEqual(conn1.SecondElementIndex, conn2.SecondElementIndex);
     Assert.AreEqual(conn1.Distance, conn2.Distance);
     Assert.AreEqual(conn1.NormalizedDistance, conn2.NormalizedDistance);
     Assert.AreEqual(conn1.Tau, conn2.Tau);
     Assert.AreEqual(conn1.TauStar, conn2.TauStar);
     Assert.AreEqual(conn1.Lambda, conn2.Lambda);
     Assert.IsInstanceOf(typeof(Connection), conn2);
     Assert.AreNotSame(conn1, conn2);
 }
 public void CloneOneTest()
 {
     var conn1 = new Connection(2, 5)
                     {
                         Connected = false,
                         Distance = 6,
                         NormalizedDistance = 0.5,
                         Tau = 3,
                         TauStar = 7,
                         Lambda = 13
                     };
     var conn2 = conn1.Clone();
     Assert.AreEqual(conn1.Connected, conn2.Connected);
     Assert.AreEqual(conn1.FirstElementIndex, conn2.FirstElementIndex);
     Assert.AreEqual(conn1.SecondElementIndex, conn2.SecondElementIndex);
     Assert.AreEqual(conn1.Distance, conn2.Distance);
     Assert.AreEqual(conn1.NormalizedDistance, conn2.NormalizedDistance);
     Assert.AreEqual(conn1.Tau, conn2.Tau);
     Assert.AreEqual(conn1.TauStar, conn2.TauStar);
     Assert.AreEqual(conn1.Lambda, conn2.Lambda);
     Assert.IsInstanceOf(typeof(Connection), conn2);
     Assert.AreNotSame(conn1, conn2);
 }
        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>
        /// Removes given connection between given nodes.
        /// Also renumbers groups emerging as result of disconnection.
        /// </summary>
        /// <param name="connection">
        /// Connected nodes pair.
        /// </param>
        public void Cut(Connection connection)
        {
            if (!connection.Connected)
            {
                return;
            }

            connection.Connected = false;
            Renumber(connection.FirstElementIndex, GetNextTaxonNumber());
        }
 public void ConnectionOneTest()
 {
     var conn1 = new Connection(0, 1);
     Assert.IsFalse(conn1.Connected);
 }
        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);
        }
 /// <summary>
 /// Creates copy of Connection.
 /// </summary>
 /// <returns>
 /// Clone of current object.
 /// </returns>
 public Connection Clone()
 {
     var clone = new Connection(FirstElementIndex, SecondElementIndex)
         {
             Connected = Connected,
             Distance = Distance,
             NormalizedDistance = NormalizedDistance,
             TauStar = TauStar,
             Tau = Tau,
             Lambda = Lambda
         };
     return clone;
 }