Esempio n. 1
0
        private IEnumerable <List <Location> > RouteClassic(bool forward, IEnumerable <Location> startLocations, Location targetLocation, int distanceLimit, int maxDepth, LocationManager locMan)
        {
            Tile intTile = targetLocation.Tile;// FPGATypes.GetInterconnectTile(targetLocation.Tile);

            while (locMan.LocationsLeft())
            {
                Location currentLocation = locMan.GetNext();

                int depth = locMan.GetDepth(currentLocation, maxDepth);
                if (depth > maxDepth)
                {
                    continue;
                }

                /*
                 * List<Tuple<Location, int>> reachables = new List<Tuple<Location, int>>();
                 * foreach (Location r in RouteNet.GetReachableLocations(currentLocation, forward))
                 * {
                 *  if (r.Tile.Location.Equals(currentLocation.Tile.Location))
                 *  {
                 *      int distance = Navigator.GetDestinations(r.Tile, r.Pip).Any() ? Navigator.GetDestinations(r.Tile, r.Pip).Min(l => RouteNet.Distance(l.Tile, targetLocation.Tile)) : 0;
                 *      reachables.Add(new Tuple<Location,int>(r, distance));
                 *  }
                 *  else
                 *  {
                 *      reachables.Add(new Tuple<Location, int>(r, RouteNet.Distance(r.Tile, targetLocation.Tile)));
                 *  }
                 * }
                 *
                 * foreach (Tuple<Location, int> tuple in reachables.OrderByDescending(t => t.Item2))
                 * */
                foreach (Location next in GetReachableLocations(currentLocation, forward))
                {
                    //Location next = tuple.Item1;
                    if (targetLocation.Equals(next))
                    {
                        List <Location> revPath = locMan.GetPath(startLocations, currentLocation);
                        revPath.Add(next);
                        yield return(revPath);
                    }
                    else
                    {
                        bool close = LocationLeadsCloserToTarget(currentLocation, next, targetLocation.Tile, distanceLimit);

                        //if (!visited.ContainsKey(next) && close)
                        if (!locMan.WasAlreadyVisited(next) && close)
                        {
                            locMan.MarkAsVisited(next, currentLocation);
                            //parent.Add(next, currentLocation);
                            locMan.Add(next);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private IEnumerable <List <Location> > RouteLocal(bool forward, IEnumerable <Location> startLocations, Location targetLocation, int distanceLimit, int maxDepth, Location startLocation, LocationManager locMan)
        {
            while (locMan.LocationsLeft())
            {
                Location currentLocation = locMan.GetNext();

                if (currentLocation.Path != null)
                {
                    if (currentLocation.Path.Count > maxDepth)
                    {
                        // save memory
                        currentLocation.Path.Clear();
                        continue;
                    }
                }

                foreach (Location l in GetReachableLocations(currentLocation, forward))
                {
                    bool targetReached = targetLocation.Equals(l);

                    // TODO when LOGICIN und auf Interconnect der Zielkachel, versuche direkt bis uzm Ziel zu routen

                    if (targetReached)
                    {
                        // as we empty the list, return a copy
                        if (currentLocation.Path == null)
                        {
                            currentLocation.Path = new List <Location>();
                            //currentLocation.Path.Add(
                            // TODO single step paths a la INT_X10Y105.EE2BEG0
                        }
                        List <Location> copy = new List <Location>(currentLocation.Path);
                        copy.Add(l);
                        yield return(copy);
                    }
                    else
                    {
                        bool close = LocationLeadsCloserToTarget(currentLocation, l, targetLocation.Tile, distanceLimit);

                        //this.Watch.Start("compare");
                        // same tile
                        bool targetTile = l.Tile.LocationX == targetLocation.Tile.LocationX && l.Tile.LocationY == targetLocation.Tile.LocationY;
                        bool startTile  = l.Tile.LocationX == startLocation.Tile.LocationX && l.Tile.LocationY == startLocation.Tile.LocationY;
                        bool useTile    = targetTile || startTile;
                        if (!useTile)
                        {
                            // if we are not on target tile, only accept interconnects
                            useTile = IdentifierManager.Instance.IsMatch(l.Tile.Location, IdentifierManager.RegexTypes.Interconnect) && !l.Pip.Name.StartsWith("LOGICIN_");
                        }
                        //this.Watch.Stop("compare");

                        //this.Watch.Start("add");
                        bool add = false;
                        // prevent use less comprae (see if)
                        if (useTile)
                        {
                            add = currentLocation.Path == null ? true : !currentLocation.Path.Contains(l) && close;
                        }
                        //this.Watch.Stop("add");

                        if (add && useTile)
                        {
                            l.Path = new List <Location>();
                            if (currentLocation.Path != null)
                            {
                                l.Path.AddRange(currentLocation.Path);
                            }
                            l.Path.Add(currentLocation);
                            locMan.Add(l);
                        }
                    }
                }

                if (currentLocation.Path != null)
                {
                    // save memory
                    currentLocation.Path.Clear();
                }
            }
        }