public void TestIsDistanceToGoal()
        {
            //Arrange
            var unitOfWork = new UnitOfWork(new DtsContext());
            var target     = unitOfWork.NavigationPoints.GetSingle(Guid.Parse("FC284FE6-73E1-42AC-9409-6267F4BAB607"));
            var drone      = new Drone
            {
                CurrentPoint = new NavigationPoint
                {
                    Id           = target.Id,
                    XNeighbourId = target.XNeighbourId,
                    ZNeighbourId = target.ZNeighbourId
                },
                TargetPoint = new NavigationPoint
                {
                    Id = Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A"),
                }
            };

            unitOfWork.Dispose();

            //Act
            var result = NavigationLogic.IsDistanceToGoal(drone);

            //Assert
            Assert.True(result, "The result came out false");
        }
        public void TestDetermineNextPoint()
        {
            //Arrange
            var unitOfWork = new UnitOfWork(new DtsContext());
            var droneOne   = new Drone
            {
                CurrentPoint = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("B19C9EF8-3CF5-4A85-A0F7-4D516E9FD53C"))),
                TargetPoint  = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A")))
            };
            var xPointOne = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(droneOne.CurrentPoint.XNeighbourId));
            var zPointOne = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(droneOne.CurrentPoint.ZNeighbourId));

            var droneTwo = new Drone
            {
                CurrentPoint = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("EAFB1408-C53F-449D-9856-4B18BF32B861"))),
                TargetPoint  = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A")))
            };
            var xPointTwo = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(droneTwo.CurrentPoint.XNeighbourId));
            var zPointTwo = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(droneTwo.CurrentPoint.ZNeighbourId));

            unitOfWork.Dispose();

            //Act
            var resultOne = NavigationLogic.DetermineNextPoint(droneOne, xPointOne, zPointOne);
            var resultTwo = NavigationLogic.DetermineNextPoint(droneTwo, xPointTwo, zPointTwo);

            //Assert
            Assert.IsNotNull(resultOne, "A navigation point was not selected for result one");
            Assert.AreEqual(xPointOne, resultOne, "The x coordinate was selected");
            Assert.IsNotNull(resultTwo, "A navigation point was not selected for result two");
            Assert.AreEqual(zPointTwo, resultTwo, "The z coordinate was selected");
        }
        public void TestGenerateRoute()
        {
            //Arrange
            var unitOfWork = new UnitOfWork(new DtsContext());
            var drone      = new Drone
            {
                TargetPoint  = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A"))),
                CurrentPoint = new NavigationPoint(unitOfWork.NavigationPoints.GetSingle(Guid.Parse("161E22AE-B152-4D7F-AC68-58201EF025DA")))
            };
            var route = new List <NavigationPoint>
            {
                drone.CurrentPoint,
                drone.TargetPoint
            };
            var droneRandom = new Drone
            {
                TargetPoint  = new NavigationPoint(unitOfWork.NavigationPoints.GetRandom(Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A"))),
                CurrentPoint = new NavigationPoint(unitOfWork.NavigationPoints.GetRandom(Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A"))),
            };
            var routeRandom = new List <NavigationPoint>
            {
                droneRandom.CurrentPoint,
                droneRandom.TargetPoint
            };

            File.AppendAllText(
                @"C:\Users\Jack\Documents\Fourth Year\Fourth Year Project\2017-ca400-murpj238\docs\blog\RandomNavigationPoints.csv",
                "TestGenerateNavigationPoint," + droneRandom.TargetPoint.Id + "," + droneRandom.TargetPoint.XPosition + "," +
                droneRandom.TargetPoint.ZPosition + "," + droneRandom.TargetPoint.Id + "," +
                droneRandom.CurrentPoint.XPosition + "," + droneRandom.CurrentPoint.ZPosition + "\n");
            //Act
            var result = NavigationLogic.GenerateRoute(drone, route,
                                                       unitOfWork.NavigationPoints.GetNaviationPoints().Where(x => x.Id != drone.TargetPoint.Id).ToList(), 0);
            var resultRandom = NavigationLogic.GenerateRoute(droneRandom, routeRandom,
                                                             unitOfWork.NavigationPoints.GetNaviationPoints().Where(x => x.Id != droneRandom.TargetPoint.Id)
                                                             .ToList(), 0);

            //Assert
            Assert.IsNotEmpty(result, "The list does not contain any values");
            Assert.AreEqual(result.Last(), drone.TargetPoint, "The last value should be the target point");
            Assert.Greater(route.Count, 2, "The route only contains the start and finish points");
            Assert.AreEqual(35, result.Count, "The list has too many or too few points");
            Assert.True(result.Any(x => x.Id == Guid.Parse("e378a340-b368-4cc1-b412-28ed418a3d24")), "This point does not exist in the list");
            Assert.IsNotEmpty(resultRandom, "The route returned empty");
            Assert.True(result.Any(x => x.Id == Guid.Parse("B955D974-2D5C-45A3-AEBA-009AD23BAC3A")));

            unitOfWork.Dispose();
        }
Exemplo n.º 4
0
        //Generate a list of navigation points for the drones
        public static List <NavigationPoint> GenerateRoute(Drone drone, List <NavigationPoint> result, List <NavigationPoints> navigationPoints, int targetReached)
        {
            if (result.Count == 2)
            {
                _originalList = navigationPoints;
            }
            var isDistanceToGoal = IsDistanceToGoal(drone);

            targetReached = isDistanceToGoal ? Math.Abs(targetReached - 1) : targetReached + 0;
            if (!isDistanceToGoal)
            {
                var xPoint = navigationPoints.Any(x => x.Id == drone.CurrentPoint.XNeighbourId)
                    ? new NavigationPoint(navigationPoints.FirstOrDefault(x => x.Id == drone.CurrentPoint.XNeighbourId))
                    : null;
                var zPoint = navigationPoints.Any(x => x.Id == drone.CurrentPoint.ZNeighbourId)
                    ? new NavigationPoint(navigationPoints.FirstOrDefault(x => x.Id == drone.CurrentPoint.ZNeighbourId))
                    : null;
                navigationPoints = navigationPoints.Where(x => x.Id != drone.CurrentPoint.Id).ToList();
                if (xPoint == null && zPoint == null)
                {
                    xPoint = drone.CurrentPoint.XNeighbourId.Equals(Guid.Empty)
                        ? null
                        : new NavigationPoint(_originalList.Find(x => x.Id == drone.CurrentPoint.XNeighbourId));
                    zPoint = drone.CurrentPoint.ZNeighbourId.Equals(Guid.Empty)
                        ? null
                        : new NavigationPoint(_originalList.Find(x => x.Id == drone.CurrentPoint.ZNeighbourId));
                }
                drone.CurrentPoint = DetermineNextPoint(drone, xPoint, zPoint);
                result.Insert(result.Count - 1, drone.CurrentPoint);
            }
            if (targetReached == 1)
            {
                drone.CurrentPoint = drone.TargetPoint;
                drone.TargetPoint  = result.First();
                targetReached     *= -1;
                navigationPoints   = _originalList;
                result.Add(drone.TargetPoint);
            }
            return(targetReached == 2 ? result : GenerateRoute(drone, result, navigationPoints, targetReached));
        }
Exemplo n.º 5
0
 //Check has the goal been reached yet
 public static bool IsDistanceToGoal(Drone drone)
 {
     return(drone.CurrentPoint.XNeighbourId.Equals(drone.TargetPoint.Id) ||
            drone.CurrentPoint.ZNeighbourId.Equals(drone.TargetPoint.Id));
 }
Exemplo n.º 6
0
        //Determine the next point to choose
        public static NavigationPoint DetermineNextPoint(Drone drone, NavigationPoint xPoint, NavigationPoint zPoint)
        {
            if (xPoint == null)
            {
                return(zPoint);
            }
            if (zPoint == null)
            {
                return(xPoint);
            }
            var currentStreets = drone.CurrentPoint.Streets;
            var targetStreets  = drone.TargetPoint.Streets;

            if (drone.TargetPoint.XPosition < drone.CurrentPoint.XPosition &&
                drone.TargetPoint.ZPosition < drone.CurrentPoint.ZPosition)
            {
                if (currentStreets.Any(x => x.Direction.Equals("Right")) &&
                    currentStreets.Any(x => x.Direction.Equals("Up")))
                {
                    return(NearestToTargetPoint(drone.TargetPoint, xPoint, zPoint));
                }
                if (currentStreets.Any(x => x.Direction.Equals("Left")) &&
                    currentStreets.Any(x => x.Direction.Equals("Up")))
                {
                    return(zPoint);
                }
                if (currentStreets.Any(x => x.Direction.Equals("Right")) &&
                    currentStreets.Any(x => x.Direction.Equals("Down")))
                {
                    return(xPoint);
                }
                return(targetStreets.Any(x => x.Direction.Equals("Down") && x.Direction.Equals("Right"))
                    ? zPoint
                    : xPoint);
            }
            if (drone.TargetPoint.XPosition > drone.CurrentPoint.XPosition &&
                drone.TargetPoint.ZPosition < drone.CurrentPoint.ZPosition)
            {
                if (currentStreets.Any(x => x.Direction.Equals("Right")) &&
                    currentStreets.Any(x => x.Direction.Equals("Down")))
                {
                    return(NearestToTargetPoint(drone.TargetPoint, xPoint, zPoint));
                }
                if (currentStreets.Any(x => x.Direction.Equals("Left")) &&
                    currentStreets.Any(x => x.Direction.Equals("Down")))
                {
                    return(zPoint);
                }
                if (currentStreets.Any(x => x.Direction.Equals("Right")) &&
                    currentStreets.Any(x => x.Direction.Equals("Up")))
                {
                    return(xPoint);
                }
                return(targetStreets.Any(x => x.Direction.Equals("Left")) ? xPoint : zPoint);
            }
            if (drone.TargetPoint.XPosition < drone.CurrentPoint.XPosition &&
                drone.TargetPoint.ZPosition > drone.CurrentPoint.ZPosition)
            {
                if (currentStreets.Any(x => x.Direction.Equals("Left")) &&
                    currentStreets.Any(x => x.Direction.Equals("Up")))
                {
                    return(NearestToTargetPoint(drone.TargetPoint, xPoint, zPoint));
                }
                if (currentStreets.Any(x => x.Direction.Equals("Right")) &&
                    currentStreets.Any(x => x.Direction.Equals("Up")))
                {
                    return(zPoint);
                }
                if (currentStreets.Any(x => x.Direction.Equals("Left")) &&
                    currentStreets.Any(x => x.Direction.Equals("Down")))
                {
                    return(xPoint);
                }
                return(targetStreets.Any(x => x.Direction.Equals("Right") && x.Direction.Equals("Down"))
                    ? xPoint
                    : zPoint);
            }
            if (drone.TargetPoint.XPosition > drone.CurrentPoint.XPosition &&
                drone.TargetPoint.ZPosition > drone.CurrentPoint.ZPosition)
            {
                if (currentStreets.Any(x => x.Direction.Equals("Left")) &&
                    currentStreets.Any(x => x.Direction.Equals("Down")))
                {
                    return(NearestToTargetPoint(drone.TargetPoint, xPoint, zPoint));
                }
                if (currentStreets.Any(x => x.Direction.Equals("Right")) &&
                    currentStreets.Any(x => x.Direction.Equals("Down")))
                {
                    return(zPoint);
                }
                if (currentStreets.Any(x => x.Direction.Equals("Left")) &&
                    currentStreets.Any(x => x.Direction.Equals("Up")))
                {
                    return(xPoint);
                }
                return(targetStreets.Any(x => x.Direction.Equals("Left") && x.Direction.Equals("Up")) ? zPoint : xPoint);
            }
            return(NearestToTargetPoint(drone.TargetPoint, xPoint, zPoint));
        }