Skip to main content

Module sim

Module sim 

Source
Expand description

A deterministic simulated network for running teams of agents: seeded delays, losses, topologies and partitions.

A Simulation runs any Participant, such as a cbba::Agent. Each Simulation::step is one tick:

flowchart LR
    deliver[deliver due messages] --> round[every agent's round]
    round --> broadcast[broadcast every outbox]
    broadcast --> deliver

Agents may also answer a delivered message right away; those answers go out with the tick’s broadcasts. A broadcast reaches every agent the sender has a link to in the Topology and is not cut off from by an active Partition; others hear of it only when it is relayed. Each copy is lost with probability Network::loss_per_mille / 1000, and otherwise arrives after 1 to 1 + max_delay ticks, so messages overtake each other. Agents process the messages that arrive in a tick in arrival order. Everything random comes from Network::seed: the same seed gives the same run.

Two optional models make the network harsher: Network::collisions lets senders that cannot hear each other destroy each other’s copies, and Network::clusters lets groups of agents exchange messages with each other only every few ticks. Both are off by default and draw no randomness then, so seeded runs stay the same.

Stats counts what the run cost: copies sent, delivered and lost, the bytes broadcast, and how many delivered copies changed their receiver.

When a team is settled is up to the protocol (Participant::is_settled). For CBBA, every agent believes in the same winners, every agent’s bundle holds exactly the tasks it wins, no bundle phase would change anything, and every message still in flight carries those same winners. Nothing can change after that.

Structs§

Clusters
Groups of agents that exchange messages at different rates: inside a group as usual, between groups only every period ticks.
Network
How the simulated network behaves.
Partition
A time interval in which agents in different groups cannot reach each other.
Simulation
A team of agents on a simulated network.
Stats
Message counts over a run.

Enums§

Topology
Which pairs of agents can exchange messages directly. Agents without a direct link only hear of each other through relays.

Constants§

BACKOFF_SLOTS
The backoff slots a sender picks from each tick when Network::collisions is on.

Traits§

Participant
An agent that a Simulation can run: it works in rounds, broadcasts messages, and handles the messages that reach it.