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
3fac7ebd
Commit
3fac7ebd
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
updated tests to new exponential distirbution random generator
parent
0ff89ada
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
flatland/envs/rail_env.py
+2
-4
2 additions, 4 deletions
flatland/envs/rail_env.py
tests/test_flatland_malfunction.py
+18
-9
18 additions, 9 deletions
tests/test_flatland_malfunction.py
tests/test_random_seeding.py
+20
-0
20 additions, 0 deletions
tests/test_random_seeding.py
with
40 additions
and
13 deletions
flatland/envs/rail_env.py
+
2
−
4
View file @
3fac7ebd
...
@@ -360,10 +360,8 @@ class RailEnv(Environment):
...
@@ -360,10 +360,8 @@ class RailEnv(Environment):
# Next malfunction in number of stops
# Next malfunction in number of stops
next_breakdown
=
int
(
next_breakdown
=
int
(
self
.
np_random
.
exponential
(
scale
=
agent
.
malfunction_data
[
'
malfunction_rate
'
]))
self
.
_exp_distirbution_synced
(
rate
=
agent
.
malfunction_data
[
'
malfunction_rate
'
]))
next_breakdown
=
self
.
np_random
.
randint
(
self
.
min_number_of_steps_broken
,
agent
.
malfunction_data
[
'
next_malfunction
'
]
=
next_breakdown
self
.
max_number_of_steps_broken
+
1
)
+
1
agent
.
malfunction_data
[
'
next_malfunction
'
]
=
5
# next_breakdown
# Duration of current malfunction
# Duration of current malfunction
num_broken_steps
=
self
.
np_random
.
randint
(
self
.
min_number_of_steps_broken
,
num_broken_steps
=
self
.
np_random
.
randint
(
self
.
min_number_of_steps_broken
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_flatland_malfunction.py
+
18
−
9
View file @
3fac7ebd
...
@@ -170,7 +170,7 @@ def test_malfunction_before_entry():
...
@@ -170,7 +170,7 @@ def test_malfunction_before_entry():
"""
Tests that malfunctions are produced by stochastic_data!
"""
"""
Tests that malfunctions are produced by stochastic_data!
"""
# Set fixed malfunction duration for this test
# Set fixed malfunction duration for this test
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
'
malfunction_rate
'
:
2
,
'
malfunction_rate
'
:
1
,
'
min_duration
'
:
10
,
'
min_duration
'
:
10
,
'
max_duration
'
:
10
}
'
max_duration
'
:
10
}
...
@@ -187,9 +187,17 @@ def test_malfunction_before_entry():
...
@@ -187,9 +187,17 @@ def test_malfunction_before_entry():
# reset to initialize agents_static
# reset to initialize agents_static
env
.
reset
(
False
,
False
,
False
,
random_seed
=
10
)
env
.
reset
(
False
,
False
,
False
,
random_seed
=
10
)
env
.
agents
[
0
].
target
=
(
0
,
0
)
env
.
agents
[
0
].
target
=
(
0
,
0
)
for
a
in
range
(
env
.
get_num_agents
()):
print
(
"
assert env.agents[{}].malfunction_data[
'
malfunction
'
] == {}
"
.
format
(
a
,
env
.
agents
[
a
].
malfunction_data
[
assert
env
.
agents
[
1
].
malfunction_data
[
'
malfunction
'
]
==
11
'
malfunction
'
]))
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
'
]
==
11
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
'
]
==
11
for
step
in
range
(
20
):
for
step
in
range
(
20
):
action_dict
:
Dict
[
int
,
RailEnvActions
]
=
{}
action_dict
:
Dict
[
int
,
RailEnvActions
]
=
{}
...
@@ -200,16 +208,16 @@ def test_malfunction_before_entry():
...
@@ -200,16 +208,16 @@ def test_malfunction_before_entry():
action_dict
[
agent
.
handle
]
=
RailEnvActions
(
0
)
action_dict
[
agent
.
handle
]
=
RailEnvActions
(
0
)
env
.
step
(
action_dict
)
env
.
step
(
action_dict
)
assert
env
.
agents
[
1
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
1
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
2
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
2
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
3
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
3
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
4
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
4
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
5
].
malfunction_data
[
'
malfunction
'
]
==
2
assert
env
.
agents
[
5
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
6
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
6
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
7
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
7
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
8
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
8
].
malfunction_data
[
'
malfunction
'
]
==
1
assert
env
.
agents
[
9
].
malfunction_data
[
'
malfunction
'
]
==
3
assert
env
.
agents
[
9
].
malfunction_data
[
'
malfunction
'
]
==
1
# Print for test generation
# Print for test generation
# for a in range(env.get_num_agents()):
# for a in range(env.get_num_agents()):
# print("assert env.agents[{}].malfunction_data['malfunction'] == {}".format(a,
# print("assert env.agents[{}].malfunction_data['malfunction'] == {}".format(a,
...
@@ -220,7 +228,7 @@ def test_malfunction_before_entry():
...
@@ -220,7 +228,7 @@ def test_malfunction_before_entry():
def
test_initial_malfunction
():
def
test_initial_malfunction
():
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
# Percentage of defective agents
stochastic_data
=
{
'
prop_malfunction
'
:
1.
,
# Percentage of defective agents
'
malfunction_rate
'
:
7
0
,
# Rate of malfunction occurence
'
malfunction_rate
'
:
10
0
,
# Rate of malfunction occurence
'
min_duration
'
:
2
,
# Minimal duration of malfunction
'
min_duration
'
:
2
,
# Minimal duration of malfunction
'
max_duration
'
:
5
# Max duration of malfunction
'
max_duration
'
:
5
# Max duration of malfunction
}
}
...
@@ -230,7 +238,7 @@ def test_initial_malfunction():
...
@@ -230,7 +238,7 @@ def test_initial_malfunction():
env
=
RailEnv
(
width
=
25
,
env
=
RailEnv
(
width
=
25
,
height
=
30
,
height
=
30
,
rail_generator
=
rail_from_grid_transition_map
(
rail
),
rail_generator
=
rail_from_grid_transition_map
(
rail
),
schedule_generator
=
random_schedule_generator
(),
schedule_generator
=
random_schedule_generator
(
seed
=
10
),
number_of_agents
=
1
,
number_of_agents
=
1
,
stochastic_data
=
stochastic_data
,
# Malfunction data generator
stochastic_data
=
stochastic_data
,
# Malfunction data generator
obs_builder_object
=
SingleAgentNavigationObs
()
obs_builder_object
=
SingleAgentNavigationObs
()
...
@@ -238,6 +246,7 @@ def test_initial_malfunction():
...
@@ -238,6 +246,7 @@ def test_initial_malfunction():
# reset to initialize agents_static
# reset to initialize agents_static
env
.
reset
(
False
,
False
,
True
,
random_seed
=
10
)
env
.
reset
(
False
,
False
,
True
,
random_seed
=
10
)
print
(
env
.
agents
[
0
].
malfunction_data
)
env
.
agents
[
0
].
target
=
(
0
,
5
)
env
.
agents
[
0
].
target
=
(
0
,
5
)
set_penalties_for_replay
(
env
)
set_penalties_for_replay
(
env
)
replay_config
=
ReplayConfig
(
replay_config
=
ReplayConfig
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_random_seeding.py
+
20
−
0
View file @
3fac7ebd
...
@@ -168,3 +168,23 @@ def test_seeding_and_malfunction():
...
@@ -168,3 +168,23 @@ def test_seeding_and_malfunction():
assert
env
.
agents
[
9
].
position
==
env2
.
agents
[
9
].
position
assert
env
.
agents
[
9
].
position
==
env2
.
agents
[
9
].
position
for
a
in
range
(
env
.
get_num_agents
()):
for
a
in
range
(
env
.
get_num_agents
()):
print
(
"
assert env.agents[{}].position == env2.agents[{}].position
"
.
format
(
a
,
a
))
print
(
"
assert env.agents[{}].position == env2.agents[{}].position
"
.
format
(
a
,
a
))
def
tests_new_distributio
():
def
_exp_distirbution_synced
(
rate
):
"""
Generates sample from exponential distribution
We need this to guarantee synchronity between different instances with same seed.
:param rate:
:return:
"""
u
=
np
.
random
.
rand
()
x
=
-
np
.
log
(
1
-
u
)
*
rate
return
x
numbers
=
[]
for
i
in
range
(
100
):
rate1
=
2
rate2
=
100
print
((
_exp_distirbution_synced
(
rate1
),
_exp_distirbution_synced
(
rate2
)))
print
(
numbers
)
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