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
0ff89ada
Commit
0ff89ada
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
updated exponential sampling to use rate as before
parent
4c613e92
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
flatland/envs/rail_env.py
+15
-2
15 additions, 2 deletions
flatland/envs/rail_env.py
tests/test_flatland_malfunction.py
+3
-9
3 additions, 9 deletions
tests/test_flatland_malfunction.py
tests/test_random_seeding.py
+6
-4
6 additions, 4 deletions
tests/test_random_seeding.py
with
24 additions
and
15 deletions
flatland/envs/rail_env.py
+
15
−
2
View file @
0ff89ada
...
...
@@ -188,7 +188,7 @@ class RailEnv(Environment):
self
.
distance_map
=
DistanceMap
(
self
.
agents
,
self
.
height
,
self
.
width
)
self
.
action_space
=
[
1
]
self
.
_seed
()
self
.
_seed
()
...
...
@@ -361,7 +361,9 @@ class RailEnv(Environment):
# Next malfunction in number of stops
next_breakdown
=
int
(
self
.
np_random
.
exponential
(
scale
=
agent
.
malfunction_data
[
'
malfunction_rate
'
]))
agent
.
malfunction_data
[
'
next_malfunction
'
]
=
next_breakdown
next_breakdown
=
self
.
np_random
.
randint
(
self
.
min_number_of_steps_broken
,
self
.
max_number_of_steps_broken
+
1
)
+
1
agent
.
malfunction_data
[
'
next_malfunction
'
]
=
5
# next_breakdown
# Duration of current malfunction
num_broken_steps
=
self
.
np_random
.
randint
(
self
.
min_number_of_steps_broken
,
...
...
@@ -754,3 +756,14 @@ class RailEnv(Environment):
from
importlib_resources
import
read_binary
load_data
=
read_binary
(
package
,
resource
)
self
.
set_full_state_msg
(
load_data
)
def
_exp_distirbution_synced
(
self
,
rate
):
"""
Generates sample from exponential distribution
We need this to guarantee synchronity between different instances with same seed.
:param rate:
:return:
"""
u
=
self
.
np_random
.
rand
()
x
=
-
np
.
log
(
1
-
u
)
*
rate
return
x
This diff is collapsed.
Click to expand it.
tests/test_flatland_malfunction.py
+
3
−
9
View file @
0ff89ada
...
...
@@ -187,15 +187,9 @@ def test_malfunction_before_entry():
# reset to initialize agents_static
env
.
reset
(
False
,
False
,
False
,
random_seed
=
10
)
env
.
agents
[
0
].
target
=
(
0
,
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
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
]
=
{}
...
...
This diff is collapsed.
Click to expand it.
tests/test_random_seeding.py
+
6
−
4
View file @
0ff89ada
...
...
@@ -61,8 +61,8 @@ def test_seeding_and_observations():
obs_builder_object
=
TreeObsForRailEnv
(
max_depth
=
2
,
predictor
=
ShortestPathPredictorForRailEnv
())
)
env
.
reset
(
False
,
False
,
False
)
env2
.
reset
(
False
,
False
,
False
)
env
.
reset
(
False
,
False
,
False
,
random_seed
=
12
)
env2
.
reset
(
False
,
False
,
False
,
random_seed
=
12
)
# Check that both environments produce the same initial start positions
assert
env
.
agents
[
0
].
initial_position
==
env2
.
agents
[
0
].
initial_position
...
...
@@ -129,8 +129,8 @@ def test_seeding_and_malfunction():
stochastic_data
=
stochastic_data
,
# Malfunction data generator
)
env
.
reset
(
False
,
False
,
False
)
env2
.
reset
(
False
,
False
,
False
)
env
.
reset
(
False
,
False
,
False
,
random_seed
=
12
)
env2
.
reset
(
False
,
False
,
False
,
random_seed
=
12
)
# Check that both environments produce the same initial start positions
assert
env
.
agents
[
0
].
initial_position
==
env2
.
agents
[
0
].
initial_position
...
...
@@ -149,9 +149,11 @@ def test_seeding_and_malfunction():
for
a
in
range
(
env
.
get_num_agents
()):
action
=
np
.
random
.
randint
(
4
)
action_dict
[
a
]
=
action
print
(
env
.
agents
[
a
].
malfunction_data
[
'
malfunction
'
],
env2
.
agents
[
a
].
malfunction_data
[
'
malfunction
'
])
env
.
step
(
action_dict
)
env2
.
step
(
action_dict
)
# Check that both environments end up in the same position
assert
env
.
agents
[
0
].
position
==
env2
.
agents
[
0
].
position
...
...
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