pub trait AgentSet {
    // Required method
    fn update<R: RngCore>(&mut self, env: &mut Env, rng: &mut R);
}
Expand description

Functionality required for simulation agents

Simulation agents provided as an argument to crate::sim_runner must implement this trait, but the details of the implementation are left to the user.

It’s a common case that we want update to update a heterogeneous set of agents which can be automatically implemented with the Agents macro as long as the agent types implement the Agent trait.

§Examples

use bourse_de::Env;
use bourse_de::agents::{Agent, Agents, AgentSet};
use rand::RngCore;

struct AgentType{}

impl Agent for AgentType {
    fn update<R: RngCore>(
        &mut self, env: &mut Env, _rng: &mut R
    ) {}
}

#[derive(Agents)]
struct MixedAgents {
    a: AgentType,
    b: AgentType
}

this is equivalent to

struct MixedAgents {
    a: AgentType,
    b: AgentType
}

impl AgentSet for MixedAgents {
    fn update<R: RngCore>(&mut self, env: &mut Env, rng: &mut R){
        self.a.update(env, rng);
        self.b.update(env, rng);
    }
}

Required Methods§

source

fn update<R: RngCore>(&mut self, env: &mut Env, rng: &mut R)

Update function called each simulated step

This function should update the state of the agent(s) and submit transactions to the simulation environment

The implementing struct is flexible in what it represent, from a single agent to a group of multiple agent types.

§Arguments
  • env - Simulation environment
  • rng - Random generator

Object Safety§

This trait is not object safe.

Implementors§