Exemplo n.º 1
0
        public void RePairSwitch()
        {
            AlgPairSwitch algPairSwitch = new AlgPairSwitch();
            StringBuilder message = new StringBuilder();
            message.AppendFormat("[date: {0}]\n", DateTime.Now);
            message.AppendFormat("file: {0}\n", mainForm.ctlTabControl.SelectedTab.Text);
            message.AppendLine("--- Pair Shifts Algorithm: Recalculate ---");

            Stopwatch stopWatch = Stopwatch.StartNew();
            foreach (Area area in Network.Areas)
            {
                if (area.Routers.Count > 0)
                {
                    while (algPairSwitch.Recalculate(area) == false) { }
                }
            }
            stopWatch.Stop();

            foreach (Area area in Network.Areas)
                if (area.Routers.Count > 0)
                {
                    //algPairSwitch.SortRoutersByDistance(area);
                    Network.UpdateGraphics(area);
                    // ********************* DEL
                    //Router root = area.Routers[0];
                    //message.AppendLine("------------------------");
                    //foreach (Router router in area.Routers)
                    //{
                    //    message.AppendLine("Router " + router.Name);
                    //    foreach (Port port in router.Ports)
                    //    {
                    //        message.AppendFormat("{0}: {1} ", port.ShortName, root.Name);
                    //        foreach (Port p in port.Route)
                    //        {
                    //            message.Append(" " + p.Router.Name);
                    //        }
                    //        message.Append(" = " + port.Distance.ToString());
                    //        message.AppendLine();
                    //        message.Append("");
                    //    }
                    //    message.AppendFormat("{0}: {1} ", router.Name, root.Name);
                    //    foreach (Port p in router.MainRoute)
                    //    {
                    //        message.Append(" " + p.Router.Name);
                    //    }
                    //    message.Append(" = " + router.DistancePointer.ToString());
                    //    message.AppendLine();
                    //    message.AppendLine();
                    //}
                    //message.AppendLine("\n------------------------");
                    // ********************* DEL
                }

            Int32 i = 0;
            foreach (ChannelsPair pc in algPairSwitch.Set)
            {
                message.AppendFormat("N{0}\n", ++i);
                message.AppendFormat("R{0}:R{1} switch R{2}:R{3}", pc.Channel1.StartRouter.Number, pc.Channel1.EndRouter.Number,
                                                                   pc.Channel2.StartRouter.Number, pc.Channel2.EndRouter.Number);
                message.AppendLine();
                message.AppendLine();
            }

            message.AppendFormat("time: {0:00.000} ms\n", (stopWatch.ElapsedTicks * 1000.0) / Stopwatch.Frequency);
            UpdateField();
            message.AppendLine("--- End ---");
            message.AppendLine();
            mainForm.ConsoleWrite(message.ToString());
        }
Exemplo n.º 2
0
        public List<Int32> MultiRePairSwitch(Area area, Int32 changesCount, Int32 limit)
        {
            List<int> changesSet = new List<int>();
            AlgPairSwitch algPairSwitch = new AlgPairSwitch();
            StringBuilder message = new StringBuilder();
            message.AppendFormat("[date: {0}]\n", DateTime.Now);
            message.AppendFormat("file: {0}\n", mainForm.ctlTabControl.SelectedTab.Text);
            message.AppendLine("--- Pair Shifts Algorithm: Recalculate ---");

            Stopwatch stopWatch = Stopwatch.StartNew();
            Random rnd = new Random();
            for (int i = 0; i < changesCount; i++)
            {
                area.Channels[rnd.Next(area.Channels.Count - 2)].Criterion = 1 + rnd.Next(limit);
                while (algPairSwitch.Recalculate(area) == false) { }
                changesSet.Add(algPairSwitch.Set.Count);
                algPairSwitch.Set.Clear();
            }
            stopWatch.Stop();

            foreach (Channel channel in area.Channels)
            {
                channel.ChangeCriterion(mainForm.Criterion);
            }

            mainForm.AddPairOperationResult(changesSet, mainForm.ctlTabControl.SelectedTab.Text, area.Number, "Pair Switch", area.Routers.Count);
            message.AppendFormat("time: {0:00.000} ms\n", (stopWatch.ElapsedTicks * 1000.0) / Stopwatch.Frequency);
            UpdateField();
            message.AppendLine("--- End ---");
            message.AppendLine();
            mainForm.ConsoleWrite(message.ToString());

            return changesSet;
        }