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
1158cdc2
Commit
1158cdc2
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
updated malfunction test
parent
2ec6d6f4
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.py
+2
-0
2 additions, 0 deletions
flatland/envs/rail_env.py
tests/test_flatland_malfunction.py
+28
-6
28 additions, 6 deletions
tests/test_flatland_malfunction.py
with
30 additions
and
6 deletions
flatland/envs/rail_env.py
+
2
−
0
View file @
1158cdc2
...
...
@@ -238,6 +238,8 @@ class RailEnv(Environment):
agent
.
speed_data
[
'
position_fraction
'
]
=
0.0
agent
.
malfunction_data
[
'
malfunction
'
]
=
0
self
.
_agent_stopped
(
i_agent
)
self
.
num_resets
+=
1
self
.
_elapsed_steps
=
0
...
...
This diff is collapsed.
Click to expand it.
tests/test_flatland_malfunction.py
+
28
−
6
View file @
1158cdc2
...
...
@@ -51,10 +51,11 @@ class SingleAgentNavigationObs(TreeObsForRailEnv):
def
test_malfunction_process
():
# Set fixed malfunction duration for this test
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
'
malfunction_rate
'
:
5
,
'
min_duration
'
:
3
,
'
max_duration
'
:
10
}
'
max_duration
'
:
3
}
np
.
random
.
seed
(
5
)
env
=
RailEnv
(
width
=
14
,
...
...
@@ -66,23 +67,44 @@ def test_malfunction_process():
stochastic_data
=
stochastic_data
)
obs
=
env
.
reset
()
# Check that a initial duration for malfunction was assigned
assert
env
.
agents
[
0
].
malfunction_data
[
'
next_malfunction
'
]
>
0
agent_halts
=
0
total_down_time
=
0
agent_malfunctioning
=
False
agent_old_position
=
env
.
agents
[
0
].
position
for
step
in
range
(
100
):
actions
=
{}
for
i
in
range
(
len
(
obs
)):
actions
[
i
]
=
np
.
argmax
(
obs
[
i
])
+
1
if
step
%
5
==
0
:
# Stop the agent and set it to be malfunctioning
actions
[
0
]
=
4
env
.
agents
[
0
].
malfunction_data
[
'
next_malfunction
'
]
=
0
agent_halts
+=
1
if
env
.
agents
[
0
].
malfunction_data
[
'
malfunction
'
]
>
0
:
agent_malfunctioning
=
True
else
:
agent_malfunctioning
=
False
obs
,
all_rewards
,
done
,
_
=
env
.
step
(
actions
)
if
done
[
"
__all__
"
]:
break
if
agent_malfunctioning
:
assert
agent_old_position
==
env
.
agents
[
0
].
position
agent_old_position
=
env
.
agents
[
0
].
position
total_down_time
+=
env
.
agents
[
0
].
malfunction_data
[
'
malfunction
'
]
# Check that the agents breaks twice
assert
env
.
agents
[
0
].
malfunction_data
[
'
nr_malfunctions
'
]
==
2
assert
env
.
agents
[
0
].
malfunction_data
[
'
nr_malfunctions
'
]
==
5
# Check that 11 stops where performed
assert
agent_halts
==
20
# Check that
7 stops where performe
d
assert
agent_halts
==
7
# Check that
malfunctioning data was standing aroun
d
assert
total_down_time
>
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