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"); }
private static RouteUtils.Node CutOutputNode(int PlaceLayer, int BaseSize, RouteUtils.Node OutNode) { //find xs int xs = 0; int ys = 0; int zs = 0; for (int i = 1; i < BaseSize; i++) { int pn = 0; for (int y = 0; y < BaseSize; y++) { for (int z = 0; z < (PlaceLayer + 10); z++) { if (OutNode.DataMatrix[i, y, z] != "0") { pn++; } } } if (pn != 0) { xs = i - 1; break; } } for (int i = 1; i < BaseSize; i++) { int pn = 0; for (int x = 0; x < BaseSize; x++) { for (int z = 0; z < (PlaceLayer + 10); z++) { if (OutNode.DataMatrix[x, i, z] != "0") { pn++; } } } if (pn != 0) { ys = i - 1; break; } } for (int i = 1; i < (PlaceLayer + 10); i++) { int pn = 0; for (int x = 0; x < BaseSize; x++) { for (int y = 0; y < BaseSize; y++) { if (OutNode.DataMatrix[x, y, i] != "0") { pn++; } } } if (pn != 0) { zs = i - 1; break; } } int xe = 0; int ye = 0; int ze = 0; for (int i = 1; i < BaseSize; i++) { int qi = BaseSize - 1 - i; int pn = 0; for (int y = 0; y < BaseSize; y++) { for (int z = 0; z < (PlaceLayer + 10); z++) { if (OutNode.DataMatrix[qi, y, z] != "0") { pn++; } } } if (pn != 0) { xe = qi + 2; break; } } for (int i = 1; i < BaseSize; i++) { int qi = BaseSize - 1 - i; int pn = 0; for (int x = 0; x < BaseSize; x++) { for (int z = 0; z < (PlaceLayer + 10); z++) { if (OutNode.DataMatrix[x, qi, z] != "0") { pn++; } } } if (pn != 0) { ye = qi + 2; break; } } for (int i = 1; i < (PlaceLayer + 10); i++) { int qi = (PlaceLayer + 10) - 1 - i; int pn = 0; for (int x = 0; x < BaseSize; x++) { for (int y = 0; y < BaseSize; y++) { if (OutNode.DataMatrix[x, y, qi] != "0") { pn++; } } } if (pn != 0) { ze = qi + 2; break; } } RouteUtils.Node OutNodeO = new RouteUtils.Node("OUT", xe - xs, ye - ys, ze - zs); for (int x = xs; x < xe; x++) { for (int y = ys; y < ye; y++) { for (int z = zs; z < ze; z++) { OutNodeO.DataMatrix[x - xs, y - ys, z - zs] = OutNode.DataMatrix[x, y, z]; } } } return OutNodeO; }