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
9bebfe03
Commit
9bebfe03
authored
5 years ago
by
u214892
Browse files
Options
Downloads
Patches
Plain Diff
#178 bugfix initial malfunction
parent
096fd933
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/core/grid/grid4_astar.py
+53
-3
53 additions, 3 deletions
flatland/core/grid/grid4_astar.py
tests/test_flatland_malfunction.py
+10
-7
10 additions, 7 deletions
tests/test_flatland_malfunction.py
with
63 additions
and
10 deletions
flatland/core/grid/grid4_astar.py
+
53
−
3
View file @
9bebfe03
import
collections
from
flatland.core.grid.grid4_utils
import
validate_new_transition
from
flatland.core.grid.grid4_utils
import
validate_new_transition
...
@@ -25,6 +27,54 @@ class AStarNode():
...
@@ -25,6 +27,54 @@ class AStarNode():
self
.
f
=
other
.
f
self
.
f
=
other
.
f
# in order for enumeration to be deterministic for testing purposes
# https://stackoverflow.com/questions/1653970/does-python-have-an-ordered-set
class
OrderedSet
(
collections
.
OrderedDict
,
collections
.
MutableSet
):
def
update
(
self
,
*
args
,
**
kwargs
):
if
kwargs
:
raise
TypeError
(
"
update() takes no keyword arguments
"
)
for
s
in
args
:
for
e
in
s
:
self
.
add
(
e
)
def
add
(
self
,
elem
):
self
[
elem
]
=
None
def
discard
(
self
,
elem
):
self
.
pop
(
elem
,
None
)
def
__le__
(
self
,
other
):
return
all
(
e
in
other
for
e
in
self
)
def
__lt__
(
self
,
other
):
return
self
<=
other
and
self
!=
other
def
__ge__
(
self
,
other
):
return
all
(
e
in
self
for
e
in
other
)
def
__gt__
(
self
,
other
):
return
self
>=
other
and
self
!=
other
def
__repr__
(
self
):
return
'
OrderedSet([%s])
'
%
(
'
,
'
.
join
(
map
(
repr
,
self
.
keys
())))
def
__str__
(
self
):
return
'
{%s}
'
%
(
'
,
'
.
join
(
map
(
repr
,
self
.
keys
())))
difference
=
property
(
lambda
self
:
self
.
__sub__
)
difference_update
=
property
(
lambda
self
:
self
.
__isub__
)
intersection
=
property
(
lambda
self
:
self
.
__and__
)
intersection_update
=
property
(
lambda
self
:
self
.
__iand__
)
issubset
=
property
(
lambda
self
:
self
.
__le__
)
issuperset
=
property
(
lambda
self
:
self
.
__ge__
)
symmetric_difference
=
property
(
lambda
self
:
self
.
__xor__
)
symmetric_difference_update
=
property
(
lambda
self
:
self
.
__ixor__
)
union
=
property
(
lambda
self
:
self
.
__or__
)
def
a_star
(
rail_trans
,
rail_array
,
start
,
end
):
def
a_star
(
rail_trans
,
rail_array
,
start
,
end
):
"""
"""
Returns a list of tuples as a path from the given start to end.
Returns a list of tuples as a path from the given start to end.
...
@@ -33,12 +83,12 @@ def a_star(rail_trans, rail_array, start, end):
...
@@ -33,12 +83,12 @@ def a_star(rail_trans, rail_array, start, end):
rail_shape
=
rail_array
.
shape
rail_shape
=
rail_array
.
shape
start_node
=
AStarNode
(
None
,
start
)
start_node
=
AStarNode
(
None
,
start
)
end_node
=
AStarNode
(
None
,
end
)
end_node
=
AStarNode
(
None
,
end
)
open_nodes
=
s
et
()
open_nodes
=
OrderedS
et
()
closed_nodes
=
s
et
()
closed_nodes
=
OrderedS
et
()
open_nodes
.
add
(
start_node
)
open_nodes
.
add
(
start_node
)
while
len
(
open_nodes
)
>
0
:
while
len
(
open_nodes
)
>
0
:
# get node with current shortest
est.
path (lowest f)
# get node with current shortest path (lowest f)
current_node
=
None
current_node
=
None
for
item
in
open_nodes
:
for
item
in
open_nodes
:
if
current_node
is
None
:
if
current_node
is
None
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_flatland_malfunction.py
+
10
−
7
View file @
9bebfe03
...
@@ -126,6 +126,7 @@ def test_malfunction_process_statistically():
...
@@ -126,6 +126,7 @@ def test_malfunction_process_statistically():
'
min_duration
'
:
3
,
'
min_duration
'
:
3
,
'
max_duration
'
:
3
}
'
max_duration
'
:
3
}
np
.
random
.
seed
(
5
)
np
.
random
.
seed
(
5
)
random
.
seed
(
0
)
env
=
RailEnv
(
width
=
20
,
env
=
RailEnv
(
width
=
20
,
height
=
20
,
height
=
20
,
...
@@ -150,11 +151,13 @@ def test_malfunction_process_statistically():
...
@@ -150,11 +151,13 @@ def test_malfunction_process_statistically():
# check that generation of malfunctions works as expected
# check that generation of malfunctions works as expected
# results are different in py36 and py37, therefore no exact test on nb_malfunction
# results are different in py36 and py37, therefore no exact test on nb_malfunction
assert
nb_malfunction
>
150
assert
nb_malfunction
==
149
,
"
nb_malfunction={}
"
.
format
(
nb_malfunction
)
def
test_initial_malfunction
(
rendering
=
True
):
def
test_initial_malfunction
(
rendering
=
True
):
random
.
seed
(
0
)
random
.
seed
(
0
)
np
.
random
.
seed
(
0
)
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
# Percentage of defective agents
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
# Percentage of defective agents
'
malfunction_rate
'
:
70
,
# Rate of malfunction occurence
'
malfunction_rate
'
:
70
,
# Rate of malfunction occurence
'
min_duration
'
:
2
,
# Minimal duration of malfunction
'
min_duration
'
:
2
,
# Minimal duration of malfunction
...
@@ -193,32 +196,32 @@ def test_initial_malfunction(rendering=True):
...
@@ -193,32 +196,32 @@ def test_initial_malfunction(rendering=True):
replay_steps
=
[
replay_steps
=
[
Replay
(
Replay
(
position
=
(
2
7
,
5
),
position
=
(
2
8
,
5
),
direction
=
Grid4TransitionsEnum
.
EAST
,
direction
=
Grid4TransitionsEnum
.
EAST
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
malfunction
=
3
malfunction
=
3
),
),
Replay
(
Replay
(
position
=
(
2
7
,
5
),
position
=
(
2
8
,
5
),
direction
=
Grid4TransitionsEnum
.
EAST
,
direction
=
Grid4TransitionsEnum
.
EAST
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
malfunction
=
2
malfunction
=
2
),
),
Replay
(
Replay
(
position
=
(
2
7
,
5
),
position
=
(
2
8
,
5
),
direction
=
Grid4TransitionsEnum
.
EAST
,
direction
=
Grid4TransitionsEnum
.
EAST
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
malfunction
=
1
malfunction
=
1
),
),
Replay
(
Replay
(
position
=
(
2
7
,
4
),
position
=
(
2
8
,
4
),
direction
=
Grid4TransitionsEnum
.
WEST
,
direction
=
Grid4TransitionsEnum
.
WEST
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
malfunction
=
0
malfunction
=
0
),
),
Replay
(
Replay
(
position
=
(
27
,
3
),
position
=
(
27
,
4
),
direction
=
Grid4TransitionsEnum
.
WEST
,
direction
=
Grid4TransitionsEnum
.
NORTH
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
action
=
RailEnvActions
.
MOVE_FORWARD
,
malfunction
=
0
malfunction
=
0
)
)
...
...
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