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
yoogottamk
Flatland
Commits
97b333ba
Commit
97b333ba
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
test fixed
parent
1bba6852
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
flatland/envs/rail_env_utils.py
+1
-1
1 addition, 1 deletion
flatland/envs/rail_env_utils.py
tests/test_shortest_path.py
+117
-37
117 additions, 37 deletions
tests/test_shortest_path.py
with
118 additions
and
38 deletions
flatland/envs/rail_env_utils.py
+
1
−
1
View file @
97b333ba
...
...
@@ -15,7 +15,7 @@ from flatland.envs.schedule_generators import schedule_from_file
from
flatland.utils.ordered_set
import
OrderedSet
WalkingElement
=
\
NamedTuple
(
'
Path_
Element
'
,
NamedTuple
(
'
Walking
Element
'
,
[(
'
position
'
,
Tuple
[
int
,
int
]),
(
'
direction
'
,
int
),
(
'
next_action_element
'
,
RailEnvNextAction
)])
...
...
This diff is collapsed.
Click to expand it.
tests/test_shortest_path.py
+
117
−
37
View file @
97b333ba
import
numpy
as
np
from
flatland.envs.rail_env
import
RailEnvNextAction
,
RailEnvActions
from
flatland.envs.rail_env_utils
import
load_flatland_environment_from_file
,
get_shortest_paths
from
flatland.envs.rail_env_utils
import
load_flatland_environment_from_file
,
get_shortest_paths
,
WalkingElement
def
test_get_shortest_paths
():
...
...
@@ -9,42 +9,122 @@ def test_get_shortest_paths():
actual
=
get_shortest_paths
(
env
.
distance_map
)
expected
=
{
0
:
[
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
1
,
2
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
1
,
3
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
3
),
next_direction
=
2
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
4
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
5
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
6
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
7
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
8
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
9
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
10
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
11
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
12
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
13
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
14
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
15
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
16
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
17
),
next_direction
=
1
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
18
),
next_direction
=
1
)],
1
:
[
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
17
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
16
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
16
),
next_direction
=
0
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
15
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
14
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
13
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
12
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
11
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
10
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
9
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
8
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
7
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
6
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
5
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
4
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
3
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
2
),
next_direction
=
3
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
1
),
next_direction
=
3
)]
0
:
[
WalkingElement
(
position
=
(
1
,
1
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
1
,
2
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
1
,
2
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
1
,
3
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
1
,
3
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
3
),
next_direction
=
2
)),
WalkingElement
(
position
=
(
2
,
3
),
direction
=
2
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
4
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
4
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
5
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
5
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
6
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
6
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
7
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
7
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
8
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
8
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
9
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
9
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
10
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
10
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
11
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
11
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
12
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
12
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
13
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
13
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
14
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
14
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
15
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
15
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
16
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
16
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
17
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
17
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
18
),
next_direction
=
1
)),
WalkingElement
(
position
=
(
2
,
18
),
direction
=
1
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
STOP_MOVING
,
next_position
=
(
2
,
18
),
next_direction
=
1
))],
1
:
[
WalkingElement
(
position
=
(
3
,
18
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
17
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
3
,
17
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
16
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
3
,
16
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
16
),
next_direction
=
0
)),
WalkingElement
(
position
=
(
2
,
16
),
direction
=
0
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
15
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
15
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
14
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
14
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
13
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
13
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
12
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
12
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
11
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
11
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
10
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
10
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
9
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
9
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
8
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
8
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
7
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
7
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
6
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
6
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
5
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
5
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
4
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
4
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
3
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
3
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
2
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
2
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
2
,
1
),
next_direction
=
3
)),
WalkingElement
(
position
=
(
2
,
1
),
direction
=
3
,
next_action_element
=
RailEnvNextAction
(
action
=
RailEnvActions
.
STOP_MOVING
,
next_position
=
(
2
,
1
),
next_direction
=
3
))]
}
for
agent_handle
in
expected
:
...
...
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