Exemplo n.º 1
0
        public void UsingPathFinderOnSameNetworkManyTimesAddingNewNodeToNetwork_GivesRightResult()
        {
            //ARRANGE
            Network    dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut   = new PathFinder(dummy);

            //Original quickest path
            sut.FindQuickestPath("A", "J");
            Assert.AreEqual(18d, sut.QuickestPathResults["J"].QuickestTimeFromStart);

            //ACT, Adding new node and connection
            dummy.AddNode("K");
            dummy.AddConnection("K", "A", 1);
            dummy.AddConnection("K", "J", 1);
            sut.FindQuickestPath("K", "J");

            //ASSERT
            Assert.AreEqual(1d, sut.QuickestPathResults["J"].QuickestTimeFromStart);
            sut.FindQuickestPath("A", "J");
            Assert.AreEqual(2d, sut.QuickestPathResults["J"].QuickestTimeFromStart);

            Assert.AreEqual("A", sut.QuickestPathResults["J"].NodesVisited[0]);
            Assert.AreEqual("K", sut.QuickestPathResults["J"].NodesVisited[1]);
            Assert.AreEqual("J", sut.QuickestPathResults["J"].NodesVisited[2]);
        }
Exemplo n.º 2
0
        public void AddConnection_AtLeastOneNodeDoesNotExist_ReturnsArgumentException()
        {
            Network network = new Network();

            network.Nodes.Add("Exists", new Node("Exists"));
            Assert.Throws <ArgumentException>(() => network.AddConnection("Exists", "DoesNotExist", 6));
        }
Exemplo n.º 3
0
        public void AddConnection_ActuallyAddsConnection()
        {
            Network network = new Network();

            network.Nodes.Add("First", new Node("First"));
            network.Nodes.Add("Second", new Node("Second"));
            network.Nodes.Add("Third", new Node("Third"));
            network.AddConnection(network.Nodes["First"].Name, network.Nodes["Second"].Name, 5);
            Assert.IsTrue(network.Nodes["First"].Connections.Count == 1 && network.Nodes["First"].Connections.Count == 1 &&
                          network.Nodes["Third"].Connections.Count == 0);
        }
    private void StartModel(T fnData, T snData)
    {
        int fId = m_storedNetwork.AddNode(fnData);
        int sId = m_storedNetwork.AddNode(snData);

        //hardcode first & second node degree to 1
        m_storedNetwork.GetNodeByID(fId).degree = 1;
        m_storedNetwork.GetNodeByID(sId).degree = 1;
        m_storedNetwork.AddConnection(fId, sId);
        if (m_currentModel == NetworkModel.Barabasi_Albert)
        {
            m_storedNetwork.AddConnection(fId, sId);
        }
        else if (m_currentModel == NetworkModel.ER)
        {
            if (UnityEngine.Random.value < DEFAULT_ER_LINK_PROBABILITY)
            {
                m_storedNetwork.AddConnection(fId, sId);
            }
        }
    }
Exemplo n.º 5
0
        public void ChangingConnectionValuesExampleOne_UpdatesQuickestPathCorrectly()
        {
            //ARRANGE
            Network    dummy = DummyCreator.CreateDummyNetworkOfTenNodesWithConnectionsOption1();
            PathFinder sut   = new PathFinder(dummy);

            //Original quickest path
            sut.FindQuickestPath("A", "J");
            Assert.AreEqual(18d, sut.QuickestPathResults["J"].QuickestTimeFromStart);

            //ACT, Changing quickest path by adding direct connection
            dummy.AddConnection("A", "J", 1);
            sut.FindQuickestPath("A", "J");

            //ASSERT that new quickest path has changed
            Assert.AreEqual(1d, sut.QuickestPathResults["J"].QuickestTimeFromStart);
        }
Exemplo n.º 6
0
        public void CompareTo_QueueSortsInReverse_ReturnsCorrectOrder()
        {
            Network network = new Network();

            network.Nodes.Add("A", new Node("A"));
            network.Nodes.Add("B", new Node("B"));
            network.Nodes.Add("C", new Node("C"));
            network.Nodes.Add("D", new Node("D"));
            network.Nodes.Add("E", new Node("E"));
            network.Nodes.Add("F", new Node("F"));
            network.Nodes.Add("G", new Node("G"));
            network.Nodes.Add("H", new Node("H"));
            network.Nodes.Add("I", new Node("I"));
            network.Nodes.Add("J", new Node("J"));


            network.AddConnection("A", "B", 3);
            network.AddConnection("A", "C", 3);
            network.AddConnection("A", "D", 3);
            network.AddConnection("B", "D", 3);
            network.AddConnection("C", "D", 3);
            network.AddConnection("E", "F", 3);
            network.AddConnection("F", "G", 3);

            PriorityQueue <Node> list = new PriorityQueue <Node>(true);

            foreach (var element in network.Nodes)
            {
                list.Add(element.Value);
            }

            int listCount     = list.Count();
            int highestNumber = 100;

            for (int j = 0; j < listCount; j++)
            {
                int currentValue = list.Pop().Connections.Count;
                if (currentValue > highestNumber)
                {
                    Assert.Fail($"Failed at iteration {j}. Value was {currentValue} and the lowest was {highestNumber}");
                }
                else
                {
                    highestNumber = currentValue;
                    Debug.WriteLine(currentValue);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a new connection. Adds the connection to the Network and to the NetworkViewController.
        /// </summary>
        /// <param name="Start">The start node of the connection</param>
        /// <param name="StartNodeInterfaceName">The name of the Interface at which the Connection is pluged in at the start node</param>
        /// <param name="End">The end node of the connection</param>
        /// <param name="EndNodeInterfaceName">The name of the Interface at which the Connection is pluged in at the end node</param>
        public void CreateConnection(string Start, string StartNodeInterfaceName, string End, string EndNodeInterfaceName)
        {
            Hardwarenode a = GetHardwarenodeByName(Start);
            Hardwarenode b = GetHardwarenodeByName(End);

            if (a == null || b == null)
            {
                Debug.Assert(false, "Hardwarenode could not be found");
                return;
            }
            if (a == b)
            {
                return;
            }

            Connection connection = new Connection(a, b);

            if (network.AddConnection(StartNodeInterfaceName, EndNodeInterfaceName, connection))
            {
                NetworkViewController.Instance.AddConnection(connection);
            }
        }
Exemplo n.º 8
0
        internal static Network CreateDummyNetworkOfTenNodesWithConnectionsOption2()
        {
            Network stockholm = new Network();

            stockholm.AddNode("A");
            stockholm.AddNode("B");
            stockholm.AddNode("C");
            stockholm.AddNode("D");
            stockholm.AddNode("E");
            stockholm.AddNode("F");
            stockholm.AddNode("G");
            stockholm.AddNode("H");
            stockholm.AddNode("I");
            stockholm.AddNode("J");

            stockholm.AddConnection("A", "B", 10);
            stockholm.AddConnection("A", "C", 2);
            stockholm.AddConnection("C", "B", 8);
            stockholm.AddConnection("B", "J", 5);
            stockholm.AddConnection("J", "D", 7);
            stockholm.AddConnection("D", "I", 2);
            stockholm.AddConnection("I", "H", 1);
            stockholm.AddConnection("H", "F", 9);
            stockholm.AddConnection("H", "G", 2);
            stockholm.AddConnection("F", "E", 4);
            stockholm.AddConnection("F", "C", 30);
            stockholm.AddConnection("E", "G", 8);



            return(stockholm);
        }
Exemplo n.º 9
0
        internal static Network CreateDummyNetworkOfTenNodesWithConnectionsOption1()
        {
            Network karlstad = new Network();

            karlstad.AddNode("A");
            karlstad.AddNode("B");
            karlstad.AddNode("C");
            karlstad.AddNode("D");
            karlstad.AddNode("E");
            karlstad.AddNode("F");
            karlstad.AddNode("G");
            karlstad.AddNode("H");
            karlstad.AddNode("I");
            karlstad.AddNode("J");

            karlstad.AddConnection("A", "B", 10);
            karlstad.AddConnection("A", "C", 2);
            karlstad.AddConnection("B", "C", 22);
            karlstad.AddConnection("B", "D", 22);
            karlstad.AddConnection("D", "E", 4);
            karlstad.AddConnection("E", "F", 3);
            karlstad.AddConnection("F", "C", 1);
            karlstad.AddConnection("D", "J", 8);
            karlstad.AddConnection("I", "J", 1);
            karlstad.AddConnection("I", "H", 3);
            karlstad.AddConnection("G", "H", 10);
            karlstad.AddConnection("G", "E", 1);

            return(karlstad);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Network stockholm = new Network();

            stockholm.AddNode("A");
            stockholm.AddNode("B");
            stockholm.AddNode("C");
            stockholm.AddNode("D");
            stockholm.AddNode("E");
            stockholm.AddNode("F");
            stockholm.AddNode("G");
            stockholm.AddNode("H");
            stockholm.AddNode("I");
            stockholm.AddNode("J");

            stockholm.AddConnection("A", "B", 10);
            stockholm.AddConnection("A", "C", 2);
            stockholm.AddConnection("C", "B", 8);
            stockholm.AddConnection("B", "J", 5);
            stockholm.AddConnection("J", "D", 7);
            stockholm.AddConnection("D", "I", 2);
            stockholm.AddConnection("I", "H", 1);
            stockholm.AddConnection("H", "F", 9);
            stockholm.AddConnection("H", "G", 2);
            stockholm.AddConnection("F", "E", 4);
            stockholm.AddConnection("F", "C", 30);
            stockholm.AddConnection("E", "G", 8);

            PathFinder p = new PathFinder(stockholm);

            Console.WriteLine(p.FindQuickestPath("A", "J", false));
        }