pub struct EventQueueModel<S, A, Store, Props, R>{ /* private fields */ }Expand description
Continuous-time agent-based model driven by an event queue.
§Type Parameters
S- space typeA- agent type implementingAgentStore- agent container implementingAgentStore<A>Props- user-defined model properties (use()if unused)R- RNG type
§Example
let actions: Vec<fn(&mut MyAgent, &mut EventContext<...>)> = vec![tick_action];
let mut model = EventQueueModel::new(store, space, (), rng, actions);
model.add_event(agent_id, 0, 1.0); // fire action 0 at t+1.0
model.step_until(100.0);Implementations§
Source§impl<S, A, Store, Props, R> EventQueueModel<S, A, Store, Props, R>
impl<S, A, Store, Props, R> EventQueueModel<S, A, Store, Props, R>
Sourcepub fn insert_positioned_agent(
&mut self,
agent: A,
) -> Result<(), InteractionError<S::Error>>
pub fn insert_positioned_agent( &mut self, agent: A, ) -> Result<(), InteractionError<S::Error>>
Insert a positioned agent into both the store and the space atomically.
Sourcepub fn remove_positioned_agent(
&mut self,
id: AgentId,
) -> Result<Option<A>, InteractionError<S::Error>>
pub fn remove_positioned_agent( &mut self, id: AgentId, ) -> Result<Option<A>, InteractionError<S::Error>>
Remove a positioned agent from both the store and the space atomically.
Sourcepub fn move_positioned_agent(
&mut self,
id: AgentId,
new_position: A::Position,
) -> Result<(), InteractionError<S::Error>>
pub fn move_positioned_agent( &mut self, id: AgentId, new_position: A::Position, ) -> Result<(), InteractionError<S::Error>>
Move a positioned agent, updating both the agent value and spatial index.
Sourcepub fn validate_space_index(&self) -> Result<(), InteractionError<S::Error>>
pub fn validate_space_index(&self) -> Result<(), InteractionError<S::Error>>
Validate that all stored agents are represented by the spatial index.
Sourcepub fn step_event_spatial(&mut self) -> Result<bool, InteractionError<S::Error>>
pub fn step_event_spatial(&mut self) -> Result<bool, InteractionError<S::Error>>
Process the next event and apply deferred add/remove actions to both the agent store and spatial index.
Sourcepub fn step_until_spatial(
&mut self,
t_end: f64,
) -> Result<(), InteractionError<S::Error>>
pub fn step_until_spatial( &mut self, t_end: f64, ) -> Result<(), InteractionError<S::Error>>
Process all events up to and including time t_end with spatially
consistent deferred lifecycle updates.
Sourcepub fn run_events_spatial(
&mut self,
n: usize,
) -> Result<(), InteractionError<S::Error>>
pub fn run_events_spatial( &mut self, n: usize, ) -> Result<(), InteractionError<S::Error>>
Process up to n events with spatially consistent lifecycle updates.
Source§impl<S, A, Store, Props, R> EventQueueModel<S, A, Store, Props, R>
impl<S, A, Store, Props, R> EventQueueModel<S, A, Store, Props, R>
Sourcepub fn new(
agents: Store,
space: S,
properties: Props,
rng: R,
actions: Vec<fn(&mut A, &mut EventContext<'_, S, A, Props, R>)>,
) -> Self
pub fn new( agents: Store, space: S, properties: Props, rng: R, actions: Vec<fn(&mut A, &mut EventContext<'_, S, A, Props, R>)>, ) -> Self
Create a new EventQueueModel.
§Arguments
agents- pre-populated agent store.space- the simulation space.properties- user-defined model properties.rng- seeded random number generator.actions- vector of event-action functions, indexed byevent_idx.
Sourcepub fn properties(&self) -> &Props
pub fn properties(&self) -> &Props
Immutable reference to user-defined properties.
Sourcepub fn properties_mut(&mut self) -> &mut Props
pub fn properties_mut(&mut self) -> &mut Props
Mutable reference to user-defined properties.
Sourcepub fn insert_agent(&mut self, agent: A) -> Result<(), A>
pub fn insert_agent(&mut self, agent: A) -> Result<(), A>
Insert an agent into the store.
Returns Err(agent) if an agent with the same ID already exists.
Sourcepub fn remove_agent(&mut self, id: AgentId) -> Option<A>
pub fn remove_agent(&mut self, id: AgentId) -> Option<A>
Remove an agent by ID, returning it if found.
Events targeting this agent will be silently skipped when they fire.
Sourcepub fn next_id(&mut self) -> AgentId
pub fn next_id(&mut self) -> AgentId
Generate the next unused agent ID (monotonically increasing).
Sourcepub fn queue_is_empty(&self) -> bool
pub fn queue_is_empty(&self) -> bool
Returns true if the event queue is empty.
Sourcepub fn peek_time(&self) -> Option<f64>
pub fn peek_time(&self) -> Option<f64>
Peek at the timestamp of the next (earliest) event, if any.
Sourcepub fn step_event(&mut self) -> bool
pub fn step_event(&mut self) -> bool
Process the next event in the queue.
Returns true if an event was popped (even if the target agent was
removed), false if the queue was empty.
Sourcepub fn step_until(&mut self, t_end: f64)
pub fn step_until(&mut self, t_end: f64)
Process all events up to and including time t_end.
After this call, self.time_f64() == t_end. Events scheduled after
t_end remain in the queue.
Sourcepub fn run_events(&mut self, n: usize)
pub fn run_events(&mut self, n: usize)
Process up to n events from the queue.
Stops early if the queue is exhausted.
Trait Implementations§
Source§impl<S, A, Store, Props, R> Model for EventQueueModel<S, A, Store, Props, R>
impl<S, A, Store, Props, R> Model for EventQueueModel<S, A, Store, Props, R>
Source§type Properties = Props
type Properties = Props
() if unused).Source§type AgentRef<'a> = Ref<'a, A>
where
Self: 'a
type AgentRef<'a> = Ref<'a, A> where Self: 'a
Ref<'a, A> for RefCell-based stores).Source§type AgentRefMut<'a> = RefMut<'a, A>
where
Self: 'a
type AgentRefMut<'a> = RefMut<'a, A> where Self: 'a
RefMut<'a, A>).