Esempio n. 1
0
 private Int32 ConnectCount(Router router, Area area)
 {
     Int32 connectCount = 0;
     foreach (Port port in router.ConnectedPorts)
         if (port.Router.Area == area) connectCount++;
     return connectCount;
 }
Esempio n. 2
0
 public Port(Router ow, String nam)
 {
     name = nam;
     owner = ow;
     Distance = Const.INF;
     Route = new List<Port>();
     Bandwidth = 10;
 }
Esempio n. 3
0
 // конструктор
 public RouterForm(Router r, Network net)
 {
     InitializeComponent();
     network = net;
     router = r;
     selectedPort = router.Ports[0];
     InitializeInterfaces();
     FindAreas();
 }
Esempio n. 4
0
 public void DoAlg(Router root)
 {
     // определение сетевого сегмента
     Area networkArea = root.Area;
     root.DistancePointer = 0;
     // текущий маршрутизатор
     Router tempRouter = root;
     for (int i = 0; i < networkArea.Routers.Count; i++)
     {
         for (int p = 0; p < tempRouter.ConnectedPorts.Count; p++)
         {
             if ((tempRouter.ConnectedPorts[p].Router.Area == tempRouter.Area) &&
                 (tempRouter.ConnectedPorts[p].Router.Used == false) &&
                 (tempRouter.ConnectedPorts[p].Router.DistancePointer >
                 (tempRouter.DistancePointer + tempRouter.ConnectedPorts[p].Channel.Criterion)))
             {
                 // обновление метки
                 tempRouter.ConnectedPorts[p].Router.DistancePointer =
                 tempRouter.DistancePointer + tempRouter.ConnectedPorts[p].Channel.Criterion;
                 // обновление кратчайшего маршрута
                 tempRouter.ConnectedPorts[p].Router.MainRoute.Clear();
                 tempRouter.ConnectedPorts[p].Router.MainRoute.AddRange(tempRouter.MainRoute);
                 tempRouter.ConnectedPorts[p].Router.MainRoute.Add(tempRouter.ConnectedPorts[p]);
             }
         }
         tempRouter.Used = true;
         double min = Const.INF;
         for (int r = 0; r < networkArea.Routers.Count; r++)
         {
             lab += 1;
             if ((networkArea.Routers[r].DistancePointer < min) &&
                 (networkArea.Routers[r].Used == false))
             {
                 min = networkArea.Routers[r].DistancePointer;
                 tempRouter = networkArea.Routers[r];
             }
         }
     }
     tempRouter = root;
     for (int r = 0; r < networkArea.Routers.Count; r++)
     {
         for (int p = 0; p < networkArea.Routers[r].ConnectedPorts.Count; p++)
         {
             if (networkArea.Routers[r].ConnectedPorts[p].Router.DistancePointer ==
                 networkArea.Routers[r].DistancePointer -
                 networkArea.Routers[r].ConnectedPorts[p].Channel.Criterion)
             {
                 networkArea.Routers[r].ConnectedPorts[p].Channel.Tree = true;
                 break;
             }
         }
     }
 }
Esempio n. 5
0
 private Port Deg(Router router)
 {
     Port port = null;
     SByte count = 0;
     foreach (Port p in router.ConnectedPorts)
         if (p.Channel.Tree == true)
         {
             port = p;
             count++;
         }
     if (count == 1)
         return port;
     return null;
 }
Esempio n. 6
0
 private void DoAlg(Router root, Network net)
 {
     root.Used = true;
     for (int i = 0; i < net.Routers.Count - 1; i++)
     {
         Channel tmpChannel = new Channel();
         tmpChannel.Criterion = Const.INF;
         foreach (Channel channel in net.Channels)
         {
             if ((channel.StartRouter.Used != channel.EndRouter.Used) &&
                 (channel.Criterion < tmpChannel.Criterion))
             {
                 tmpChannel = channel;
             }
         }
         tmpChannel.Tree = tmpChannel.StartRouter.Used = tmpChannel.EndRouter.Used = true;
     }
 }
Esempio n. 7
0
        public Channel(Router sRouter, Router eRouter)
        {
            Port sPort = null;
            Port ePort = null;
            foreach (Port port in sRouter.Ports)
            {
                if (port.IsConnected == false)
                {
                    sPort = port;
                    break;
                }
            }
            foreach (Port port in eRouter.Ports)
            {
                if (port.IsConnected == false)
                {
                    ePort = port;
                    break;
                }
            }

            startRouter = sRouter;
            sRouter.Channels.Add(this);
            endRouter = eRouter;
            eRouter.Channels.Add(this);
            endPort = ePort;
            endPort.Connect(this, sRouter);
            startPort = sPort;
            startPort.Connect(this, eRouter);

            endPort.OppositePort = sPort;
            startPort.OppositePort = ePort;

            // добавление ребра в сегмент
            if (sRouter.Area == eRouter.Area)
            {
                Area = sRouter.Area;
                Area.Channels.Add(this);
            }
            UpdateOspf();
            UpdateCenter();
        }
Esempio n. 8
0
        // основной метод
        public void DoAlg(Router startRouter, Router endRouter)
        {
            // если узел-источник и узел-получатель находятся в одном сегменте ...
            if (startRouter.Area == endRouter.Area)
            {
                // проложить маршрут в сегменте
                routeRouters.Add(endRouter);
                PaveRoute(startRouter, endRouter, 0);
            }
            else // если узел-источник и узел-получатель находятся в разных сегментах ...
            {
                // проложить межсегментный маршрут
                PaveRoute(startRouter.Area, endRouter.Area, 0);

                // добавить узел-получатель в маршрут
                if (routeRouters.Contains(endRouter) == false)
                {
                    routeRouters.Add(endRouter);
                }

                // добавить узел-источник в маршрут
                if (routeRouters.Contains(startRouter) == false)
                {
                    routeRouters.Insert(0, startRouter);
                }

                // построить полный маршрут
                for (int i = 0; i < routeRouters.Count - 1; i++)
                {
                    if (routeRouters[i].Area == routeRouters[i + 1].Area)
                    {
                        int oldCount = routeRouters.Count;
                        PaveRoute(routeRouters[i], routeRouters[i + 1], i + 1);
                        i += routeRouters.Count - oldCount;
                    }
                }
            }
        }
Esempio n. 9
0
        public Channel(Router sRouter, Port sPort, Router eRouter, Port ePort)
        {
            startRouter = sRouter;
            sRouter.Channels.Add(this);
            endRouter = eRouter;
            eRouter.Channels.Add(this);
            endPort = ePort;
            endPort.Connect(this, sRouter);
            startPort = sPort;
            startPort.Connect(this, eRouter);

            endPort.OppositePort = sPort;
            startPort.OppositePort = ePort;

            // добавление ребра в сегмент
            if (sRouter.Area == eRouter.Area)
            {
                Area = sRouter.Area;
                Area.Channels.Add(this);
            }
            UpdateOspf();
            UpdateCenter();
        }
Esempio n. 10
0
 public void Connect(Channel ch, Router r)
 {
     channel = ch;
     router = r;
     owner.ConnectedPorts.Add(this);
 }
Esempio n. 11
0
 // удаление узла связи
 public void RemoveRouter(Router router)
 {
     while (router.Channels.Count > 0)
         RemoveChannel(router.Channels[0]);
     drawingRouters.Remove(router);
     router.Area.Routers.Remove(router);
     Network.Routers.Remove(router);
     mainForm.RoutersRefresh(Network.Routers.Count);
     mainForm.ChannelsRefresh(Network.Channels.Count);
     UpdateField();
 }
Esempio n. 12
0
        public void CreateNetwork(int width, int height)
        {
            int offset = 150;
            double countX = width / (Drawing.xOffset + offset);
            countX = Math.Floor(countX);

            double countY = height / (Drawing.yOffset + offset);
            countY = Math.Floor(countY);

            Router[,] mass = new Router[(int)countX, (int)countY];
            int constx = Drawing.xOffset + offset;
            int consty = Drawing.yOffset + offset;

            int x = 70;
            int y = 70;
            int routerNumber = 0;

            Network.Areas.Add(new Area());

            for (int i = 0; i < countX; i++)
            {
                for (int j = 0; j < countY; j++)
                {
                    Router router = new Router(new Point(x, y), routerNumber);
                    Network.MainArea.AddRouter(router);
                    mass[i, j] = router;
                    Network.Routers.Add(router);
                    routerNumber += 1;
                    y += consty;
                }
                x += constx;
                y = 70;
            }

            Random random = new Random();

            if (mainForm.FullMesh == false)
            {
                for (int i = 0; i < countX; i++)
                {
                    for (int j = 0; j < countY; j++)
                    {
                        if (j < countY - 1)
                        {
                            Channel channel = new Channel(mass[i, j], mass[i, j + 1]);
                            Network.Channels.Add(channel);
                            channel.Delay = 1 + random.Next(15);
                            channel.Cost = 1 + random.Next(15);
                            channel.Metric = 1 + random.Next(15);
                            channel.ChangeCriterion(mainForm.Criterion);
                        }

                        if (i > 0)
                        {
                            Channel channel = new Channel(mass[i, j], mass[i - 1, j]);
                            Network.Channels.Add(channel);
                            channel.Delay = 1 + random.Next(15);
                            channel.Cost = 1 + random.Next(15);
                            channel.Metric = 1 + random.Next(15);
                            channel.ChangeCriterion(mainForm.Criterion);
                        }
                    }
                }
            }
            else
            {
                foreach (Router router in Network.Routers)
                {
                    foreach (Router r in Network.Routers)
                    {
                        if (router != r)
                        {
                            Channel channel = new Channel(router, r);
                            Network.Channels.Add(channel);
                            drawingChannels.Add(channel);
                            channel.Delay = 1 + random.Next(15);
                            channel.Cost = 1 + random.Next(15);
                            channel.Metric = 1 + random.Next(15);
                            channel.ChangeCriterion(mainForm.Criterion);
                        }
                    }
                }
            }
            mainForm.ChannelsRefresh(Network.Channels.Count);
        }
Esempio n. 13
0
 public void CreateChannel(Router r1, Port port1, Router r2, Port port2, 
                           Int32 delay, Int32 cost, Int32 metric)
 {
     Channel channel = new Channel(r1, port1, r2, port2);
     Network.Channels.Add(channel);
     drawingChannels.Add(channel);
     channel.Delay = delay;
     channel.Cost = cost;
     channel.Metric = metric;
     channel.ChangeCriterion(mainForm.Criterion);
     mainForm.ChannelsRefresh(Network.Channels.Count);
 }
Esempio n. 14
0
 public void CreateChannel(Router r1, Port port1, Router r2, Port port2)
 {
     Channel channel = new Channel(r1, port1, r2, port2);
     Network.Channels.Add(channel);
     drawingChannels.Add(channel);
     if (mainForm.AutoWeight == false)
     {
         ChannelForm properties = new ChannelForm(channel);
         properties.ShowDialog(this);
     }
     else
     {
         Random random = new Random();
         channel.Delay = 1 + random.Next(15);
         channel.Cost = 1 + random.Next(15);
         channel.Metric = 1 + random.Next(15);
     }
     if (mainForm.AutoPortName == true)
     {
         CreateTextLabel(port1.ShortName, new Point(r1.Location.X + (r2.Location.X - r1.Location.X) / 6,
                                           r1.Location.Y + (r2.Location.Y - r1.Location.Y) / 6));
         CreateTextLabel(port2.ShortName, new Point(r2.Location.X + (r1.Location.X - r2.Location.X) / 6,
                                           r2.Location.Y + (r1.Location.Y - r2.Location.Y) / 6));
     }
     channel.ChangeCriterion(mainForm.Criterion);
     mainForm.ChannelsRefresh(Network.Channels.Count);
 }
Esempio n. 15
0
        // событие: клавиша мыши нажата
        private void ctlPicBox_MouseDown(object sender, MouseEventArgs e)
        {
            // обработка события
            if (e.Button == MouseButtons.Left)
            {
                switch (mainForm.Instrument)
                {
                    case Instruments.Edit:
                            IDrag selectedElement = null;
                            if ((selectedElement = FindElement(e.Location)) == null)
                            {
                                if ((SelectedChannel = FindChannel(e.Location)) == null)
                                    multiSelect = true;
                                SelectedElements.Clear();
                            }
                            else
                            {
                                if (SelectedElements.Count == 0)
                                    SelectedElements.Add(selectedElement);
                                else if (SelectedElements.Count == 1)
                                {
                                    if (CtrlIsCliced == true)
                                    {
                                        if (selectedElement != SelectedElements[0])
                                            SelectedElements.Add(selectedElement);
                                        else
                                            SelectedElements.Clear();
                                    }
                                    else
                                        SelectedElements[0] = selectedElement;
                                }
                                else
                                {
                                    if (CtrlIsCliced == true)
                                    {
                                        if (SelectedElements.Contains(selectedElement) == false)
                                            SelectedElements.Add(selectedElement);
                                        else
                                            SelectedElements.Remove(selectedElement);
                                    }
                                    else
                                    {
                                        if (SelectedElements.Contains(selectedElement) == false)
                                        {
                                            SelectedElements.Clear();
                                            SelectedElements.Add(selectedElement);
                                        }
                                    }
                                }

                                foreach (IDrag element in SelectedElements)
                                {
                                    element.XOffset = e.X - element.Location.X;
                                    element.YOffset = e.Y - element.Location.Y;
                                }
                                SelectedChannel = null;
                            }
                        rectPoint = e.Location;
                        mouseIsCliced = true;
                        break;

                    case Instruments.Insert_Router:
                        Router router = new Router(e.Location, Network.RouterMaxNumber + 1);
                        Network.MainArea.AddRouter(router);
                        Network.Routers.Add(router);
                        drawingRouters.Add(router);

                        if (mainForm.FullMesh == true)
                        {
                            Random random = new Random();
                            foreach (Router r in Network.Routers)
                            {
                                if (router != r)
                                {
                                    Channel channel = new Channel(router, r);

                                    Network.Channels.Add(channel);
                                    drawingChannels.Add(channel);

                                    channel.Delay = 1 + random.Next(15);
                                    channel.Cost = 1 + random.Next(15);
                                    channel.Metric = 1 + random.Next(15);

                                    channel.ChangeCriterion(mainForm.Criterion);
                                    mainForm.ChannelsRefresh(Network.Channels.Count);
                                }
                            }
                        }

                        mainForm.RoutersRefresh(Network.Routers.Count);
                        break;

                    case Instruments.Insert_Channel:
                        if (mouseIsCliced == true && tmpRouter1 != null)
                        {
                            if ((tmpRouter2 = FindRouter(e.Location)) != null)
                            {
                                ctlPicBoxContextMenu.Show(ctlPicBox.PointToScreen(e.Location));
                            }
                            else
                            {
                                mouseIsCliced = false;
                                tmpPort1 = tmpPort2 = null;
                                tmpRouter1 = tmpRouter2 = null;
                            }
                        }
                        else
                        {
                            if ((tmpRouter1 = FindRouter(e.Location)) != null)
                                ctlPicBoxContextMenu.Show(ctlPicBox.PointToScreen(e.Location));
                        }
                        break;

                   case Instruments.Create_Text:
                        TextLabel textLabel = CreateTextLabel(null, e.Location);
                        EditText editTextForm = new EditText(textLabel);
                        editTextForm.SetLocation(ctlPicBox.PointToScreen(textLabel.Location));
                        editTextForm.ShowDialog();
                        break;
                }
                UpdateField();
            }
        }
Esempio n. 16
0
        public static void DrawRouter(Router router, PaintEventArgs e)
        {
            e.Graphics.DrawImage(router.Image, new Point(router.Location.X - xOffset,
                                                         router.Location.Y - yOffset));

            Rectangle rectangle = new Rectangle(new Point(router.Location.X - router.TextSize.Width / 2,
                                                                              router.Location.Y - yOffset - 18),
                                                                              router.TextSize);
            e.Graphics.FillRectangle(Brushes.White, rectangle);

            switch (router.Mark)
            {
                case Marks.Dejkstra:
                    e.Graphics.DrawRectangle(new Pen(router.Area.SpecChannelColor, 2), rectangle);
                    break;

                case Marks.Prim:
                    e.Graphics.DrawRectangle(new Pen(Color.Black, 2), rectangle);
                    break;

                case Marks.Segmentation:
                    e.Graphics.DrawRectangle(new Pen(Color.Blue, 2), rectangle);
                    break;

                case Marks.OptimalRoute:
                    e.Graphics.DrawRectangle(new Pen(Color.Red, 2), rectangle);
                    break;

                case Marks.Jarry:
                    e.Graphics.DrawRectangle(new Pen(Color.BurlyWood, 2), rectangle);
                    break;
            }
            StringFormat stringFormat = new StringFormat();
            stringFormat.Alignment = StringAlignment.Center;
            e.Graphics.DrawString(router.Name, new Font("Arial", 12), Brushes.Black, new Point(router.Location.X,
                                                                                               router.Location.Y - yOffset - 18),
                                                                                               stringFormat);
        }
Esempio n. 17
0
 private void CheckLoop(Router router, ref int counter)
 {
     foreach (Port port in router.ConnectedPorts)
     {
         if (port.IsConnected && port.Router.Used == false)
         {
             port.Router.Used = true;
             counter++;
             CheckLoop(port.Router, ref counter);
         }
     }
 }
Esempio n. 18
0
 public void Disconnect()
 {
     channel = null;
     router = null;
     owner.ConnectedPorts.Remove(this);
 }
Esempio n. 19
0
 public AlgSegmentation(Network net, Router root, Double q)
 {
     DoAlg(net, root, q);
     net.CheckAreas();
 }
Esempio n. 20
0
 /// <summary>
 /// Построение резервных маршрутов для текущего 
 /// маршрутизатора
 /// </summary>
 /// <param name="router">Текущий маршрутизатор</param>
 private void PaveReserveRouts(Router router)
 {
     foreach (Port port in router.ConnectedPorts)
     {
         if (port.Router.Area == router.Area)
         {
             if (port.Router.DistancePointer + port.Channel.Criterion == router.DistancePointer)
             {
                 port.Distance = router.DistancePointer;
                 port.Route.Clear();
                 port.Route.AddRange(router.MainRoute);
                 router.EnterPort = port;
             }
             else
             {
                 if (router.DistancePointer + port.Channel.Criterion == port.Router.DistancePointer)
                 {
                     port.Distance = Const.INF;
                     port.Route.Clear();
                 }
                 else
                 {
                     port.Distance = port.Router.DistancePointer + port.Channel.Criterion;
                     port.Route.Clear();
                     port.Route.AddRange(port.Router.MainRoute);
                     port.Route.Add(port.OppositePort);
                 }
             }
         }
     }
 }
Esempio n. 21
0
 // конструктор
 public AlgPrim(Router root, Network net)
 {
     DoAlg(root, net);
 }
Esempio n. 22
0
        // событие: раскрытие контекстного меню Рабочего Поля
        private void ctlPicBoxContextMenu_Opening(object sender, CancelEventArgs e)
        {
            ctlPicBoxContextMenu.Items.Clear();
            switch (mainForm.Instrument)
            {
                case Instruments.Edit:
                    // заполнить меню узла связи
                    Router selectedRouter = FindRouter(mouseLocation);
                    if (selectedRouter != null)
                    {
                        SelectedElements.Add(selectedRouter);
                        SelectedChannel = null;
                        ctlPicBoxContextMenu.Items.Clear();
                        ctlRemove.Image = Properties.Resources.ToolRouterRemove;
                        ctlPicBoxContextMenu.Items.Add(ctlRemove);
                        ctlPicBoxContextMenu.Items.Add(contextSeparator1);
                        ctlPicBoxContextMenu.Items.Add(ctlDejkstra);
                        ctlPicBoxContextMenu.Items.Add(ctlOptimalRout);
                        ctlPicBoxContextMenu.Items.Add(ctlPrim);
                        ctlPicBoxContextMenu.Items.Add(ctlSegmentation);
                        ctlPicBoxContextMenu.Items.Add(ctlPairSwitch);
                        ctlPicBoxContextMenu.Items.Add(contextSeparator2);
                        ctlPicBoxContextMenu.Items.Add(ctlProperties);
                        ctlRemove.Text = "Remove Router";
                        ctlPicBox.Invalidate();
                        return;
                    }

                    // заполнить меню канала связи
                    SelectedChannel = FindChannel(mouseLocation);
                    if (SelectedChannel != null)
                    {
                        SelectedElements.Clear();
                        ctlRemove.Image = Properties.Resources.ToolLineRemove;
                        ctlPicBoxContextMenu.Items.Add(ctlRemove);
                        ctlPicBoxContextMenu.Items.Add(contextSeparator1);
                        ctlPicBoxContextMenu.Items.Add(ctlProperties);
                        ctlRemove.Text = "Remove Channel";
                        ctlPicBox.Invalidate();
                        return;
                    }

                    // заполнить меню Рабочего Поля
                    ctlPicBoxContextMenu.Items.Add(ctlDeleteAll);
                    ctlPicBoxContextMenu.Items.Add(contextSeparator1);
                    ctlPicBoxContextMenu.Items.Add(ctlProperties);
                    UpdateField();
                    break;

                case Instruments.Insert_Channel:
                    Router router = FindRouter(mouseLocation);
                    if (router != null)
                    {
                        foreach (Port port in router.Ports)
                        {
                            ToolStripMenuItem item = new ToolStripMenuItem();
                            item.Name = port.FullName;
                            item.Text = port.FullName;
                            item.Enabled = !port.IsConnected;
                            item.Size = new Size(32, 19);
                            item.Click += (_sender, _e) =>
                            {
                                if (tmpPort1 == null)
                                {
                                    tmpPort1 = port;
                                    mouseIsCliced = true;
                                }
                                else
                                {
                                    tmpPort2 = port;
                                    if (tmpRouter1 != null && tmpRouter1 != tmpRouter2)
                                    {
                                        CreateChannel(tmpRouter1, tmpPort1, tmpRouter2, tmpPort2);
                                        mouseIsCliced = false;
                                        tmpPort1 = tmpPort2 = null;
                                        tmpRouter1 = tmpRouter2 = null;
                                    }
                                }
                            };
                            ctlPicBoxContextMenu.Items.Add(item);
                        }
                    }
                    break;
            }
        }
Esempio n. 23
0
        private void DoAlg(Network net, Router root, Double q)
        {
            // 1 этап. Алгоритм Прима
            AlgPrim algPrim = new AlgPrim(root, net);

            // 2 этап. Получение первичных сегментов
            foreach (Router router in net.Routers)
            {
                Port port = Deg(router);
                if (port != null)
                {
                    Area area = new Area(net.Areas.Count);
                    area.AddRouter(port.Owner);
                    if (port.Router.Area == net.MainArea)
                        area.AddRouter(port.Router);
                    else
                        port.Router.Area.AddRouter(router);
                    net.Areas.Add(area);
                }
            }

            // 3 этап. Получение вторичных сегментов
            List<Router> unallocatedRouters;
            while ((unallocatedRouters = GetUnallocatedRouters(net.Routers, net.MainArea)).Count > 0 )
            {
                // список сегментов, к которым могут присоединиться нераспределенные вершины PA
                List<Area> potentialAreas = new List<Area>();
                // список весов ребер, связывающих вершины с их потенциальными сегментами PW
                List<Int32> potentialWeights = new List<Int32>();
                foreach (Router router in unallocatedRouters)
                {
                    // количество сегментов с одинаковой величиной связей
                    Int32 maxConnectValue = 0;
                    // список сегментов с одинаковой величиной связей ECA
                    List<Area> equalConnectAreas = new List<Area>();
                    // список весов ребер, соединяющий вершину с соответствующим сегментом
                    List<Int32> channelWeights = new List<Int32>();
                    foreach (Port port in router.ConnectedPorts)
                    {
                        if (port.Channel.Tree == true && port.Router.Area != net.MainArea && port.Router.Area.Used == false)
                        {
                            Int32 connectCount = ConnectCount(router, port.Router.Area);
                            if (connectCount == maxConnectValue)
                            {
                                // дополнение списка ECA
                                port.Router.Area.Used = true;
                                equalConnectAreas.Add(port.Router.Area);
                                channelWeights.Add(port.Channel.Criterion);
                            }
                            else if (connectCount > maxConnectValue)
                            {
                                // обновление списка ECA
                                foreach (Area area in equalConnectAreas)
                                    area.Used = false;
                                port.Router.Area.Used = true;
                                maxConnectValue = connectCount;
                                equalConnectAreas = new List<Area>() { port.Router.Area };
                                channelWeights = new List<Int32>() { port.Channel.Criterion };
                            }
                        }
                    }
                    /* выбор оптимального сегмента из соседей вершины */
                    Area connectedArea = null;
                    // минимальный вес ребра между сегментом и вершиной
                    Int32 minConn = Const.INF;
                    if (equalConnectAreas.Count > 0)
                    {
                        for (Int32 i = 0; i < equalConnectAreas.Count; i++ )
                        {
                            equalConnectAreas[i].Used = false;
                            if (channelWeights[i] < minConn)
                            {
                                connectedArea = equalConnectAreas[i];
                                minConn = channelWeights[i];
                            }
                        }
                    }
                    // добавление сегмента к списку PA
                    potentialAreas.Add(connectedArea);
                    // добавление веса ребра к списку PW
                    potentialWeights.Add(minConn);
                    /*
                        * ЗАМЕЧАНИЕ 1:
                        * индекс добавленного сегмента и веса ребра
                        * совпадает с индексом текущей нераспределенной вершины
                            * ЗАМЕЧАНИЕ 2:
                            * элемент списка PA может быть null
                    */
                }
                /* определение оптимальной пары сегмент - вершина */
                Area a = potentialAreas[0];
                Router r = unallocatedRouters[0];
                Int32 min = potentialWeights[0];
                for (Int32 i = 1; i < potentialAreas.Count; i++)
                    if (potentialWeights[i] < min)
                    {
                        min = potentialWeights[i];
                        a = potentialAreas[i];
                        r = unallocatedRouters[i];
                    }
                /* добавление вершины к сегменту */
                a.AddRouter(r);
            }

            // 4 этап. Окончательное разбиение
            // список неоптимальных сегментов ( Q < optQ )
            List<Area> suboptimalAreas;
            while ((suboptimalAreas = GetSuboptimalAreas(net.Areas, q)).Count > 0)
            {
                // список сегментов, которые могут быть объединены с неоптимальными сегментами PA
                List<Area> potentialAreas = new List<Area>();
                // список весов ребер, связывающих сегменты PW
                List<Int32> potentialWeights = new List<Int32>();
                foreach (Area area in suboptimalAreas)
                {
                    // количество сегментов с одинаковой величиной связей
                    Int32 maxConnectValue = 0;
                    // список сегментов с одинаковой величиной связей ECA
                    List<Area> equalConnectAreas = new List<Area>();
                    // список весов ребер, соединяющих сегменты
                    List<Int32> channelWeights = new List<Int32>();
                    foreach (Port gateway in area.Gateways)
                    {
                        if (gateway.Channel.Tree == true && gateway.Router.Area.Used == false)
                        {
                            Int32 connectCount = ConnectCount(area, gateway.Router.Area);
                            if (connectCount == maxConnectValue)
                            {
                                // дополнение списка ECA
                                gateway.Router.Area.Used = true;
                                equalConnectAreas.Add(gateway.Router.Area);
                                channelWeights.Add(gateway.Channel.Criterion);
                            }
                            else if (connectCount > maxConnectValue)
                            {
                                // обновление списка ECA
                                foreach (Area ar in equalConnectAreas)
                                    ar.Used = false;
                                gateway.Router.Area.Used = true;
                                maxConnectValue = connectCount;
                                equalConnectAreas = new List<Area>() { gateway.Router.Area };
                                channelWeights = new List<Int32>() { gateway.Channel.Criterion };
                            }
                        }
                    }
                    /* выбор оптимального сегмента из соседей текущего */
                    Area connectedArea = null;
                    // минимальный вес ребра между сегментами
                    Int32 minConn = Const.INF;
                    if (equalConnectAreas.Count > 0)
                    {
                        for (Int32 i = 0; i < equalConnectAreas.Count; i++)
                        {
                            equalConnectAreas[i].Used = false;
                            if (channelWeights[i] < minConn)
                            {
                                connectedArea = equalConnectAreas[i];
                                minConn = channelWeights[i];
                            }
                        }
                    }
                    // добавление сегмента к списку PA
                    potentialAreas.Add(connectedArea);
                    // добавление веса ребра к списку PW
                    potentialWeights.Add(minConn);
                    /*
                        * ЗАМЕЧАНИЕ 3:
                        * индекс добавленного сегмента и веса ребра
                        * совпадает с индексом текущего неоптимального сегмента
                            * ЗАМЕЧАНИЕ 4:
                            * элемент списка PA может быть null
                    */
                }
                /* определение оптимальной пары сегмент - сегмент */
                Area a1 = potentialAreas[0];
                Area a2 = suboptimalAreas[0];
                Int32 min = potentialWeights[0];
                for (Int32 i = 1; i < potentialAreas.Count; i++)
                    if (potentialWeights[i] < min)
                    {
                        min = potentialWeights[i];
                        a1 = potentialAreas[i];
                        a2 = suboptimalAreas[i];
                    }
                /* объединение сегментов */
                a1.Merge(a2);
            }
        }
Esempio n. 24
0
 public Port(Channel ch, Router r, Router ow, String nam)
     : this(ow, nam)
 {
     channel = ch;
     router = r;
 }
Esempio n. 25
0
        public static void DrawRouterFrame(Router router, PaintEventArgs e)
        {
            int width = xOffset * 2 + 8;
            int height = yOffset * 2 + 8;
            int x = router.Location.X - xOffset - 4;
            int y = router.Location.Y - yOffset - 4;
            int piece = 5;

            Pen pen = new Pen(Brushes.Blue, 2);
            e.Graphics.SmoothingMode = SmoothingMode.Default;

            e.Graphics.DrawLines(pen, new Point[] {
                                                    new Point(x + piece, y + height),
                                                    new Point(x, y + height),
                                                    new Point(x, y),
                                                    new Point(x + piece, y)
                                                    });

            e.Graphics.DrawLines(pen, new Point[] {
                                                   new Point(x + width - piece, y + height),
                                                   new Point(x + width, y + height),
                                                   new Point(x + width, y),
                                                   new Point(x + width - piece, y)
                                                   });
        }
Esempio n. 26
0
 public void AddRouter(Router router)
 {
     Routers.Add(router);
     if (router.Area != null)
         router.Area.Routers.Remove(router);
     router.Area = this;
 }
Esempio n. 27
0
 /// <summary>
 /// Построение резервных маршрутов для текущего 
 /// маршрутизатора
 /// </summary>
 /// <param name="router">Текущий маршрутизатор</param>
 private void PaveReserveRouts(Router router)
 {
     foreach (Port port in router.ConnectedPorts)
     {
         if (port.Router.Area == router.Area)
         {
             if (port.Router.DistancePointer + port.Channel.Criterion == router.DistancePointer)
             {
                 port.Distance = router.DistancePointer;
                 router.EnterPort = port;
             }
             else
             {
                 if (router.DistancePointer + port.Channel.Criterion == port.Router.DistancePointer)
                 {
                     port.Distance = Const.INF;
                 }
                 else
                 {
                     port.Distance = port.Router.DistancePointer + port.Channel.Criterion;
                 }
             }
         }
     }
 }
Esempio n. 28
0
        // построение маршрута внутри сегмента
        private void PaveRoute(Router startRouter, Router endRouter, int position)
        {
            int arLab = 0;

            /* Поиск маршрута по алгоритму Дейкстры */
            startRouter.DistancePointer = 0;
            Router tmpRouter = startRouter;

            while (tmpRouter != endRouter)
            {
                foreach (Port port in tmpRouter.ConnectedPorts)
                {
                    if ((port.Router.DistancePointer > (tmpRouter.DistancePointer + port.Channel.Criterion)) &&
                        (port.Router.Used == false) && (port.Router.Area == tmpRouter.Area))
                    {
                        port.Router.DistancePointer = tmpRouter.DistancePointer + port.Channel.Criterion;
                    }
                }
                tmpRouter.Used = true;
                int min = Const.INF;
                foreach (Router router in startRouter.Area.Routers)
                {
                    arLab += 1;
                    if ((router.DistancePointer < min) && (router.Used == false))
                    {
                        min = router.DistancePointer;
                        tmpRouter = router;
                    }
                }
            }

            /* Построение найденного маршрута */
            tmpRouter = endRouter;
            while (tmpRouter != startRouter)
            {
                foreach (Port port in tmpRouter.ConnectedPorts)
                {
                    if ((port.Router.DistancePointer == (tmpRouter.DistancePointer - port.Channel.Criterion)) &&
                        (port.Router.Area == tmpRouter.Area))
                    {
                        if (routeRouters.Contains(tmpRouter = port.Router) == false)
                        {
                            routeRouters.Insert(position, tmpRouter);
                        }
                        routeChannels.Add(port.Channel);
                        break;
                    }
                }
            }

            areaLab.Add(new KeyValuePair<int, int>(startRouter.Area.Number, arLab));
        }