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
2121d51e
Commit
2121d51e
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
fixed malfunction tests
parent
b9092b25
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_flatland_malfunction.py
+36
-16
36 additions, 16 deletions
tests/test_flatland_malfunction.py
with
36 additions
and
16 deletions
tests/test_flatland_malfunction.py
+
36
−
16
View file @
2121d51e
...
...
@@ -82,7 +82,7 @@ def test_malfunction_process():
obs_builder_object
=
SingleAgentNavigationObs
()
)
# reset to initialize agents_static
obs
,
info
=
env
.
reset
(
False
,
False
,
True
,
random_seed
=
0
)
obs
,
info
=
env
.
reset
(
False
,
False
,
True
,
random_seed
=
1
0
)
print
(
env
.
agents
[
0
].
malfunction_data
)
# Check that a initial duration for malfunction was assigned
assert
env
.
agents
[
0
].
malfunction_data
[
'
next_malfunction
'
]
>
0
...
...
@@ -151,7 +151,7 @@ def test_malfunction_process_statistically():
obs_builder_object
=
SingleAgentNavigationObs
()
)
# reset to initialize agents_static
env
.
reset
(
True
,
True
,
False
,
random_seed
=
0
)
env
.
reset
(
True
,
True
,
False
,
random_seed
=
1
0
)
env
.
agents
[
0
].
target
=
(
0
,
0
)
nb_malfunction
=
0
...
...
@@ -163,11 +163,11 @@ def test_malfunction_process_statistically():
env
.
step
(
action_dict
)
# check that generation of malfunctions works as expected
assert
env
.
agents
[
0
].
malfunction_data
[
"
nr_malfunctions
"
]
==
4
assert
env
.
agents
[
0
].
malfunction_data
[
"
nr_malfunctions
"
]
==
5
def
test_malfunction_before_entry
():
"""
Tests hat malfunctions are produced by stochastic_data!
"""
"""
Tests
t
hat malfunctions are produced by stochastic_data!
"""
# Set fixed malfunction duration for this test
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
'
malfunction_rate
'
:
2
,
...
...
@@ -179,28 +179,48 @@ def test_malfunction_before_entry():
env
=
RailEnv
(
width
=
25
,
height
=
30
,
rail_generator
=
rail_from_grid_transition_map
(
rail
),
schedule_generator
=
random_schedule_generator
(),
number_of_agents
=
1
,
schedule_generator
=
random_schedule_generator
(
seed
=
2
),
# seed 12
number_of_agents
=
10
,
random_seed
=
1
,
stochastic_data
=
stochastic_data
,
# Malfunction data generator
obs_builder_object
=
SingleAgentNavigationObs
()
)
# reset to initialize agents_static
env
.
reset
(
False
,
False
,
False
,
random_seed
=
0
)
env
.
reset
(
False
,
False
,
False
,
random_seed
=
1
0
)
env
.
agents
[
0
].
target
=
(
0
,
0
)
nb_malfunction
=
0
assert
env
.
agents
[
1
].
malfunction_data
[
'
malfunction
'
]
==
11
assert
env
.
agents
[
2
].
malfunction_data
[
'
malfunction
'
]
==
11
assert
env
.
agents
[
3
].
malfunction_data
[
'
malfunction
'
]
==
11
assert
env
.
agents
[
4
].
malfunction_data
[
'
malfunction
'
]
==
11
assert
env
.
agents
[
5
].
malfunction_data
[
'
malfunction
'
]
==
0
assert
env
.
agents
[
6
].
malfunction_data
[
'
malfunction
'
]
==
11
assert
env
.
agents
[
7
].
malfunction_data
[
'
malfunction
'
]
==
11
assert
env
.
agents
[
8
].
malfunction_data
[
'
malfunction
'
]
==
11
assert
env
.
agents
[
9
].
malfunction_data
[
'
malfunction
'
]
==
0
for
step
in
range
(
20
):
action_dict
:
Dict
[
int
,
RailEnvActions
]
=
{}
for
agent
in
env
.
agents
:
# We randomly select an action
action_dict
[
agent
.
handle
]
=
RailEnvActions
(
2
)
if
step
<
10
:
action_dict
[
agent
.
handle
]
=
RailEnvActions
(
0
)
assert
env
.
agents
[
0
].
malfunction_data
[
'
malfunction
'
]
==
0
else
:
action_dict
[
agent
.
handle
]
=
RailEnvActions
(
2
)
print
(
env
.
agents
[
0
].
malfunction_data
)
env
.
step
(
action_dict
)
assert
env
.
agents
[
0
].
malfunction_data
[
'
malfunction
'
]
>
0
assert
env
.
agents
[
1
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
2
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
3
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
4
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
5
].
malfunction_data
[
'
malfunction
'
]
==
2
assert
env
.
agents
[
6
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
7
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
8
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
9
].
malfunction_data
[
'
malfunction
'
]
==
3
# Print for test generation
# for a in range(env.get_num_agents()):
# print("assert env.agents[{}].malfunction_data['malfunction'] == {}".format(a,
# env.agents[a].malfunction_data[
# 'malfunction']))
def
test_initial_malfunction
():
...
...
@@ -223,8 +243,8 @@ def test_initial_malfunction():
)
# reset to initialize agents_static
env
.
reset
(
False
,
False
,
True
,
random_seed
=
0
)
env
.
reset
(
False
,
False
,
True
,
random_seed
=
1
0
)
env
.
agents
[
0
].
target
=
(
0
,
5
)
set_penalties_for_replay
(
env
)
replay_config
=
ReplayConfig
(
replay
=
[
...
...
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