Example #1
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])
Example #2
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}] ')
Example #3
0
 def test_MazeFacade_NotEmpty(self):
     mazeFacade = MazeFacade(self.__mazeparser)
     self.assertTrue(mazeFacade.GetMatrix().any())