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
pranjal_dhole
Flatland
Commits
1a4aea23
Commit
1a4aea23
authored
5 years ago
by
u214892
Browse files
Options
Downloads
Patches
Plain Diff
unit test for env_utils, cleanup predictions
parent
8a9ba90d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
flatland/envs/env_utils.py
+18
-6
18 additions, 6 deletions
flatland/envs/env_utils.py
flatland/envs/predictions.py
+1
-1
1 addition, 1 deletion
flatland/envs/predictions.py
tests/test_env_utils.py
+21
-0
21 additions, 0 deletions
tests/test_env_utils.py
with
40 additions
and
7 deletions
flatland/envs/env_utils.py
+
18
−
6
View file @
1a4aea23
...
...
@@ -71,30 +71,42 @@ def validate_new_transition(rail_trans, rail_array, prev_pos, current_pos, new_p
return
rail_trans
.
is_valid
(
new_trans
)
def
position_to_coordinate
(
wid
th
,
position
):
def
position_to_coordinate
(
dep
th
,
position
):
"""
[ (0,0) (0,1) .. (0,w)
(1,0) (1,1) (1,w)
...
(
d
,
0
)
(
d
,
1
)
(
d
,
w
)
]
:param width:
-->
[ 0 1 .. w
w+1 w+2 .. 2w
...
d
*
w
+
1
d
*
w
+
:param depth:
:param position:
:return:
"""
coords
=
()
for
p
in
position
:
coords
=
coords
+
((
int
(
p
)
%
wid
th
,
int
(
p
)
//
wid
th
),)
# changed x_dim to y_dim
coords
=
coords
+
((
int
(
p
)
%
dep
th
,
int
(
p
)
//
dep
th
),)
# changed x_dim to y_dim
return
coords
def
coordinate_to_position
(
wid
th
,
coords
):
def
coordinate_to_position
(
dep
th
,
coords
):
"""
Helper function to
:param
wid
th:
:param
dep
th:
:param coords:
:return:
"""
position
=
np
.
empty
(
len
(
coords
),
dtype
=
int
)
idx
=
0
for
t
in
coords
:
position
[
idx
]
=
int
(
t
[
1
]
*
wid
th
+
t
[
0
])
position
[
idx
]
=
int
(
t
[
1
]
*
dep
th
+
t
[
0
])
idx
+=
1
return
position
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/predictions.py
+
1
−
1
View file @
1a4aea23
...
...
@@ -112,7 +112,7 @@ class ShortestPathPredictorForRailEnv(PredictionBuilder):
agents
=
self
.
env
.
agents
if
handle
:
agents
=
[
self
.
env
.
agents
[
handle
]]
assert
custom_args
assert
custom_args
is
not
None
distance_map
=
custom_args
.
get
(
'
distance_map
'
)
assert
distance_map
is
not
None
...
...
This diff is collapsed.
Click to expand it.
tests/test_env_utils.py
0 → 100644
+
21
−
0
View file @
1a4aea23
import
numpy
as
np
from
flatland.envs.env_utils
import
position_to_coordinate
,
coordinate_to_position
depth_to_test
=
5
positions_to_test
=
[
0
,
5
,
1
,
6
,
20
,
30
]
coordinates_to_test
=
[[
0
,
0
],
[
0
,
1
],
[
1
,
0
],
[
1
,
1
],
[
0
,
4
],
[
0
,
6
]]
def
test_position_to_coordinate
():
actual_coordinates
=
position_to_coordinate
(
depth_to_test
,
positions_to_test
)
expected_coordinates
=
coordinates_to_test
assert
np
.
array_equal
(
actual_coordinates
,
expected_coordinates
),
\
"
converted positions {}, expected {}
"
.
format
(
actual_coordinates
,
expected_coordinates
)
def
test_coordinate_to_position
():
actual_positions
=
coordinate_to_position
(
depth_to_test
,
coordinates_to_test
)
expected_positions
=
positions_to_test
assert
np
.
array_equal
(
actual_positions
,
expected_positions
),
\
"
converted positions {}, expected {}
"
.
format
(
actual_positions
,
expected_positions
)
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