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
sfwatergit
Flatland
Commits
d70f2642
Commit
d70f2642
authored
5 years ago
by
u214892
Browse files
Options
Downloads
Patches
Plain Diff
#57 first steps importlib_resources
parent
9464e58c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
env-data/__init__.py
+0
-0
0 additions, 0 deletions
env-data/__init__.py
env-data/railway/__init__.py
+0
-0
0 additions, 0 deletions
env-data/railway/__init__.py
examples/demo.py
+11
-23
11 additions, 23 deletions
examples/demo.py
flatland/envs/rail_env.py
+7
-2
7 additions, 2 deletions
flatland/envs/rail_env.py
with
18 additions
and
25 deletions
env-data/__init__.py
0 → 100644
+
0
−
0
View file @
d70f2642
This diff is collapsed.
Click to expand it.
env-data/railway/__init__.py
0 → 100644
+
0
−
0
View file @
d70f2642
This diff is collapsed.
Click to expand it.
examples/demo.py
+
11
−
23
View file @
d70f2642
...
@@ -53,7 +53,7 @@ class Scenario_Generator:
...
@@ -53,7 +53,7 @@ class Scenario_Generator:
return
env
return
env
@staticmethod
@staticmethod
def
load_scenario
(
filename
,
number_of_agents
=
3
):
def
load_scenario
(
resource
,
package
=
'
env-data.railway
'
,
number_of_agents
=
3
):
env
=
RailEnv
(
width
=
2
*
(
1
+
number_of_agents
),
env
=
RailEnv
(
width
=
2
*
(
1
+
number_of_agents
),
height
=
1
+
number_of_agents
)
height
=
1
+
number_of_agents
)
...
@@ -64,11 +64,8 @@ class Scenario_Generator:
...
@@ -64,11 +64,8 @@ class Scenario_Generator:
[filename,
[filename,
number_of_agents=number_of_agents)
number_of_agents=number_of_agents)
"""
"""
if
os
.
path
.
exists
(
filename
):
env
.
load_resource
(
package
,
resource
)
env
.
load
(
filename
)
env
.
reset
(
False
,
False
)
env
.
reset
(
False
,
False
)
else
:
print
(
"
File does not exist:
"
,
filename
,
"
Working directory:
"
,
os
.
getcwd
())
return
env
return
env
...
@@ -135,45 +132,36 @@ if False:
...
@@ -135,45 +132,36 @@ if False:
demo_001
.
run_demo
()
demo_001
.
run_demo
()
demo_001
=
None
demo_001
=
None
demo_000
=
Demo
(
Scenario_Generator
.
load_scenario
(
demo_000
=
Demo
(
Scenario_Generator
.
load_scenario
(
'
example_network_000.pkl
'
))
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
env-data
'
,
'
railway
'
,
'
example_network_000.pkl
'
)))
demo_000
.
run_demo
()
demo_000
.
run_demo
()
demo_000
=
None
demo_000
=
None
demo_001
=
Demo
(
Scenario_Generator
.
load_scenario
(
demo_001
=
Demo
(
Scenario_Generator
.
load_scenario
(
'
example_network_001.pkl
'
))
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
env-data
'
,
'
railway
'
,
'
example_network_001.pkl
'
)))
demo_001
.
run_demo
()
demo_001
.
run_demo
()
demo_001
=
None
demo_001
=
None
demo_002
=
Demo
(
Scenario_Generator
.
load_scenario
(
demo_002
=
Demo
(
Scenario_Generator
.
load_scenario
(
'
example_network_002.pkl
'
))
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
env-data
'
,
'
railway
'
,
'
example_network_002.pkl
'
)))
demo_002
.
run_demo
()
demo_002
.
run_demo
()
demo_002
=
None
demo_002
=
None
demo_flatland_000
=
Demo
(
demo_flatland_000
=
Demo
(
Scenario_Generator
.
load_scenario
(
'
example_flatland_000.pkl
'
))
Scenario_Generator
.
load_scenario
(
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
env-data
'
,
'
railway
'
,
'
example_flatland_000.pkl
'
)))
demo_flatland_000
.
renderer
.
resize
()
demo_flatland_000
.
renderer
.
resize
()
demo_flatland_000
.
run_demo
(
60
)
demo_flatland_000
.
run_demo
(
60
)
demo_flatland_000
=
None
demo_flatland_000
=
None
demo_flatland_000
=
Demo
(
demo_flatland_000
=
Demo
(
Scenario_Generator
.
load_scenario
(
'
example_network_003.pkl
'
))
Scenario_Generator
.
load_scenario
(
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
env-data
'
,
'
railway
'
,
'
example_network_003.pkl
'
)))
demo_flatland_000
.
renderer
.
resize
()
demo_flatland_000
.
renderer
.
resize
()
demo_flatland_000
.
set_max_framerate
(
5
)
demo_flatland_000
.
set_max_framerate
(
5
)
demo_flatland_000
.
run_demo
(
30
)
demo_flatland_000
.
run_demo
(
30
)
demo_flatland_000
=
None
demo_flatland_000
=
None
demo_flatland_000
=
Demo
(
demo_flatland_000
=
Demo
(
Scenario_Generator
.
load_scenario
(
'
example_flatland_001.pkl
'
))
Scenario_Generator
.
load_scenario
(
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
env-data
'
,
'
railway
'
,
'
example_flatland_001.pkl
'
)))
demo_flatland_000
.
renderer
.
resize
()
demo_flatland_000
.
renderer
.
resize
()
demo_flatland_000
.
set_record_frames
(
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
rendering
'
,
'
frame_{:04d}.bmp
'
))
demo_flatland_000
.
set_record_frames
(
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
rendering
'
,
'
frame_{:04d}.bmp
'
))
demo_flatland_000
.
run_demo
(
60
)
demo_flatland_000
.
run_demo
(
60
)
demo_flatland_000
=
None
demo_flatland_000
=
None
demo_001
=
Demo
(
Scenario_Generator
.
load_scenario
(
'
./env-data/railway/
complex_scene.pkl
'
))
demo_001
=
Demo
(
Scenario_Generator
.
load_scenario
(
'
complex_scene.pkl
'
))
demo_001
.
set_record_frames
(
'
./
rendering
/
frame_{:04d}.bmp
'
)
demo_001
.
set_record_frames
(
os
.
path
.
join
(
__file_dirname__
,
'
..
'
,
'
rendering
'
,
'
frame_{:04d}.bmp
'
)
)
demo_001
.
run_demo
(
360
)
demo_001
.
run_demo
(
360
)
demo_001
=
None
demo_001
=
None
This diff is collapsed.
Click to expand it.
flatland/envs/rail_env.py
+
7
−
2
View file @
d70f2642
...
@@ -216,11 +216,11 @@ class RailEnv(Environment):
...
@@ -216,11 +216,11 @@ class RailEnv(Environment):
if
action
==
RailEnvActions
.
DO_NOTHING
and
agent
.
moving
:
if
action
==
RailEnvActions
.
DO_NOTHING
and
agent
.
moving
:
# Keep moving
# Keep moving
# Changed MOVE_FORWARD to DO_NOTHING
# Changed MOVE_FORWARD to DO_NOTHING
#action_dict[iAgent] = RailEnvActions.DO_NOTHING
#
action_dict[iAgent] = RailEnvActions.DO_NOTHING
action
=
RailEnvActions
.
MOVE_FORWARD
action
=
RailEnvActions
.
MOVE_FORWARD
if
action
==
RailEnvActions
.
STOP_MOVING
and
agent
.
moving
:
if
action
==
RailEnvActions
.
STOP_MOVING
and
agent
.
moving
:
#action_dict[iAgent] = RailEnvActions.DO_NOTHING
#
action_dict[iAgent] = RailEnvActions.DO_NOTHING
# CHanged DO_NOTHING to STOP_MOVING
# CHanged DO_NOTHING to STOP_MOVING
# action = RailEnvActions.STOP_MOVING
# action = RailEnvActions.STOP_MOVING
agent
.
moving
=
False
agent
.
moving
=
False
...
@@ -391,3 +391,8 @@ class RailEnv(Environment):
...
@@ -391,3 +391,8 @@ class RailEnv(Environment):
with
open
(
filename
,
"
rb
"
)
as
file_in
:
with
open
(
filename
,
"
rb
"
)
as
file_in
:
load_data
=
file_in
.
read
()
load_data
=
file_in
.
read
()
self
.
set_full_state_msg
(
load_data
)
self
.
set_full_state_msg
(
load_data
)
def
load_resource
(
self
,
package
,
resource
):
from
importlib_resources
import
read_binary
load_data
=
read_binary
(
package
,
resource
)
self
.
set_full_state_msg
(
load_data
)
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