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
cab970d7
Commit
cab970d7
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
added simple test for decay of next_malfunction step
parent
2ebc1dbe
No related branches found
Branches containing commit
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
+0
-4
0 additions, 4 deletions
flatland/envs/rail_env.py
tests/test_flatland_malfunction.py
+46
-55
46 additions, 55 deletions
tests/test_flatland_malfunction.py
with
46 additions
and
59 deletions
flatland/envs/rail_env.py
+
0
−
4
View file @
cab970d7
...
...
@@ -437,10 +437,6 @@ class RailEnv(Environment):
return
True
# Decrease counter for next event only if agent is currently not broken and agent has a malfunction rate
if
agent
.
malfunction_data
[
'
next_malfunction
'
]
>
0
and
agent
.
malfunction_data
[
'
malfunction
'
]
<
1
:
agent
.
malfunction_data
[
'
next_malfunction
'
]
-=
1
def
step
(
self
,
action_dict_
:
Dict
[
int
,
RailEnvActions
]):
...
...
This diff is collapsed.
Click to expand it.
tests/test_flatland_malfunction.py
+
46
−
55
View file @
cab970d7
...
...
@@ -156,14 +156,14 @@ def test_malfunction_process_statistically():
env
.
agents
[
0
].
target
=
(
0
,
0
)
# Next line only for test generation
#agent_malfunction_list = [[] for i in range(20)]
#
agent_malfunction_list = [[] for i in range(20)]
agent_malfunction_list
=
[[
0
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
,
0
,
1
,
2
,
3
,
2
],
[
1
,
2
,
4
,
1
,
5
,
5
,
0
,
1
,
2
,
1
],
[
0
,
1
,
3
,
0
,
4
,
4
,
0
,
0
,
1
,
0
],
[
0
,
0
,
2
,
0
,
3
,
3
,
0
,
0
,
0
,
0
],
[
5
,
0
,
1
,
0
,
2
,
2
,
5
,
5
,
0
,
5
],
[
4
,
0
,
0
,
0
,
1
,
1
,
4
,
4
,
5
,
4
],
[
3
,
0
,
0
,
5
,
0
,
0
,
3
,
3
,
4
,
3
],
[
2
,
5
,
0
,
4
,
0
,
0
,
2
,
2
,
3
,
2
],
[
1
,
4
,
0
,
3
,
5
,
5
,
1
,
1
,
2
,
1
],
[
0
,
3
,
0
,
2
,
4
,
4
,
0
,
0
,
1
,
0
],
[
0
,
2
,
0
,
1
,
3
,
3
,
0
,
0
,
0
,
0
],
[
5
,
1
,
0
,
0
,
2
,
2
,
5
,
5
,
0
,
5
],
[
4
,
0
,
5
,
0
,
1
,
1
,
4
,
4
,
5
,
4
]]
for
step
in
range
(
20
):
action_dict
:
Dict
[
int
,
RailEnvActions
]
=
{}
...
...
@@ -202,16 +202,16 @@ def test_malfunction_before_entry():
# Test initial malfunction values for all agents
# we want some agents to be malfuncitoning already and some to be working
# we want different next_malfunction values for the agents
assert
env
.
agents
[
0
].
malfunction_data
[
'
next_malfunction
'
]
==
5
assert
env
.
agents
[
1
].
malfunction_data
[
'
next_malfunction
'
]
==
6
assert
env
.
agents
[
2
].
malfunction_data
[
'
next_malfunction
'
]
==
6
assert
env
.
agents
[
3
].
malfunction_data
[
'
next_malfunction
'
]
==
3
assert
env
.
agents
[
1
].
malfunction_data
[
'
next_malfunction
'
]
==
5
assert
env
.
agents
[
2
].
malfunction_data
[
'
next_malfunction
'
]
==
5
assert
env
.
agents
[
3
].
malfunction_data
[
'
next_malfunction
'
]
==
2
assert
env
.
agents
[
4
].
malfunction_data
[
'
next_malfunction
'
]
==
1
assert
env
.
agents
[
5
].
malfunction_data
[
'
next_malfunction
'
]
==
1
assert
env
.
agents
[
6
].
malfunction_data
[
'
next_malfunction
'
]
==
3
assert
env
.
agents
[
7
].
malfunction_data
[
'
next_malfunction
'
]
==
4
assert
env
.
agents
[
8
].
malfunction_data
[
'
next_malfunction
'
]
==
6
assert
env
.
agents
[
9
].
malfunction_data
[
'
next_malfunction
'
]
==
0
assert
env
.
agents
[
6
].
malfunction_data
[
'
next_malfunction
'
]
==
2
assert
env
.
agents
[
7
].
malfunction_data
[
'
next_malfunction
'
]
==
3
assert
env
.
agents
[
8
].
malfunction_data
[
'
next_malfunction
'
]
==
5
assert
env
.
agents
[
9
].
malfunction_data
[
'
next_malfunction
'
]
==
-
1
assert
env
.
agents
[
0
].
malfunction_data
[
'
malfunction
'
]
==
0
assert
env
.
agents
[
1
].
malfunction_data
[
'
malfunction
'
]
==
0
assert
env
.
agents
[
2
].
malfunction_data
[
'
malfunction
'
]
==
0
...
...
@@ -223,50 +223,41 @@ def test_malfunction_before_entry():
assert
env
.
agents
[
8
].
malfunction_data
[
'
malfunction
'
]
==
0
assert
env
.
agents
[
9
].
malfunction_data
[
'
malfunction
'
]
==
0
for
a
in
range
(
env
.
get_num_agents
()):
print
(
"
assert env.agents[{}].malfunction_data[
'
next_malfunction
'
] == {}
"
.
format
(
a
,
env
.
agents
[
a
].
malfunction_data
[
'
next_malfunction
'
]))
for
a
in
range
(
env
.
get_num_agents
()):
print
(
"
assert env.agents[{}].malfunction_data[
'
malfunction
'
] == {}
"
.
format
(
a
,
env
.
agents
[
a
].
malfunction_data
[
'
malfunction
'
]))
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
)
def
test_next_malfunction_counter
():
"""
Test that the next malfunction occurs when desired
Returns
-------
"""
# Set fixed malfunction duration for this test
rail
,
rail_map
=
make_simple_rail2
()
action_dict
:
Dict
[
int
,
RailEnvActions
]
=
{}
env
=
RailEnv
(
width
=
25
,
height
=
30
,
rail_generator
=
rail_from_grid_transition_map
(
rail
),
schedule_generator
=
random_schedule_generator
(
seed
=
2
),
# seed 12
number_of_agents
=
1
,
random_seed
=
1
,
)
# reset to initialize agents_static
env
.
reset
(
False
,
False
,
activate_agents
=
True
,
random_seed
=
10
)
env
.
agents
[
0
].
malfunction_data
[
'
next_malfunction
'
]
=
5
env
.
agents
[
0
].
malfunction_data
[
'
malfunction_rate
'
]
=
5
env
.
agents
[
0
].
malfunction_data
[
'
malfunction
'
]
=
0
env
.
agents
[
0
].
target
=
(
0
,
0
),
#Move the target out of range
print
(
env
.
agents
[
0
].
position
,
env
.
agents
[
0
].
malfunction_data
[
'
next_malfunction
'
])
for
time_step
in
range
(
1
,
6
):
# Move in the env
env
.
step
(
action_dict
)
# We want to check that all agents are malfunctioning and that their values changed
# Check that next_step decreases as expected
assert
env
.
agents
[
0
].
malfunction_data
[
'
next_malfunction
'
]
==
5
-
time_step
# Test malfunction values for all agents after 20 steps
assert
env
.
agents
[
0
].
malfunction_data
[
'
next_malfunction
'
]
==
4
assert
env
.
agents
[
1
].
malfunction_data
[
'
next_malfunction
'
]
==
6
assert
env
.
agents
[
2
].
malfunction_data
[
'
next_malfunction
'
]
==
2
assert
env
.
agents
[
3
].
malfunction_data
[
'
next_malfunction
'
]
==
2
assert
env
.
agents
[
4
].
malfunction_data
[
'
next_malfunction
'
]
==
1
assert
env
.
agents
[
5
].
malfunction_data
[
'
next_malfunction
'
]
==
1
assert
env
.
agents
[
6
].
malfunction_data
[
'
next_malfunction
'
]
==
2
assert
env
.
agents
[
7
].
malfunction_data
[
'
next_malfunction
'
]
==
1
assert
env
.
agents
[
8
].
malfunction_data
[
'
next_malfunction
'
]
==
1
assert
env
.
agents
[
9
].
malfunction_data
[
'
next_malfunction
'
]
==
4
assert
env
.
agents
[
0
].
malfunction_data
[
'
malfunction
'
]
==
0
assert
env
.
agents
[
1
].
malfunction_data
[
'
malfunction
'
]
==
8
assert
env
.
agents
[
2
].
malfunction_data
[
'
malfunction
'
]
==
8
assert
env
.
agents
[
3
].
malfunction_data
[
'
malfunction
'
]
==
0
assert
env
.
agents
[
4
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
5
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
6
].
malfunction_data
[
'
malfunction
'
]
==
0
assert
env
.
agents
[
7
].
malfunction_data
[
'
malfunction
'
]
==
6
assert
env
.
agents
[
8
].
malfunction_data
[
'
malfunction
'
]
==
8
assert
env
.
agents
[
9
].
malfunction_data
[
'
malfunction
'
]
==
2
# Print for test generation
#for a in range(env.get_num_agents()):
# print("assert env.agents[{}].malfunction_data['next_malfunction'] == {}".format(a, env.agents[a].malfunction_data['next_malfunction']))
#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
():
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
# Percentage of defective agents
...
...
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