sim_rust/
traits.rs

1//! This module holds all the traits that have to be implemented for
2//! the agent to be a plugable compontent.
3//!
4//! The following mental model is used to the api design.
5//!
6//! There will be constructor functions that construct and run the simulation automatically. These
7//! functions can take in any abritrary type that has implemented the correct traits. This makes it
8//! so multiple types can be defined as agents and a simulation can be run in the same manner as
9//! with only a single agent type.
10//!
11//! The point of the simulations is to add some form of random sequencing. This means there will
12//! need to be multiple runs of the simulation with the same input parameters. One simulation run
13//! will be fully separate of another simulation run, making a multiprocess execution model a very
14//! good candidate for speeding up the program.
15//!
16//! The process will look something like this:
17//!
18//!
19//! /*                  Environment
20//!                         |
21//!                 --------------------
22//!                 |       |           |
23//!             [Agent_1,   |           |
24//!                         Agent_2,    |
25//!                                     Agent_3, ... ]
26//! */
27//!
28//! The environment will give out a tick command that propagates down to all the agents contained
29//! in its system.
30//!
31//! /*                Environment.tick()
32//!                         |
33//!                 --------------------
34//!                 |       |           |
35//!     [Agent_1.tick()     |           |
36//!                     Agent_2.tick()  |
37//!                                 Agent_3.tick() ]
38//! */
39//!
40//!
41//! /*                  Environment.collect()
42//!                         |
43//!                 --------------------
44//!                 |       |           |
45//!     [Agent_1.collect()  |           |
46//!                     Agent_2.collect()
47//!                                 Agent_3.collect() ]
48//! */
49
50pub trait Agent {
51    ///
52    fn generate() -> Result<Box<Self>, &'static str>
53    where
54        Self: Sized;
55
56    ///
57    fn collect(&self) -> Result<String, &'static str>;
58
59    ///
60    fn tick(&mut self) -> Result<(), &'static str>;
61}
62
63pub trait Environment {
64    ///
65    fn generate(pop: Vec<Box<dyn Agent>>) -> Result<Box<Self>, &'static str>
66    where
67        Self: Sized;
68
69    ///
70    fn collect(&self) -> Result<String, &'static str>;
71
72    ///
73    fn tick(&mut self) -> Result<(), &'static str>;
74
75    //
76    fn add_agent(&mut self, agent: Box<dyn Agent>) -> Result<(), &'static str>;
77
78    //
79    fn add_agents(&mut self, agents: Vec<Box<dyn Agent>>) -> Result<(), &'static str>;
80}