Skip to content
Snippets Groups Projects
Commit 027b7955 authored by hagrid67's avatar hagrid67
Browse files

fixing msgpack serialization probs with numpy arrays appearing in EnvAgent

parent ec7b23e6
No related branches found
No related tags found
No related merge requests found
from attr import attrs, attrib
from itertools import starmap
import numpy as np
# from flatland.envs.rail_env import RailEnv
......@@ -36,7 +37,18 @@ class EnvAgentStatic(object):
return list(starmap(EnvAgentStatic, zip(positions, directions, targets)))
def to_list(self):
return [self.position, self.direction, self.target]
# I can't find an expression which works on both tuples, lists and ndarrays
# which converts them all to a list of native python ints.
lPos = self.position
if type(lPos) is np.ndarray:
lPos = lPos.tolist()
lTarget = self.target
if type(lTarget) is np.ndarray:
lTarget = lTarget.tolist()
return [lPos, int(self.direction), lTarget]
@attrs
......
......@@ -328,6 +328,11 @@ class RailEnv(Environment):
grid_data = self.rail.grid.tolist()
agent_static_data = [agent.to_list() for agent in self.agents_static]
agent_data = [agent.to_list() for agent in self.agents]
msgpack.packb(grid_data)
msgpack.packb(agent_data)
msgpack.packb(agent_static_data)
msg_data = {
"grid": grid_data,
"agents_static": agent_static_data,
......
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