Ejemplo n.º 1
0
 def test_goals_exist(self):
     tasks, rows, cols = self.goals.shape
     for task in range(tasks):
         # find the positive goal state for the current task
         goal_loc = None
         for row in range(rows):
             for col in range(cols):
                 if self.goals[task, row, col] > 0:
                     goal_loc = grid.rowcol_to_index(self.maze, row, col)
         self.assertTrue(goal_loc != None)
Ejemplo n.º 2
0
Archivo: io.py Proyecto: deong/merlin
def write_maze_instance(maze, goals):
    tasks, rows, cols = goals.shape
    print("{} {} {}\n".format(rows*cols, 4, tasks))

    for row in range(rows):
        for col in range(cols):
            node_num = grd.rowcol_to_index(maze, row, col)
            line = "{} ".format(node_num)

            # order of actions is up, down, left, right
            neighbors = [(x, col) for x in [row-1, row+1]] + [(row, y) for y in [col-1, col+1]]
            for action, (x,y) in enumerate(neighbors):
                target = grd.rowcol_to_index(maze, x, y)
                if target != None:
                    line += "{} ".format(target)
                    for task in range(tasks):
                        line += "{} ".format(goals[task, x, y])
                else:
                    line += "{} ".format(node_num)
                    for task in range(tasks):
                        line += "{} ".format(-10)
            print(line)
    print("\n")