Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flatland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sfwatergit
Flatland
Commits
bfcd9ab5
Commit
bfcd9ab5
authored
5 years ago
by
gmollard
Browse files
Options
Downloads
Patches
Plain Diff
test for dead ends
parent
d70a3855
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_environments.py
+95
-2
95 additions, 2 deletions
tests/test_environments.py
with
95 additions
and
2 deletions
tests/test_environments.py
+
95
−
2
View file @
bfcd9ab5
...
...
@@ -34,7 +34,6 @@ def test_rail_environment_single_agent():
# Simple turn not in the base transitions ?
south_east_turn
=
int
(
'
0100000000000010
'
,
2
)
south_west_turn
=
transitions
.
rotate_transition
(
south_east_turn
,
90
)
# print(bytes(south_west_turn))
north_east_turn
=
transitions
.
rotate_transition
(
south_east_turn
,
270
)
north_west_turn
=
transitions
.
rotate_transition
(
south_east_turn
,
180
)
...
...
@@ -77,7 +76,7 @@ def test_rail_environment_single_agent():
valid_active_actions_done
+=
1
# After 6 movements on this railway network, the train should be back
# to its original
position
.
# to its original
height on the map
.
assert
(
initial_pos
[
0
]
==
rail_env
.
agents_position
[
0
][
0
])
# We check that the train always attains its target after some time
...
...
@@ -92,3 +91,97 @@ def test_rail_environment_single_agent():
_
,
_
,
dones
,
_
=
rail_env
.
step
({
0
:
action
})
done
=
dones
[
'
__all__
'
]
def
test_dead_end
():
transitions
=
Grid4Transitions
([])
straight_vertical
=
int
(
'
1000000000100000
'
,
2
)
# Case 1 - straight
straight_horizontal
=
transitions
.
rotate_transition
(
straight_vertical
,
90
)
dead_end_from_south
=
int
(
'
0010000000000000
'
,
2
)
# Case 7 - dead end
# We instantiate the following railway
# O->-- where > is the train and O the target. After 6 steps,
# the train should be done.
rail_map
=
np
.
array
(
[[
transitions
.
rotate_transition
(
dead_end_from_south
,
270
)]
+
[
straight_horizontal
]
*
3
+
[
transitions
.
rotate_transition
(
dead_end_from_south
,
90
)]],
dtype
=
np
.
uint16
)
rail
=
GridTransitionMap
(
width
=
rail_map
.
shape
[
1
],
height
=
rail_map
.
shape
[
0
],
transitions
=
transitions
)
rail
.
grid
=
rail_map
rail_env
=
RailEnv
(
rail
,
number_of_agents
=
1
)
def
check_consistency
(
rail_env
):
# We run step to check that trains do not move anymore
# after being done.
for
i
in
range
(
7
):
prev_pos
=
rail_env
.
agents_position
[
0
]
# The train cannot turn, so we check that when it tries,
# it stays where it is.
_
=
rail_env
.
step
({
0
:
1
})
_
=
rail_env
.
step
({
0
:
3
})
assert
(
rail_env
.
agents_position
[
0
]
==
prev_pos
)
_
,
_
,
dones
,
_
=
rail_env
.
step
({
0
:
2
})
if
i
<
5
:
assert
(
not
dones
[
0
]
and
not
dones
[
'
__all__
'
])
else
:
assert
(
dones
[
0
]
and
dones
[
'
__all__
'
])
# We try the configuration in the 4 directions:
rail_env
.
reset
()
rail_env
.
agents_target
[
0
]
=
[
0
,
0
]
rail_env
.
agents_position
[
0
]
=
[
0
,
2
]
rail_env
.
agents_direction
[
0
]
=
1
check_consistency
(
rail_env
)
rail_env
.
reset
()
rail_env
.
agents_target
[
0
]
=
[
0
,
4
]
rail_env
.
agents_position
[
0
]
=
[
0
,
2
]
rail_env
.
agents_direction
[
0
]
=
3
check_consistency
(
rail_env
)
# In the vertical configuration:
rail_map
=
np
.
array
(
[[
dead_end_from_south
]]
+
[[
straight_vertical
]]
*
3
+
[[
transitions
.
rotate_transition
(
dead_end_from_south
,
180
)]],
dtype
=
np
.
uint16
)
rail
=
GridTransitionMap
(
width
=
rail_map
.
shape
[
1
],
height
=
rail_map
.
shape
[
0
],
transitions
=
transitions
)
rail
.
grid
=
rail_map
rail_env
=
RailEnv
(
rail
,
number_of_agents
=
1
)
rail_env
.
reset
()
rail_env
.
agents_target
[
0
]
=
[
0
,
0
]
rail_env
.
agents_position
[
0
]
=
[
2
,
0
]
rail_env
.
agents_direction
[
0
]
=
2
check_consistency
(
rail_env
)
rail_env
.
reset
()
rail_env
.
agents_target
[
0
]
=
[
4
,
0
]
rail_env
.
agents_position
[
0
]
=
[
2
,
0
]
rail_env
.
agents_direction
[
0
]
=
0
check_consistency
(
rail_env
)
test_dead_end
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment