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
672f0f3c
Commit
672f0f3c
authored
5 years ago
by
spiglerg
Browse files
Options
Downloads
Patches
Plain Diff
first push stochastic breaking -- added flags to agents
parent
a447381f
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/agent_utils.py
+16
-3
16 additions, 3 deletions
flatland/envs/agent_utils.py
flatland/envs/rail_env.py
+2
-0
2 additions, 0 deletions
flatland/envs/rail_env.py
with
18 additions
and
3 deletions
flatland/envs/agent_utils.py
+
16
−
3
View file @
672f0f3c
...
...
@@ -15,6 +15,7 @@ class EnvAgentStatic(object):
direction
=
attrib
()
target
=
attrib
()
moving
=
attrib
(
default
=
False
)
# speed_data: speed is added to position_fraction on each moving step, until position_fraction>=1.0,
# after which 'transition_action_on_cellexit' is executed (equivalent to executing that action in the previous
# cell if speed=1, as default)
...
...
@@ -22,6 +23,11 @@ class EnvAgentStatic(object):
speed_data
=
attrib
(
default
=
Factory
(
lambda
:
dict
({
'
position_fraction
'
:
0.0
,
'
speed
'
:
1.0
,
'
transition_action_on_cellexit
'
:
0
})))
# if broken>0, the agent's actions are ignored for 'broken' steps
# number of time the agent had to stop, since the last time it broke down
broken_data
=
attrib
(
default
=
Factory
(
lambda
:
dict
({
'
broken
'
:
0
,
'
number_of_halts
'
:
0
})))
@classmethod
def
from_lists
(
cls
,
positions
,
directions
,
targets
,
speeds
=
None
):
"""
Create a list of EnvAgentStatics from lists of positions, directions and targets
...
...
@@ -31,7 +37,14 @@ class EnvAgentStatic(object):
speed_datas
.
append
({
'
position_fraction
'
:
0.0
,
'
speed
'
:
speeds
[
i
]
if
speeds
is
not
None
else
1.0
,
'
transition_action_on_cellexit
'
:
0
})
return
list
(
starmap
(
EnvAgentStatic
,
zip
(
positions
,
directions
,
targets
,
[
False
]
*
len
(
positions
),
speed_datas
)))
# TODO: on initialization, all agents are re-set as non-broken. Perhaps it may be desirable to set some as broken?
broken_datas
=
[]
for
i
in
range
(
len
(
positions
)):
broken_datas
.
append
({
'
broken
'
:
0
,
'
number_of_halts
'
:
0
})
return
list
(
starmap
(
EnvAgentStatic
,
zip
(
positions
,
directions
,
targets
,
[
False
]
*
len
(
positions
),
speed_datas
,
broken_datas
)))
def
to_list
(
self
):
...
...
@@ -45,7 +58,7 @@ class EnvAgentStatic(object):
if
type
(
lTarget
)
is
np
.
ndarray
:
lTarget
=
lTarget
.
tolist
()
return
[
lPos
,
int
(
self
.
direction
),
lTarget
,
int
(
self
.
moving
),
self
.
speed_data
]
return
[
lPos
,
int
(
self
.
direction
),
lTarget
,
int
(
self
.
moving
),
self
.
speed_data
,
self
.
broken_data
]
@attrs
...
...
@@ -63,7 +76,7 @@ class EnvAgent(EnvAgentStatic):
def
to_list
(
self
):
return
[
self
.
position
,
self
.
direction
,
self
.
target
,
self
.
handle
,
self
.
old_direction
,
self
.
old_position
,
self
.
moving
,
self
.
speed_data
]
self
.
old_direction
,
self
.
old_position
,
self
.
moving
,
self
.
speed_data
,
self
.
broken_data
]
@classmethod
def
from_static
(
cls
,
oStatic
):
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/rail_env.py
+
2
−
0
View file @
672f0f3c
...
...
@@ -196,6 +196,8 @@ class RailEnv(Environment):
for
i_agent
in
range
(
self
.
get_num_agents
()):
agent
=
self
.
agents
[
i_agent
]
agent
.
speed_data
[
'
position_fraction
'
]
=
0.0
agent
.
broken_data
[
'
broken
'
]
=
0
agent
.
broken_data
[
'
number_of_halts
'
]
=
0
self
.
num_resets
+=
1
self
.
_elapsed_steps
=
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