Commit 7ac889fb authored by u214892's avatar u214892
Browse files

#188 approaching...

parent 57fdc75f
Pipeline #2333 failed with stages
in 60 minutes
import numpy as np
from flatland.envs.agent_utils import EnvAgent
from flatland.envs.agent_utils import EnvAgent, RailAgentStatus
from flatland.envs.observations import GlobalObsForRailEnv
from flatland.envs.rail_env import RailEnv, RailEnvActions
from flatland.envs.rail_generators import sparse_rail_generator
......@@ -44,10 +44,11 @@ def test_get_global_observation():
obs_agents_state = obs[i][1]
obs_targets = obs[i][2]
#
# test first channel of obs_targets: own target
nr_agents = np.count_nonzero(obs_targets[:, :, 0])
assert nr_agents == 1
assert nr_agents == 1, "agent {}: something wrong with own target, found {}".format(i, nr_agents)
# test second channel of obs_targets: other agent's target
for r in range(env.height):
for c in range(env.width):
_other_agent_target = 0
......@@ -55,4 +56,24 @@ def test_get_global_observation():
if other_agent.target == (r, c):
_other_agent_target = 1
break
assert obs_targets[(r, c)][1] == _other_agent_target, "agent {} at {} expected {}".format(i, (r,c), _other_agent_target)
assert obs_targets[(r, c)][
1] == _other_agent_target, "agent {}: at {} expected to be other agent's target = {}".format(
i, (r, c),
_other_agent_target)
# test first channel of obs_agents_state: direction at own position
for r in range(env.height):
for c in range(env.width):
if (agent.status == RailAgentStatus.ACTIVE or agent.status == RailAgentStatus.DONE) and (
r, c) == agent.position:
assert np.isclose(obs_agents_state[(r, c)][0], agent.direction), \
"agent {} in status {} at {} expected to contain own direction {}, found {}" \
.format(i, agent.status, (r, c), agent.direction, obs_agents_state[(r, c)][0])
elif (agent.status == RailAgentStatus.READY_TO_DEPART) and (r, c) == agent.initial_position:
assert np.isclose(obs_agents_state[(r, c)][0], agent.direction), \
"agent {} in status {} at {} expected to contain own direction {}, found {}" \
.format(i, agent.status, (r, c), agent.direction, obs_agents_state[(r, c)][0])
else:
assert np.isclose(obs_agents_state[(r, c)][0], -1), \
"agent {} in status {} at {} expected contain -1 found {}" \
.format(i, agent.status, (r, c), obs_agents_state[(r, c)][0])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment