Trait Agent

Source
pub trait Agent {
    // Required methods
    fn update<D: DB, V: Validator, R: RngCore>(
        &mut self,
        rng: &mut R,
        env: &mut Env<D, V>,
    ) -> Vec<Transaction>;
    fn get_address(&self) -> Address;
}
Expand description

Trait defining behaviour for a single agent

This is intended to be called for each individual agent at each step of the simulation, updating the state of the agent and recording state data.

§Examples

use rand::RngCore;
use alloy_primitives::Address;
use verbs_rs::{DB, env::{Env, Validator}};
use verbs_rs::agent::{Agent, RecordedAgent, AgentVec, AgentSet};
use verbs_rs::contract::Transaction;

struct DummyAgent{
    state: i32,
}

impl Agent for DummyAgent {
    fn update<D: DB, V: Validator, R: RngCore>(
        &mut self, rng: &mut R, network: &mut Env<D, V>
    ) -> Vec<Transaction> {
        self.state += 1;
        Vec::default()
    }

    fn get_address(&self) -> Address {
        Address::ZERO
    }
}

Required Methods§

Source

fn update<D: DB, V: Validator, R: RngCore>( &mut self, rng: &mut R, env: &mut Env<D, V>, ) -> Vec<Transaction>

Update the agent and optionally return a Transaction this should not update the state of the evm directly.

§Arguments
  • rng: Random generate
  • env: Simulation environment
Source

fn get_address(&self) -> Address

Get the address of the agent.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§