Skip to content

Conversation

@Gamenot
Copy link
Collaborator

@Gamenot Gamenot commented Feb 22, 2023

Still WIP.

See #1839 for context.

New plan

Message format is like:

class Header(NamedTuple):
   channel: str
   sender: str
   sender_type: str
   cc: Set[str]
   bcc: Set[str]
   format: str

class Message(NamedTuple):
   content: Any

Use idea is the following:

def filter_useless(transmissions):
   for header, msg in transmissions:
      if header.sender in ("parked_agent", "broken_stoplight"):
         continue
      if header.sender_type in ("advertisement",):
         continue
      yield header, msg

class GossiperAgent:
   def __init__(self, id_, filter, friends):
      self._filter = filter
      self._id = id_
      self._friends = friends

   def act(self, observation):
      out_transmissions = []
      for header, msg in filter(observation["transmissions"]):
         if not {self._id, "__all__"}.intersection(header["cc"] | header["bcc"]):
            continue
         if header.channel == "position_request":
            out_transmissions.append((
               Header(
                  channel="position",
                  sender=self._id,
                  sender_type="ad_vehicle",
                  cc={header.sender},
                  bcc={*self.friends},
                  format="position",
               )._as_dict(), # optimize this later
               Message(
                  content=obs.ego_vehicle_state.position,
               )._as_dict(), # optimize this later
            ))
         ...
      ...
      action = policy.select_action(observation)
      return (base_action, out_transmissions)

# for now
env = MessagePasser(
   hiwayv1env,
   max_message_bytes=MESSAGE_BYTES,
   message_config={
      "gossiper0": (
         V2XTransmitter(bands=Bands.ALL, range=100, available_channels=["position_request", "position"]),
         V2XReceiver(bands=Bands.ALL, aliases=["tim"], blacklist_channels=["self_control"]),
      ),
      ...
   },
)
gossiper_agent = GossiperAgent("gossiper0", filter=filter_useless, friends={"schemer", "gossiper1"})
oblivious_gossiper_agent = GossiperAgent("gossiper1", filter=filter_all, friends={"schemer"})
schemer_agent = SchemerAgent("schemer")

# then just the standard gym interface with no modifications
obs, info = env.reset()
for ...:
   actions = {agent_id: agent.act(obs[agent_id]) for agent_id, agent in agents}
   obs, reward, term, trunc, info = env.step(actions)

@Gamenot Gamenot requested a review from Adaickalavan February 22, 2023 19:20
@Gamenot Gamenot self-assigned this Feb 22, 2023
@Gamenot Gamenot requested review from Adaickalavan and removed request for Adaickalavan February 24, 2023 17:49
@Gamenot Gamenot force-pushed the tucker/add_agent_communication branch from e9a22c0 to f6355a6 Compare March 1, 2023 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants