Skip to content
Snippets Groups Projects
Commit 9a78df3c authored by u214892's avatar u214892
Browse files

Merge branch 'master' of gitlab.aicrowd.com:flatland/flatland into...

Merge branch 'master' of gitlab.aicrowd.com:flatland/flatland into 66-shortest-path-predictor-cleanup-tests
parents 870fdf43 f51c77cb
No related branches found
No related tags found
No related merge requests found
......@@ -105,7 +105,13 @@ Once you have a copy of the source, you can install it with ::
$ python setup.py install
Jupyter Canvas Widget
---------------------
If you work with jupyter notebook you need to install the Jupyer Canvas Widget. To install the Jupyter Canvas Widget read also
https://github.com/Who8MyLunch/Jupyter_Canvas_Widget#installation
Usage
=====
To use flatland in a project ::
......
......@@ -163,8 +163,8 @@ class Demo:
def run_complex_scene():
demo_001 = Demo(Scenario_Generator.load_scenario('complex_scene.pkl'))
demo_001.set_record_frames(os.path.join(__file_dirname__, '..', 'rendering', 'frame_{:04d}.bmp'))
demo_001.run_demo(360)
demo_001.run_demo(120)
if __name__ == "__main__":
Demo.run_complex_scene()
......@@ -291,6 +291,18 @@ def distance_on_rail(pos1, pos2):
return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1])
def get_new_position(position, movement):
""" Utility function that converts a compass movement over a 2D grid to new positions (r, c). """
if movement == Grid4TransitionsEnum.NORTH:
return (position[0] - 1, position[1])
elif movement == Grid4TransitionsEnum.EAST:
return (position[0], position[1] + 1)
elif movement == Grid4TransitionsEnum.SOUTH:
return (position[0] + 1, position[1])
elif movement == Grid4TransitionsEnum.WEST:
return (position[0], position[1] - 1)
def get_rnd_agents_pos_tgt_dir_on_rail(rail, num_agents):
"""
Given a `rail' GridTransitionMap, return a random placement of agents (initial position, direction and target).
......
......@@ -238,14 +238,20 @@ class Controller(object):
bAlt = event["altKey"]
if bCtrl and not bShift and not bAlt:
self.model.click_agent(rcCell)
self.lrcStroke = []
elif bShift and bCtrl:
self.model.add_target(rcCell)
self.lrcStroke = []
elif bAlt and not bShift and not bCtrl:
self.model.clearCell(rcCell)
self.lrcStroke = []
self.debug("click in cell", rcCell)
self.model.debug_cell(rcCell)
if self.model.iSelectedAgent is not None:
self.lrcStroke = []
def setDebug(self, dEvent):
self.model.setDebug(dEvent["new"])
......@@ -271,8 +277,35 @@ class Controller(object):
# If the mouse is held down, enqueue an event in our own queue
# The intention was to avoid too many redraws.
# Reset the lrcStroke list, if ALT, CTRL or SHIFT pressed
if event["buttons"] > 0:
qEvents.append((time.time(), x, y))
bShift = event["shiftKey"]
bCtrl = event["ctrlKey"]
bAlt = event["altKey"]
if bShift:
self.lrcStroke = []
while len(qEvents) > 0:
t, x, y = qEvents.popleft()
return
if bCtrl:
self.lrcStroke = []
while len(qEvents) > 0:
t, x, y = qEvents.popleft()
return
if bAlt:
self.lrcStroke = []
while len(qEvents) > 0:
t, x, y = qEvents.popleft()
return
else:
self.lrcStroke = []
if self.model.iSelectedAgent is not None:
self.lrcStroke = []
while len(qEvents) > 0:
t, x, y = qEvents.popleft()
return
# Process the events in our queue:
# Draw a black square to indicate a trail
......
......@@ -433,12 +433,12 @@ class PILSVG(PILGL):
if (col + row) % 10 > 7:
pilTrack = self.dScenery[0]
else:
if (col + row + col * row) % 2 == 0:
if (col + row + col * row) % 3 == 0:
a = (a + (col + row + col * row)) % len(self.dBuildings)
pilTrack = self.dBuildings[a]
elif (self.background_grid[col][row] > 5) or ((col ** 3 + row ** 2 + col * row) % 10 == 0):
a = int(self.background_grid[col][row]) - 5
a = a % len(self.dScenery)
elif (self.background_grid[col][row] > 4) or ((col ** 3 + row ** 2 + col * row) % 10 == 0):
a = int(self.background_grid[col][row]) - 4
a = (a + (col + row + col * row + col ** 3 + row ** 4)) % len(self.dScenery)
if (col + row + col * row) % 10 > 2:
a = 0
pilTrack = self.dScenery[a]
......
......@@ -100,7 +100,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c96cefa474204cb1992da3eb286fb659",
"model_id": "140f16d2c9a643e39d68c6421e50b9bd",
"version_major": 2,
"version_minor": 0
},
......
%% Cell type:markdown id: tags:
# Plot the Env and some trees
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Cell type:code id: tags:
``` python
import jpy_canvas
import random
import time
import sys
```
%% Cell type:code id: tags:
``` python
# in case you need to tweak your PYTHONPATH...
sys.path.append("../flatland")
```
%% Cell type:code id: tags:
``` python
import flatland.core.env
import flatland.utils.rendertools as rt
from flatland.envs.rail_env import RailEnv, random_rail_generator
from flatland.envs.observations import TreeObsForRailEnv
```
%% Cell type:code id: tags:
``` python
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:90% !important; }</style>"))
```
%% Output
%% Cell type:markdown id: tags:
# Generate
%% Cell type:code id: tags:
``` python
nAgents = 3
fnMethod = random_rail_generator(cell_type_relative_proportion=[1] * 11)
env = RailEnv(width=20,
height=10,
rail_generator=fnMethod,
number_of_agents=nAgents,
obs_builder_object=TreeObsForRailEnv(max_depth=2))
```
%% Cell type:markdown id: tags:
# Render
%% Cell type:code id: tags:
``` python
oRT = rt.RenderTool(env,gl="PILSVG")
oRT.renderEnv()
img = oRT.getImage()
```
%% Output
Illegal target rail: 3 13 0001011000000001
Illegal target rail: 5 13 0100000000000010
%% Cell type:code id: tags:
``` python
jpy_canvas.Canvas(img)
```
%% Output
......
......@@ -20,21 +20,21 @@ if os.name == 'nt':
is64bit = p[0] == '64bit'
if sys.version[0:3] == '3.5':
if is64bit:
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.0-cp35-cp35m-win_amd64.whl'
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.1-cp35-cp35m-win_amd64.whl'
else:
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.0-cp35-cp35m-win32.whl'
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.1-cp35-cp35m-win32.whl'
if sys.version[0:3] == '3.6':
if is64bit:
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.0-cp36-cp36m-win_amd64.whl'
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.1-cp36-cp36m-win_amd64.whl'
else:
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.0-cp36-cp36m-win32.whl'
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.1-cp36-cp36m-win32.whl'
if sys.version[0:3] == '3.7':
if is64bit:
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.0-cp37-cp37m-win_amd64.whl'
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.1-cp37-cp37m-win_amd64.whl'
else:
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.0-cp37-cp37m-win32.whl'
url = 'https://download.lfd.uci.edu/pythonlibs/t4jqbe6o/pycairo-1.18.1-cp37-cp37m-win32.whl'
try:
import pycairo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment