示例#1
0
        public void DoAlgJarry()
        {
            StringBuilder message = new StringBuilder();
            message.AppendFormat("[date: {0}]\n", DateTime.Now);
            message.AppendFormat("file: {0}\n", mainForm.ctlTabControl.SelectedTab.Text);
            message.AppendLine("--- Jarry Algorithm ---");
            Router root;
            if (SelectedElements.Count == 1 && (root = SelectedElements[0] as Router) != null)
            {
                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");
                    }

                    Network.ResetEquipment(root.Area);
                    Network.ResetReserve(root.Area);
                    Stopwatch stopWatch = Stopwatch.StartNew();
                    AlgJarry jarry = new AlgJarry(root.Area.Routers, root);
                    stopWatch.Stop();
                    root.Mark = Marks.Jarry;
                    Network.ResetEquipment(root.Area);
                    AlgDejkstra dejkstra = new AlgDejkstra();
                    dejkstra.DoAlg(root);

                    message.AppendFormat("root: R{0}\n", root.Number);
                    message.AppendFormat("area: {0}\n", root.Area.Number);
                    message.AppendFormat("time: {0:00.000} ms\n", (stopWatch.ElapsedTicks * 1000.0) / Stopwatch.Frequency);

                    message.AppendLine();
                    foreach (Router router in root.Area.Routers)
                        if (router.Grade > 0)
                            message.AppendFormat("R{0}; Grade:{1}; Reserve:R{2}; Distance:{3} Main:R{4}\n",
                                                 router.Number,
                                                 router.Grade,
                                                 router.Father.Number,
                                                 router.DistancePointer,
                                                 router.MainRoute[router.MainRoute.Count - 1].Owner.Number);
                }
                else
                {
                    message.Append("warning: gaph is not closed!\n" +
                           "execution is stopped.\n");
                }
            }
            else
            {
                message.Append("warning: please select one router!\n" +
                       "execution is stopped.\n");
            }

            UpdateField();
            message.AppendLine("--- End ---");
            message.AppendLine();
            mainForm.ConsoleWrite(message.ToString());
        }
示例#2
0
        public void DoAlgPairSwitch()
        {
            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();
                AlgPairSwitch algPairSwitch = new AlgPairSwitch();
                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);
                        algPairSwitch.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());
        }
示例#3
0
        public void DoAlgDejkstra()
        {
            StringBuilder message = new StringBuilder();
            message.AppendFormat("[date: {0}]\n", DateTime.Now);
            message.AppendFormat("file: {0}\n", mainForm.ctlTabControl.SelectedTab.Text);
            message.AppendLine("--- Dejkstra Algorithm ---");
            Router root;
            if (SelectedElements.Count == 1 && (root = SelectedElements[0] as Router) != null)
            {
                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();
                    Network.ResetEquipment(root.Area);
                    root.Mark = Marks.Dejkstra;

                    Stopwatch stopWatch = Stopwatch.StartNew();
                    algDejkstra.DoAlg(root);
                    stopWatch.Stop();

                    Pen redPen = new Pen(((Router)SelectedElements[0]).Area.SpecChannelColor, 4);
                    foreach (Channel channel in ((Router)SelectedElements[0]).Area.Channels)
                    {
                        if (channel.Tree == true)
                        {
                            channel.Pen = redPen;
                        }
                    }

                    message.AppendFormat("root: R{0}\n", root.Number);
                    message.AppendFormat("area: {0}\n", root.Area.Number);
                    message.AppendFormat("time: {0:00.000} ms\n", (stopWatch.ElapsedTicks * 1000.0) / Stopwatch.Frequency);
                    message.AppendFormat("routers count: {0}\n", root.Area.Routers.Count);
                    message.AppendFormat("lab_total: {0} e.o.\n", algDejkstra.Lab);
                }
                else
                {
                    message.Append("warning: gaph is not closed!\n" +
                           "execution is stopped.\n");
                }
            }
            else
            {
                message.Append("warning: please select one router!\n" +
                       "execution is stopped.\n");
            }

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