def observation(self, agent, world):
        # get positions of all entities in this agent's reference frame
        entity_pos = []
        for entity in world.landmarks:
            entity_pos.append(entity.state.p_pos - agent.state.p_pos)

        other_pos = []
        other_vel = []
        for other in world.agents:
            if other is agent: continue
            other_pos.append(other.state.p_pos - agent.state.p_pos)
            if not other.adversary:
                other_vel.append(other.state.p_vel)

        e = float(GeoSeries(Point(agent.state.p_pos * world.norm)).distance(world.red).values[0])
        ii = world.es.house_wall_geo(world.es.buildinginf[agent.index]["walls"]) \
            .translate(xoff=agent.state.p_pos[0] * world.norm[0],yoff=agent.state.p_pos[1] * world.norm[1]) \
            .distance(world.red).values[0]

        request = world.request[agent.index].tolist()
        # print(request)
        # print(type(request))
        # print(request.shape)
        request = request[:agent.index] + request[agent.index + 1:]
        # request
        distance = world.distance[agent.index].tolist()
        distance = distance[:agent.index] + distance[agent.index + 1:]

        return np.concatenate([agent.state.p_vel] + other_pos + other_vel + [request] + [distance] + [[e]] + [[ii]])
def _ensure_geometry(data):
    """
    Ensure the data is of geometry dtype or converted to it.

    If input is a (Geo)Series, output is a GeoSeries, otherwise output
    is GeometryArray.
    """
    if is_geometry_type(data):
        if isinstance(data, Series):
            return GeoSeries(data)
        return data
    else:
        if isinstance(data, Series):
            out = from_shapely(np.asarray(data))
            return GeoSeries(out, index=data.index, name=data.name)
        else:
            out = from_shapely(data)
            return out
Exemple #3
0
def _ensure_geometry(data, crs=None):
    """
    Ensure the data is of geometry dtype or converted to it.

    If input is a (Geo)Series, output is a GeoSeries, otherwise output
    is GeometryArray.

    If the input is a GeometryDtype with a set CRS, `crs` is ignored.
    """
    if is_geometry_type(data):
        if isinstance(data, Series):
            return GeoSeries(data)
        return data
    else:
        if isinstance(data, Series):
            out = from_shapely(np.asarray(data), crs=crs)
            return GeoSeries(out, index=data.index, name=data.name)
        else:
            out = from_shapely(data, crs=crs)
            return out
Exemple #4
0
    def observation(self, agent, world):
        # get positions of all entities in this agent's reference frame
        entity_pos = []
        for entity in world.landmarks:
            entity_pos.append(entity.state.p_pos - agent.state.p_pos)

        other_pos = []
        other_vel = []
        for other in world.agents:
            if other is agent: continue
            other_pos.append(other.state.p_pos - agent.state.p_pos)
            if not other.adversary:
                other_vel.append(other.state.p_vel)

        e = float(
            GeoSeries(Point(agent.state.p_pos)).distance(self.red).values[0])
        ii = self.es.house_wall_geo(self.es.buildinginf[int(agent.name.split()[1])]["walls"]) \
            .translate(xoff=agent.state.p_pos[0],yoff=agent.state.p_pos[1]) \
            .distance(self.red).values[0]

        return np.concatenate([agent.state.p_vel] + other_pos + other_vel +
                              [[e]] + [[ii]])
Exemple #5
0
 def red_line_geo(self, red_line_raw):
     red_line = GeoSeries(Polygon([(i[0], i[1]) for i in red_line_raw]))
     return red_line
Exemple #6
0
 def house_wall_geo(self, house_wall_raw):
     house_wall = GeoSeries(Polygon(np.reshape(house_wall_raw, (-1, 2))))
     return house_wall