public void FindRouteStartIsEnd()
        {
            var result = RouteFinder.FindRoute(
                Vector.Create(1, 1), Vector.Create(1, 1), vector => true);

            Assert.IsFalse(result.HasValue);
        }
        private static void AssertPathFromMap(
            string[] map, Vector from, Vector to, IEnumerable <Vector> expected)
        {
            var result = RouteFinder.FindRoute(
                from, to, vector => IsValidMove(map, vector));

            AssertPath(expected, result);
        }
示例#3
0
        public void OriginDestinationWaypointsTheSameShouldThrow()
        {
            var w = new Waypoint("1", 0.0, 1.0);

            var wptList = GetWptList(w);
            int i       = wptList.FindByWaypoint(w);
            var finder  = new RouteFinder(wptList);

            Assert.Throws <ArgumentException>(() => finder.FindRoute(i, i));
        }
        public void FindRouteNoWalls()
        {
            var result = RouteFinder.FindRoute(
                Vector.Create(1, 1), Vector.Create(1, 3), vector => true);

            Assert.IsTrue(result.HasValue);

            AssertPath(
                new [] { Vector.Create(1, 2), Vector.Create(1, 3) },
                result);
        }
        public ActionResult <BusScheduleInfo> GetSchedule([FromQuery] string from, string to, string start)
        {
            var         data      = reader.ReadBusScheduleAsync();
            var         routes    = parser.ParseBusSchedule(data.Result);
            RouteFinder finder    = new RouteFinder(routes);
            var         routeInfo = finder.FindRoute(from, to, start);

            if (routeInfo == null)
            {
                return(NotFound());
            }
            return(Ok(routeInfo));
        }
示例#6
0
        /// <exception cref="RouteNotFoundException"></exception>
        /// <exception cref="ArgumentException"></exception>
        private Route GetRouteWaypointToWaypoint()
        {
            EnsureOrigWptExists();
            EnsureDestWptExists();

            var fuelModel = model.FuelPlanningModel;

            var finder = new RouteFinder(
                fuelModel.AirwayNetwork.WptList,
                fuelModel.CheckedCountryCodes.Instance,
                model.WindCalc());

            return(finder.FindRoute(OrigWaypointIndex, DestWaypointIndex));
        }
        public void FindRouteNoValidPath()
        {
            var map =
                new[]
            {
                "     ",
                "+++++",
                "     ",
            };

            var result = RouteFinder.FindRoute(
                Vector.Create(0, 0), Vector.Create(4, 2),
                vector => IsValidMove(map, vector));

            Assert.IsFalse(result.HasValue);
        }
        public void FindRouteHitBreakLimit()
        {
            var map =
                new[]
            {
                "     ",
                "     ",
                "     ",
            };

            var result = RouteFinder.FindRoute(
                Vector.Create(0, 0), Vector.Create(4, 2),
                vector => IsValidMove(map, vector),
                3.ToSome());

            Assert.IsFalse(result.HasValue);
        }
        private Route FindRoute(IReadOnlyList <SubRoute> analyzed, int index)
        {
            var routeFinder = new RouteFinder(wptList);

            if (index == 0)
            {
                if (index == analyzed.Count - 1)
                {
                    return(new RouteFinderFacade(wptList, airportList)
                           .FindRoute(
                               origIcao, origRwy, sids, sids.GetSidList(origRwy),
                               destIcao, destRwy, stars, stars.GetStarList(destRwy)));
                }
                else
                {
                    int wptTo = wptList.FindByWaypoint(analyzed[index + 1].Route.FirstWaypoint);

                    return(new RouteFinderFacade(wptList, airportList)
                           .FindRoute(origIcao, origRwy, sids, sids.GetSidList(origRwy), wptTo));
                }
            }
            else
            {
                if (index == analyzed.Count - 1)
                {
                    int wptFrom = wptList.FindByWaypoint(analyzed[index - 1].Route.LastWaypoint);

                    return(new RouteFinderFacade(wptList, airportList)
                           .FindRoute(wptFrom, destIcao, destRwy, stars, stars.GetStarList(destRwy)));
                }
                else
                {
                    int wptFrom = wptList.FindByWaypoint(analyzed[index - 1].Route.LastWaypoint);
                    int wptTo   = wptList.FindByWaypoint(analyzed[index + 1].Route.FirstWaypoint);
                    return(routeFinder.FindRoute(wptFrom, wptTo));
                }
            }
        }
        public void FindRouteComplex()
        {
            var map =
                new[]
            {
                "               ",
                "+++++++++++    ",
                "   +      + +++",
                "   + ++ + +    ",
                "   + +  + ++++ ",
                "   ++++++ +    ",
                "   +      + +++",
                "   + ++++++    ",
                "     +   +++++ ",
                "       +       "
            };

            var result = RouteFinder.FindRoute(
                Vector.Create(6, 4), Vector.Create(0, 0),
                vector => IsValidMove(map, vector));

            Assert.IsTrue(result.HasValue);
        }
示例#11
0
    public Route GetRoute(Vector2 origin, Vector2 target, int clearance)
    {
        // The supplied points are the centre of an object.
        // The annotations assume an object growing up and right. As such, offset by half the clearance
        // to find the actual tile to search from.
        float   offset    = ((float)clearance * m_cellSize) / 2.0f;
        Vector2 offsetVec = new Vector2(offset, offset);

        origin -= offsetVec;
        target -= offsetVec;

        Point startCell = GetCellIndices(origin);
        Point endCell   = GetCellIndices(target);

        Vector2 finalCellPos;

        GetCellLocation(endCell.x, endCell.y, out finalCellPos);

        // Out of bounds
        if (startCell == null || endCell == null)
        {
            return(null);
        }

        // TODO: Not this. Obviously.
        RouteFinder routeFinder = new RouteFinder(m_numCellsX * m_numCellsY);

        // Use (clearance + 1) to allow in-cell movement. It effectively adds a cell of buffer.
        Route result = routeFinder.FindRoute(m_defaultGraph, m_defaultNodes[startCell.x][startCell.y], m_defaultNodes[endCell.x][endCell.y], clearance + 1);

        // Set the offset used in the search, so the calling function can reconstruct the centres used.
        result.OffsetVector = offsetVec;

        result.FinalOffset = target - finalCellPos;

        return(result);
    }
示例#12
0
 private static IEnumerable <Tuple <Vector2, Vector2> > FindRoute(Vector2 startingBuilding,
                                                                  Vector2 destinationBuilding, IEnumerable <Tuple <Vector2, Vector2> > roads)
 {
     return(RouteFinder.FindRoute(startingBuilding, destinationBuilding, roads));
 }