static List <Point> Autoroute(AutoroutingMap map, AutoroutingNet net, List <AutoroutingNet> netIdsInTheWay = null) { Func <Point, float> costEvaluator = delegate(Point to) { if (to.X == net.End.X && to.Y == net.End.Y || to.X == net.Start.X && to.Y == net.Start.Y) { return(1); } else if (map.tiles[to.X, to.Y].Net != null) { if (netIdsInTheWay != null && !netIdsInTheWay.Contains(map.tiles[to.X, to.Y].Net)) { netIdsInTheWay.Add(map.tiles[to.X, to.Y].Net); } return(float.PositiveInfinity); } else { return(map.tiles[to.X, to.Y].Cost); } }; if (net.Start.Net != null && net.Start.Net != net) { return(null); } if (net.End.Net != null && net.End.Net != net) { return(null); } net.Start.Net = null; net.End.Net = null; var aStarResult = CornersReductedAStar.Find(map.Width, map.Height, costEvaluator, net.Start.X, net.Start.Y, net.End.X, net.End.Y); if (aStarResult != null) { foreach (Point p in aStarResult) { map.tiles[p.X, p.Y].Net = net; } } return(aStarResult); }
public AutoroutingNet GetSameNetIn(AutoroutingMap map) { return(map.tiles[Start.X, Start.Y].Net); }
static Dictionary <Conveyor, List <Point> > GetAutoroutingSolution(Map originalMap, Conveyor originalNet) { //originalMap.Remove(originalNet); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); bool autorouteSuccess = false; List <Conveyor> netIdsInTheWay = GetNetsInTheWay(originalMap, originalNet, out autorouteSuccess); if (netIdsInTheWay.Contains(null)) { } int bestCost = Int32.MaxValue; Conveyor[] bestPermutation = null; List <List <Point> > bestRouting = null; List <Conveyor> netsToPermute = new List <Conveyor>(); netsToPermute.AddRange(netIdsInTheWay); netsToPermute.Add(originalNet); Parallel.ForEach <IEnumerable <Conveyor> >(netsToPermute.GetPermutations(), permutation => { if (stopwatch.ElapsedMilliseconds >= 50 && (bestCost < Int32.MaxValue)) { return; } else if (stopwatch.ElapsedMilliseconds >= 500) { return; } AutoroutingMap possibleMap = new AutoroutingMap(originalMap); AutoroutingNet originalNet2 = new AutoroutingNet(); originalNet2.Start = possibleMap.tiles[originalNet._start.X, originalNet._start.Y]; originalNet2.End = possibleMap.tiles[originalNet._end.X, originalNet._end.Y]; foreach (Conveyor x in netIdsInTheWay) { possibleMap.RipupNet(x); } possibleMap.RipupNet(originalNet2); int cost = 0; List <List <Point> > routing = new List <List <Point> >(); foreach (Conveyor n in permutation) { List <Point> result = Autoroute(possibleMap, possibleMap.tiles[n._start.X, n._start.Y].Net); if (result == null) { return; //Bad permutation, can't route everything } routing.Add(result); cost += result.Count; } if (cost < bestCost) { bestCost = cost; bestRouting = routing; bestPermutation = permutation.ToArray(); } }); Dictionary <Conveyor, List <Point> > ret = new Dictionary <Conveyor, List <Point> >(); if (bestCost != Int32.MaxValue) { for (int i = 0; i < bestPermutation.Length; i++) { if (bestPermutation[i] == originalNet) { ret.Add(originalNet, bestRouting[i]); } else { ret.Add(bestPermutation[i], bestRouting[i]); } } return(ret); } else { return(null); } }