示例#1
0
        static void Main(string[] args)
        {
            //string file = "test_D_O";
            string file = "lut_0006_D_O";

            if (args.Length > 0)
            {
                file = args[0];
            }

            Mnet MainNetwork = new Mnet();
            MainNetwork.ReadMnetFile(file + @".MNET");
            if (SortObjectOpt)
            {
                Console.WriteLine("Оптимизация распалажения");
                SortOptimize(MainNetwork);
            }
            //ReducteDUP(MainNetwork);
            //loadnodes
            Console.WriteLine("Загрузка темплейтов");
            RouteUtils.Node[] mcNodes = new RouteUtils.Node[MainNetwork.nodes.Count];
            for (int i = 0; i < MainNetwork.nodes.Count; i++)
            {
                mcNodes[i] = new RouteUtils.Node(MainNetwork.nodes[i].NodeType + ".binhl");
                mcNodes[i].NodeName = MainNetwork.nodes[i].NodeName;
                MainNetwork.nodes[i].mcNode = mcNodes[i];
            }
            Console.WriteLine("OK");
            //Place nodes
            int PlaceLayer = 0;
            int BaseSize = 0;

            //switch (placeMode) { }
            switch (placeMode)
            {
                case PlaceModes.Compact1:
                    PlaceCompact(MainNetwork, mcNodes, out PlaceLayer, out BaseSize);
                    break;
                case PlaceModes.Fast:
                    PlaceFast(MainNetwork, mcNodes, out PlaceLayer, out BaseSize);
                    break;
                case PlaceModes.Optimal:
                    PlaceOptimal(MainNetwork, mcNodes, out PlaceLayer, out BaseSize);
                    break;
                default:
                    break;
            }

            Console.WriteLine("Размещение ОК");

            List<RouteUtils.Cpoint> Cpoints = new List<RouteUtils.Cpoint>();

            //CreateCpointList

            for (int i = 0; i < MainNetwork.nodes.Count; i++)
            {
                for (int j = 0; j < mcNodes[i].InPorts.Length; j++)
                {
                    Cpoints.Add(new RouteUtils.Cpoint
                    {
                        BaseX = mcNodes[i].InPorts[j].PosX + MainNetwork.nodes[i].x,
                        BaseY = mcNodes[i].InPorts[j].PosY + MainNetwork.nodes[i].y,
                        PointName = MainNetwork.nodes[i].NodeName + "-" + mcNodes[i].InPorts[j].Name,
                        Indat = true
                    });

                }

                for (int j = 0; j < mcNodes[i].OutPorts.Length; j++)
                {
                    Cpoints.Add(new RouteUtils.Cpoint
                    {
                        BaseX = mcNodes[i].OutPorts[j].PosX + MainNetwork.nodes[i].x,
                        BaseY = mcNodes[i].OutPorts[j].PosY + MainNetwork.nodes[i].y,
                        PointName = MainNetwork.nodes[i].NodeName + "-" + mcNodes[i].OutPorts[j].Name,
                        Indat = false
                    });

                }
            }

            SortWire(Cpoints,MainNetwork,BaseSize);

            int CurrentWireLayer = 1;
            int CurrentRealLayer = 0;
            int WireNum = 0;
            RouteUtils.Wire[] MCWires = new RouteUtils.Wire[MainNetwork.wires.Count];
            //Draw wires in layer
            int TotalLayers = 0;
            for (int j = 0; j < 24; j++)
            {

                CurrentWireLayer = j * 2 + 1;
                if (j > 4) CurrentWireLayer += 5;
                if (j > 9) CurrentWireLayer += 5;
                if (j > 14) CurrentWireLayer += 5;

                CurrentRealLayer = PlaceLayer - 1 - j * 2;

                if (j > 4) CurrentRealLayer -= 2;
                if (j > 9) CurrentRealLayer -= 2;
                if (j > 14) CurrentRealLayer -= 2;

                WireNum = 0;

                char[,] WireMask = new char[BaseSize, BaseSize];

                for (int i = 0; i < MainNetwork.wires.Count; i++)
                {

                    List<int> WPX;
                    List<int> WPY;

                    if (WireOpt)
                    {
                        int Twire = 0;
                        int mink = 999999;
                        int bestN = 0;

                        //TODO Попробовать распаралелить
                        for (int k = 0; k < MainNetwork.wires.Count; k++)
                        {
                            if (!MainNetwork.wires[k].Placed)
                            {
                                int bw = FindBestWireToRoute(MainNetwork, BaseSize, Cpoints, CurrentWireLayer, CurrentRealLayer, k, MCWires, WireMask);
                                if (mink > bw && bw != 0)
                                {
                                    mink = bw;
                                    bestN = k;
                                }
                            }
                        }
                        if (!MainNetwork.wires[bestN].Placed)
                        {
                            PlaceWire(MainNetwork, BaseSize, Cpoints, CurrentWireLayer, CurrentRealLayer, bestN, MCWires, WireMask, out WPX, out WPY);
                            Twire = bestN;
                            if (MainNetwork.wires[bestN].Placed)
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                WireNum++;
                                Console.WriteLine(MainNetwork.wires[bestN].ToString());
                            }
                            else
                            {
                                i = MainNetwork.wires.Count;
                                Console.ForegroundColor = ConsoleColor.White;
                            }

                        }
                        else
                        {
                            i = MainNetwork.wires.Count;
                        }

                    }
                    else
                    {
                        if (!MainNetwork.wires[i].Placed)
                        {

                            PlaceWire(MainNetwork, BaseSize, Cpoints, CurrentWireLayer, CurrentRealLayer, i, MCWires, WireMask, out WPX, out WPY);

                            if (MainNetwork.wires[i].Placed)
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                WireNum++;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.White;
                            }

                            Console.WriteLine(MainNetwork.wires[i].ToString());

                        }
                    }
                }
                Console.WriteLine("Разведено в текущем слое:" + WireNum);
                if (WireNum > 0)
                {
                    TotalLayers++;
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine("Всего Слоев:" + TotalLayers);

            RouteUtils.Node OutNode = new RouteUtils.Node("OUT", BaseSize, BaseSize, PlaceLayer + 10);

            //OutNode.PlaceAnotherNode(new RouteUtils.Node("DUP23.binhl"), 0, 0, 0);
            for (int i = 0; i < MainNetwork.nodes.Count; i++)
            {
                OutNode.PlaceAnotherNode(mcNodes[i], MainNetwork.nodes[i].x, MainNetwork.nodes[i].y, MainNetwork.nodes[i].z);

            }
            //LongCpoint

            for (int i = 0; i < Cpoints.Count; i++)
            {
                if (Cpoints[i].UsedLayer >= 10)
                {
                    Cpoints[i].UsedLayer -= 4;
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 12, PlaceLayer - 11] = "W";
                    if (Cpoints[i].Indat)
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 12, PlaceLayer - 10] = "^";
                    else
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 12, PlaceLayer - 10] = "v";

                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 13, PlaceLayer - 11] = "W";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 13, PlaceLayer - 10] = "#";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 14, PlaceLayer - 11] = "W";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 14, PlaceLayer - 10] = "#";
                }

                if (Cpoints[i].UsedLayer >= 22)
                {
                    Cpoints[i].UsedLayer -= 3;
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 27, PlaceLayer - 23] = "W";
                    if (Cpoints[i].Indat)
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 27, PlaceLayer - 22] = "^";
                    else
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 27, PlaceLayer - 22] = "v";

                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 28, PlaceLayer - 23] = "W";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 28, PlaceLayer - 22] = "#";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 29, PlaceLayer - 23] = "W";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 29, PlaceLayer - 22] = "#";
                }

                if (Cpoints[i].UsedLayer >= 34)
                {
                    Cpoints[i].UsedLayer -= 3;
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 42, PlaceLayer - 35] = "W";
                    if (Cpoints[i].Indat)
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 42, PlaceLayer - 34] = "^";
                    else
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 42, PlaceLayer - 34] = "v";

                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 43, PlaceLayer - 35] = "W";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 43, PlaceLayer - 34] = "#";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 44, PlaceLayer - 35] = "W";
                    OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + 44, PlaceLayer - 34] = "#";
                }

                for (int j = 0; j < Cpoints[i].UsedLayer; j++)
                {
                    if (j <= 10)
                    {
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + j + 1, PlaceLayer - j - 1] = "w";
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + j + 1, PlaceLayer - j - 0] = "#";
                    }
                    if (j > 10 && j <= 22)
                    {
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + j + 4, PlaceLayer - j - 1] = "w";
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + j + 4, PlaceLayer - j - 0] = "#";
                    }
                    if (j > 22 && j <= 34)
                    {
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + j + 7, PlaceLayer - j - 1] = "w";
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + j + 7, PlaceLayer - j - 0] = "#";
                    }

                    if (j > 34)
                    {
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + j + 10, PlaceLayer - j - 1] = "w";
                        OutNode.DataMatrix[Cpoints[i].BaseX, Cpoints[i].BaseY + j + 10, PlaceLayer - j - 0] = "#";
                    }
                }
            }
            //PlaceReapiters
            for (int i = 0; i < MainNetwork.wires.Count; i++)
            {
                MCWires[i].PlaceRepeaters();
            }
            //SyncWires
            List<RouteUtils.Wire> WiresToSync = new List<RouteUtils.Wire>();
            for (int i = 0; i < MainNetwork.wires.Count; i++)
            {
                if (MainNetwork.wires[i].DistPort == "clk")
                {
                    WiresToSync.Add(MCWires[i]);
                }
            }
            int SyncLen = 0;
            for (int i = 0; i < WiresToSync.Count; i++)
            {
                if (WiresToSync[i].CalcRepCount() > SyncLen)
                    SyncLen = WiresToSync[i].CalcRepCount();
            }

            for (int i = 0; i < WiresToSync.Count; i++)
            {
                WiresToSync[i].RepCompincate(SyncLen - WiresToSync[i].CalcRepCount());
                WiresToSync[i].Synced = true;
            }

                //PlaceWires
                for (int i = 0; i < MainNetwork.wires.Count; i++)
                {
                    if (MainNetwork.wires[i].Placed)
                    {
                        for (int j = 0; j < MCWires[i].WirePointX.Length; j++)
                        {
                            if (MCWires[i].Synced)
                            {
                                OutNode.DataMatrix[MCWires[i].WirePointX[j], MCWires[i].WirePointY[j], MCWires[i].WirePointZ[j]] = "S";
                            }
                            else
                            {
                                OutNode.DataMatrix[MCWires[i].WirePointX[j], MCWires[i].WirePointY[j], MCWires[i].WirePointZ[j]] = "w";
                            }
                            if (MCWires[i].Rep[j])
                            {
                                OutNode.DataMatrix[MCWires[i].WirePointX[j], MCWires[i].WirePointY[j], MCWires[i].WirePointZ[j] + 1] = MCWires[i].RepNp[j];
                            }
                            else
                            {
                                OutNode.DataMatrix[MCWires[i].WirePointX[j], MCWires[i].WirePointY[j], MCWires[i].WirePointZ[j] + 1] = "#";
                            }
                        }
                    }
                }

                //Обрезка
                Console.WriteLine("Обрезка рабочей Облости");
                RouteUtils.Node OutNodeO = CutOutputNode(PlaceLayer, BaseSize, OutNode);
                //Маркировка портов ввода вывода
                OutNodeO.InPorts = MainNetwork.nodes.Where(t => t.NodeType == "INPort").Select(t => new RouteUtils.InPort(t.NodeName, t.x+1, t.y)).ToArray();
                OutNodeO.OutPorts = MainNetwork.nodes.Where(t => t.NodeType == "OUTPort").Select(t => new RouteUtils.OutPort(t.NodeName, t.x+1, t.y)).ToArray();

                Console.WriteLine("Экспорт");
                OutNodeO.Export( file + ".binhl");
        }
示例#2
0
        private static void PlaceWire(Mnet MainNetwork, int BaseSize, List<RouteUtils.Cpoint> Cpoints, int CurrentWireLayer, int CurrentRealLayer, int WireNum, RouteUtils.Wire[] MCWires, char[,] WireMask, out List<int> WPX, out List<int> WPY)
        {
            //WireMask = new string[BaseSize, BaseSize];

            //PlaceMaskCpoint
            for (int j = 0; j < Cpoints.Count; j++)
            {
                if (Cpoints[j].UsedLayer == 0)
                DrawAtMask(WireMask, Cpoints[j].BaseX, Cpoints[j].BaseY + CurrentWireLayer, 1, 2);
            }

            Wire W = MainNetwork.wires[WireNum];

            RouteUtils.Wire MCW = new RouteUtils.Wire(W.SrcName + "-" + W.SrcPort, W.DistName + "-" + W.DistPort);
            //UnmaskStartEndPoint
            RouteUtils.Cpoint SP = FindCpoint(MCW.StartName, Cpoints);
            RouteUtils.Cpoint EP = FindCpoint(MCW.EndName, Cpoints);

            SP.BaseY += CurrentWireLayer;
            EP.BaseY += CurrentWireLayer;

            UnmaskCpoint(WireMask, SP);
            UnmaskCpoint(WireMask, EP);
            //CalcAstar
            int[,] AStarTable = CalcAstar(BaseSize, WireMask, SP, EP);

            //DrawWire

            bool placed = TryPlaceWire(SP, EP, AStarTable, out WPX, out WPY);
            if (placed)
            {
                //WireRemask
                for (int i = 0; i < WPX.Count; i++)
                {
                    DrawAtMask(WireMask, WPX[i], WPY[i], 1, 1);
                }

                MCWires[WireNum] = new RouteUtils.Wire(MCW.StartName, MCW.EndName);

                MCWires[WireNum].WirePointX = new int[WPX.Count];
                MCWires[WireNum].WirePointY = new int[WPX.Count];
                MCWires[WireNum].WirePointZ = new int[WPX.Count];

                for (int i = 0; i < WPX.Count; i++)
                {
                    MCWires[WireNum].WirePointX[WPX.Count - i - 1] = WPX[i];
                    MCWires[WireNum].WirePointY[WPX.Count - i - 1] = WPY[i];
                    MCWires[WireNum].WirePointZ[WPX.Count - i - 1] = CurrentRealLayer;
                }
                MainNetwork.wires[WireNum].Placed = true;

                SP.UsedLayer = CurrentWireLayer;
                EP.UsedLayer = CurrentWireLayer;
            }
            SP.BaseY -= CurrentWireLayer;
            EP.BaseY -= CurrentWireLayer;
        }
示例#3
0
        private static int FindBestWireToRoute(Mnet MainNetwork, int BaseSize, List<RouteUtils.Cpoint> Cpoints, int CurrentWireLayer, int CurrentRealLayer, int WireNum, RouteUtils.Wire[] MCWires, char[,] WireMask)
        {
            for (int j = 0; j < Cpoints.Count; j++)
            {
                if (Cpoints[j].UsedLayer == 0)
                    DrawAtMask(WireMask, Cpoints[j].BaseX, Cpoints[j].BaseY + CurrentWireLayer, 1, 2);
            }

            Wire W = MainNetwork.wires[WireNum];

            RouteUtils.Wire MCW = new RouteUtils.Wire(W.SrcName + "-" + W.SrcPort, W.DistName + "-" + W.DistPort);
            //UnmaskStartEndPoint
            RouteUtils.Cpoint SP = FindCpoint(MCW.StartName, Cpoints);
            RouteUtils.Cpoint EP = FindCpoint(MCW.EndName, Cpoints);

            SP.BaseY += CurrentWireLayer;
            EP.BaseY += CurrentWireLayer;

            UnmaskCpoint(WireMask, SP);
            UnmaskCpoint(WireMask, EP);
            //CalcAstar
            int[,] AStarTable = CalcAstar(BaseSize, WireMask, SP, EP);
            SP.BaseY -= CurrentWireLayer;
            EP.BaseY -= CurrentWireLayer;

            return AStarTable[EP.BaseX, EP.BaseY + CurrentWireLayer];
        }