Skip to content

Pathfinding bug (binary domain / calc_longest_path) #12

@smearle

Description

@smearle

The following code returns a sub-optimal path:

import gym
import numpy as np

import gym_pcgrl
from gym_pcgrl.envs.helper import get_string_map


maze = np.array([[0, 0],
                 [0, 0],
                 [0, 1],])

env_name = "binary-narrow-v0"
env = gym.make(env_name)
stats = env.unwrapped._prob.get_stats(
    get_string_map(maze, env.unwrapped._prob.get_tile_types()),
)
print(stats)

This prints {'regions': 1, 'path-length': 2}, but the maximum path length is 3 (from bottom left to top right).

In calc_longest_path, the empty tile (0, 0) is chosen as the source of a call to run_dijkstra. This returns the following dijkstra map:

0 1
1 2
2 -1

. The extremities relative to this tile are tiles (1, 1) and (2, 0), which are both 2 away from (0, 0). But (1, 1) is chosen as the source of the next call to dijkstra, which results in:

2 1
1 0
2 -1

, giving a path-length of 2.

If instead (2, 0) was chosen as the source of the second call to dijkstra, we would have:

2 3
1 2
0 -1

, resulting in a path-length of 3.

One obvious fix would be to call dijkstra from each of the extremities that results from the first search, then record the maximum path-length over these. Is there any faster way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions