예제 #1
0
 def test_GetAntWorldImage_NoObs_Center_2(self):
     mazeparser = DIYMazeParser(5)
     mazeparser.SetExits([Position(4, 4)])
     mazefacade = MazeFacade(mazeparser)
     WorldImageProvider = SimpleWorldImageProvider(self.__Config,
                                                   mazefacade)
     ant = RemoteControlledAnt(1, self.__Config)
     ant.UpdatePosition(position=Position(2, 1))
     antworldimage = WorldImageProvider.GetAntWorldImage(ant)
     self.assertTrue(len(antworldimage.VisibleNodes) == 20)
예제 #2
0
 def test_UpdateStep_SeeObs(self):
     mazeparser = DIYMazeParser(5)
     mazeparser.SetExits([Position(4, 4)])
     mazeparser.SetObs([Position(3, 3)])
     mazefacade = MazeFacade(mazeparser)
     WorldImageProvider = SimpleWorldImageProvider(self.__Config,
                                                   mazefacade)
     ant = RemoteControlledAnt(1, self.__Config)
     ant.UpdatePosition(position=Position(4, 4))
     WorldImageProvider.ProcessStep(ant, AntStep(1, Position(4, 4)))
     WorldImageProvider.UpdatePositionsAccordingToMoves()
     antworldimage = WorldImageProvider.GetAntWorldImage(ant)
     obsList = list(
         filter(lambda x: x.NodeState == NodeStateEnum.Obs,
                antworldimage.VisibleNodes))
     self.assertTrue(len(obsList) == 1)
예제 #3
0
	def test__CalculatePathToDestination_UniformGrid(self):
		Maze = MazeFacade(DIYMazeParser(8))
		Provider = UnifiedWorldImageProvider(maze=Maze, config=DictionaryConfigProvider())

		weights = {NodeStateEnum.Clear: 2,
				   NodeStateEnum.Obs: np.inf,
				   NodeStateEnum.UnExplored: 1,
				   NodeStateEnum.Ant: np.inf}

		Planner = AntPathPlanner(safetyRadius=2, cellTypeWeights=weights, stabilityFactor=1)
		StartPosition = Position(0, 0)
		mazeMatrix = Maze.GetMatrix()
		manuallyAdjustedMaze = np.where(mazeMatrix == 1, NodeStateEnum.UnExplored, NodeStateEnum.Clear)
		manuallyAdjustedMaze[0, 0] = NodeStateEnum.Clear
		singleAntWorldImage = SimpleSingleAntWorldImage(manuallyAdjustedMaze, {})
		weightedMatrix = Planner._AntPathPlanner__ConvertWorldImageToWeightedMatrix(StartPosition, singleAntWorldImage)
		pathMatrix = Dijkstra(weightedMatrix, StartPosition)

		resultRoute = Planner._AntPathPlanner__CalculatePathToDestination(StartPosition, Position(4, 4), pathMatrix)

		weightSum = 0

		for position in resultRoute:
			weightSum += weightedMatrix[position.X][position.Y]
			self.assertEqual(pathMatrix[position.X][position.Y], weightSum)

		def printRoute(route):
			for position in route:
				print(f'[{position.X}, {position.Y}] ')
예제 #4
0
	def test__ConvertWorldImageToWeightedMatrix_EmptyGrid(self):
		Maze = MazeFacade(DIYMazeParser(8))
		Provider = UnifiedWorldImageProvider(maze=Maze, config=DictionaryConfigProvider())

		weights = {NodeStateEnum.Clear: 2,
				   NodeStateEnum.Obs: np.inf,
				   NodeStateEnum.UnExplored: 1,
				   NodeStateEnum.Ant: np.inf}

		Planner = AntPathPlanner(safetyRadius=2, cellTypeWeights=weights, stabilityFactor=1)
		StartPosition = Position(0, 0)
		mazeMatrix = Maze.GetMatrix()
		manuallyAdjustedMaze = np.where(mazeMatrix == 1, NodeStateEnum.UnExplored, NodeStateEnum.Clear)
		manuallyAdjustedMaze[0, 0] = NodeStateEnum.Clear
		singleAntWorldImage = SimpleSingleAntWorldImage(manuallyAdjustedMaze, {})
		result = Planner._AntPathPlanner__ConvertWorldImageToWeightedMatrix(StartPosition, singleAntWorldImage)

		Width, Height = result.shape

		for i in range(0, Width):
			for j in range(0, Height):
				if i == 0 and j == 0:
					self.assertEqual(result[i][j], weights[NodeStateEnum.Clear])
				else:
					self.assertEqual(result[i][j], weights[NodeStateEnum.UnExplored])
예제 #5
0
def test_SingleScout(self):
	Maze = MazeFacade(DIYMazeParser(8))
	Provider = UnifiedWorldImageProvider(maze=Maze, config=DictionaryConfigProvider())

	weights = {NodeStateEnum.Clear: 2,
			   NodeStateEnum.Obs: np.inf,
			   NodeStateEnum.UnExplored: 1,
			   NodeStateEnum.Ant: np.inf}

	ant = AlgoAnt(id=1, config=DictionaryConfigProvider(), position=Position(3, 3))

	Provider.ProcessStep(ant, AntStep(ant.ID, ant.CurrentPosition))
	Provider.UpdatePositionsAccordingToMoves()
	Planner = AntPathPlanner(safetyRadius=0, cellTypeWeights=weights)

	result = Planner._AntPathPlanner__ConvertWorldImageToWeightedMatrix(Position(0, 0),
																		Provider.GetAntWorldImage(ant))

	print(result)