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
123806b1
Commit
123806b1
authored
5 years ago
by
maljx
Browse files
Options
Downloads
Patches
Plain Diff
level gen: optimized validation
parent
7212e11a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
flatland/core/transitions.py
+15
-13
15 additions, 13 deletions
flatland/core/transitions.py
flatland/envs/rail_env.py
+5
-4
5 additions, 4 deletions
flatland/envs/rail_env.py
with
20 additions
and
17 deletions
flatland/core/transitions.py
+
15
−
13
View file @
123806b1
...
...
@@ -532,14 +532,25 @@ class RailEnvTransitions(Grid4Transitions):
int
(
'
1100110000110011
'
,
2
),
# Case 5 - double slip
int
(
'
0101001000000010
'
,
2
),
# Case 6 - symmetrical
int
(
'
0010000000000000
'
,
2
),
# Case 7 - dead end
int
(
'
0100000000000010
'
,
2
),
# Case 1b - simple turn right
int
(
'
0001001000000000
'
,
2
),
# Case 1c - simple turn left
int
(
'
1100000000100010
'
,
2
)]
# Case 2b - simple switch mirrored
int
(
'
0100000000000010
'
,
2
),
# Case 1b
(8)
- simple turn right
int
(
'
0001001000000000
'
,
2
),
# Case 1c
(9)
- simple turn left
int
(
'
1100000000100010
'
,
2
)]
# Case 2b
(10)
- simple switch mirrored
def
__init__
(
self
):
super
(
RailEnvTransitions
,
self
).
__init__
(
transitions
=
self
.
transition_list
)
# create this to make validation faster
self
.
transitions_all
=
[]
for
index
,
trans
in
enumerate
(
self
.
transitions
):
self
.
transitions_all
.
append
(
trans
)
if
index
in
(
2
,
4
,
6
,
7
,
8
,
9
,
10
):
for
_
in
range
(
3
):
trans
=
self
.
rotate_transition
(
trans
,
rotation
=
90
)
self
.
transitions_all
.
append
(
trans
)
elif
index
in
(
1
,
5
):
trans
=
self
.
rotate_transition
(
trans
,
rotation
=
90
)
self
.
transitions_all
.
append
(
trans
)
def
print
(
self
,
cell_transition
):
print
(
"
NESW
"
)
...
...
@@ -562,17 +573,8 @@ class RailEnvTransitions(Grid4Transitions):
Boolean
True or False
"""
# i = 0
for
trans
in
self
.
transitions
:
# print(">", i)
# i += 1
# self.print(trans)
for
trans
in
self
.
transitions_all
:
if
cell_transition
==
trans
:
return
True
for
_
in
range
(
3
):
trans
=
self
.
rotate_transition
(
trans
,
rotation
=
90
)
# self.print(trans)
if
cell_transition
==
trans
:
return
True
return
False
This diff is collapsed.
Click to expand it.
flatland/envs/rail_env.py
+
5
−
4
View file @
123806b1
...
...
@@ -73,7 +73,7 @@ def validate_new_transition(rail_trans, rail_array, prev_pos, current_pos, new_p
else
:
# check if matches existing layout
new_trans
=
rail_trans
.
set_transition
(
new_trans
,
current_dir
,
new_dir
,
1
)
new_trans
=
rail_trans
.
set_transition
(
new_trans
,
mirror
(
new_dir
),
mirror
(
current_dir
),
1
)
#
new_trans = rail_trans.set_transition(new_trans, mirror(new_dir), mirror(current_dir), 1)
# rail_trans.print(new_trans)
else
:
# set the forward path
...
...
@@ -89,7 +89,7 @@ def validate_new_transition(rail_trans, rail_array, prev_pos, current_pos, new_p
else
:
# check if matches existing layout
new_trans_e
=
rail_trans
.
set_transition
(
new_trans_e
,
new_dir
,
new_dir
,
1
)
new_trans_e
=
rail_trans
.
set_transition
(
new_trans_e
,
mirror
(
new_dir
),
mirror
(
new_dir
),
1
)
#
new_trans_e = rail_trans.set_transition(new_trans_e, mirror(new_dir), mirror(new_dir), 1)
# print("end:", end_pos, current_pos)
# rail_trans.print(new_trans_e)
...
...
@@ -244,7 +244,8 @@ def connect_rail(rail_trans, rail_array, start, end):
else
:
# into existing rail
new_trans
=
rail_trans
.
set_transition
(
new_trans
,
current_dir
,
new_dir
,
1
)
new_trans
=
rail_trans
.
set_transition
(
new_trans
,
mirror
(
new_dir
),
mirror
(
current_dir
),
1
)
# new_trans = rail_trans.set_transition(new_trans, mirror(new_dir), mirror(current_dir), 1)
pass
else
:
# set the forward path
new_trans
=
rail_trans
.
set_transition
(
new_trans
,
current_dir
,
new_dir
,
1
)
...
...
@@ -261,7 +262,7 @@ def connect_rail(rail_trans, rail_array, start, end):
else
:
# into existing rail
new_trans_e
=
rail_trans
.
set_transition
(
new_trans_e
,
new_dir
,
new_dir
,
1
)
new_trans_e
=
rail_trans
.
set_transition
(
new_trans_e
,
mirror
(
new_dir
),
mirror
(
new_dir
),
1
)
#
new_trans_e = rail_trans.set_transition(new_trans_e, mirror(new_dir), mirror(new_dir), 1)
rail_array
[
end_pos
]
=
new_trans_e
current_dir
=
new_dir
...
...
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