Trait djinn::Simulation
[−]
[src]
pub trait Simulation: Sized + Send + Sync + Clone { type State: State; type World: State; type Update: Update; fn decide<R: Redis>(
&self,
agent: &Agent<Self::State>,
world: &Self::World,
population: &Population<Self, R>,
updates: &mut Updates<Self>
); fn update(
&self,
state: &mut Self::State,
updates: Vec<Self::Update>
) -> bool; fn on_spawns<R: Redis>(
&self,
agents: Vec<Agent<Self::State>>,
population: &Population<Self, R>
) { ... } fn on_deaths<R: Redis>(
&self,
agents: Vec<Agent<Self::State>>,
population: &Population<Self, R>
) { ... } fn world_decide<R: Redis>(
&self,
world: &Self::World,
population: &Population<Self, R>,
updates: &mut Updates<Self>
) { ... } fn world_update(
&self,
world: Self::World,
updates: Vec<Self::Update>
) -> Self::World { ... } }
This trait's implementation defines the main logic of a simulation.
A single simulation step consists of two synchronized phases:
decide
: this is a read-only phase where agents decide on what updates to apply. The updates themselves are not applied in this phase.update
: this is a phase where agents consider queued updates and compute a new state accordingly.
Associated Types
Required Methods
fn decide<R: Redis>(
&self,
agent: &Agent<Self::State>,
world: &Self::World,
population: &Population<Self, R>,
updates: &mut Updates<Self>
)
&self,
agent: &Agent<Self::State>,
world: &Self::World,
population: &Population<Self, R>,
updates: &mut Updates<Self>
)
Computes updates for the specified agents and/or other agents.
fn update(&self, state: &mut Self::State, updates: Vec<Self::Update>) -> bool
Compute a final updated state given a starting state and updates.
If there is some update you want to do every step, things will run faster if you implement it here directly rather than using an Update
.
Provided Methods
fn on_spawns<R: Redis>(
&self,
agents: Vec<Agent<Self::State>>,
population: &Population<Self, R>
)
&self,
agents: Vec<Agent<Self::State>>,
population: &Population<Self, R>
)
Called whenever a new agent is spawned. You can use this to, for example, build an index of agents by state values.
fn on_deaths<R: Redis>(
&self,
agents: Vec<Agent<Self::State>>,
population: &Population<Self, R>
)
&self,
agents: Vec<Agent<Self::State>>,
population: &Population<Self, R>
)
Called whenever an agent is killed. You can use this to, for example, remove an agent from an index.
fn world_decide<R: Redis>(
&self,
world: &Self::World,
population: &Population<Self, R>,
updates: &mut Updates<Self>
)
&self,
world: &Self::World,
population: &Population<Self, R>,
updates: &mut Updates<Self>
)
Compute updates for the world.
fn world_update(
&self,
world: Self::World,
updates: Vec<Self::Update>
) -> Self::World
&self,
world: Self::World,
updates: Vec<Self::Update>
) -> Self::World
Compute a final state for the world given updates.