Exemple #1
0
        public List<Int32> MultiRePairShift(Area area, int changesCount, int limit)
        {
            List<int> changesSet = new List<int>();
            AlgPairShift algPairShift = new AlgPairShift();
            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 - 1)].Criterion = 1 + rnd.Next(limit);
                algPairShift.Recalculate(area);
                changesSet.Add(algPairShift.Set.Count);
                algPairShift.Set.Clear();
            }
            stopWatch.Stop();

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

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

            return changesSet;
        }
Exemple #2
0
        public void RePairShift()
        {
            AlgPairShift algPairShift = new AlgPairShift();
            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 (algPairShift.Recalculate(area) == false) { }
                }
            }
            stopWatch.Stop();

            foreach (Area area in Network.Areas)
            {
                if (area.Routers.Count > 0)
                {
                    Network.UpdateGraphics(area);
                    // ********************* DEL
                    Router root = area.Routers[0];
                    foreach (Router r in area.Routers)
                        if (r.DistancePointer == 0)
                            root = r;

                    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
                }
            }

            int i = 0;
            foreach (PairRoutes pr in algPairShift.Set)
            {
                message.AppendFormat("shift_{0}\n", ++i);
                message.AppendFormat("R{0}-", pr.Route1[0].Owner.Number);
                foreach (Port port in pr.Route1)
                {
                    message.AppendFormat("R{0}", port.Router.Number);
                    if (pr.Route1.IndexOf(port) != pr.Route1.Count - 1)
                    {
                        message.Append("-");
                    }
                }
                message.Append("\n     ");
                message.AppendFormat("R{0}-", pr.Route2[0].Owner.Number);
                foreach (Port port in pr.Route2)
                {
                    message.AppendFormat("R{0}", port.Router.Number);
                    if (pr.Route2.IndexOf(port) != pr.Route2.Count - 1)
                    {
                        message.Append("-");
                    }
                }
                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());
        }
Exemple #3
0
        public void DoAlgPairShift()
        {
            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 ---");
            if (Network.CheckNetwork() == 0)
            {
                message.AppendLine("checking: graph checking ... OK");
                if (Network.Areas.Count > 1)
                {
                    message.AppendLine("checking: network is segmented ... YES");
                }
                else
                {
                    message.AppendLine("checking: network is segmented ... NO");
                }

                AlgDejkstra algDejkstra = new AlgDejkstra();
                AlgPairShift algPairShift = new AlgPairShift();
                foreach (Area area in Network.Areas)
                {
                    if (area.Routers.Count > 0)
                    {
                        Router root = area.Routers[0];
                        foreach (Router router in SelectedElements)
                        {
                            if (area.Routers.Contains(router) == true)
                            {
                                root = router;
                                break;
                            }
                        }
                        Network.ResetEquipment(area);
                        algDejkstra.DoAlg(root);
                        algPairShift.DoAlg(area);
                        Network.UpdateGraphics(area);
                        // ********************* DEL
                        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
                    }
                }
            }
            else
            {
                message.Append("warning: gaph is not closed!\n" +
                        "execution is stopped.\n");
            }

            UpdateField();
            message.AppendLine("--- End ---");
            message.AppendLine();
            mainForm.ConsoleWrite(message.ToString());
        }