Exemplo n.º 1
0
        static void Main()
        {
            InformationLoader informationLoader = new InformationLoader();
            List <Entity>     entities          = informationLoader.LoadEntities(@"C:\Users\pomino\Source\Repos\MAVNetTest\MAVNetTest\MAVNetTest\EntityInformation.xml");

            Thread[] threads = new Thread[entities.Count];
            CompletedFlags.Initialization(entities.Count);
            Map.Initialization(entities);
            AddressBook.Initialization(entities.ToArray());

            for (var i = 0; i < entities.Count; i++)
            {
                threads[i] = new Thread(entities[i].SimStart);
            }

            foreach (var thread in threads)
            {
                thread.Start();
            }

            while (!CompletedFlags.IsAllCompleted())
            {
                Thread.Sleep(1000);
            }

            //计算延迟和显示跳数
            foreach (var entity in entities)
            {
                if (entity.TypeReader == (int)AddressBook.EntityType.Station)
                {
                    var entity1 = (Station)entity;
                    entity1.CalculateDelayAndShowTheHop();
                }
            }

            //计算抵达的比率
            int sumOfSend    = 0;
            int sumOfReceive = 0;

            foreach (var entity in entities)
            {
                if (entity.TypeReader == (int)AddressBook.EntityType.Station)
                {
                    Station entity1 = (Station)entity;
                    sumOfReceive = entity1.AmountOfReceive;
                }
                else if (entity.TypeReader == (int)AddressBook.EntityType.Ferrying || entity.TypeReader == (int)AddressBook.EntityType.Searching)
                {
                    SearchingMav entity1 = (SearchingMav)entity;
                    sumOfSend += entity1.AmountOfSent;
                }
            }

            Console.WriteLine("The Deliver Ratio is {0}", (double)sumOfReceive / sumOfSend);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 用于开始模拟
        /// Used for starting simulation
        /// </summary>
        public override void SimStart()
        {
            base.SimStart();

            IPEndPoint ipe = AddressBook.SearchIpEndPoint(Type, Id);

            UdpClient = new UdpClient(ipe);

            UdpReceiver();

            while (!_completed)
            {
                Thread.Sleep(1000);
            }

            CompletedFlags.Completed();
        }