Struct entromatica::Simulation
source · pub struct Simulation { /* private fields */ }Expand description
All information and methods needed to run the simulation.
All information is managed by the methods of this struct. Do not change properties manually.
Implementations§
source§impl Simulation
impl Simulation
pub fn new() -> Self
sourcepub fn from(
resources: HashMap<ResourceName, Resource>,
initial_state: State,
rules: HashMap<RuleName, Rule>
) -> Result<Simulation, NotFoundError<ResourceName, (EntityName, Entity)>>
pub fn from(
resources: HashMap<ResourceName, Resource>,
initial_state: State,
rules: HashMap<RuleName, Rule>
) -> Result<Simulation, NotFoundError<ResourceName, (EntityName, Entity)>>
Creates a new simulation with the given resources, initial state and rules.
Examples found in repository?
src/lib.rs (lines 304-308)
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
pub fn is_doubly_statistical(&self) -> Result<bool, ResourceCapacityError> {
let mut simulation = Simulation::from(
self.resources.clone(),
self.initial_state.clone(),
self.rules.clone(),
)
.map_err(ResourceCapacityError::NotFound)?;
let mut current_reachable_states = simulation.reachable_states.clone();
while current_reachable_states.len() != self.reachable_states.len()
&& current_reachable_states
.iter()
.map(|(state_hash, _)| state_hash)
.all(|state_hash| self.reachable_states.contains(state_hash))
{
current_reachable_states = simulation.reachable_states.clone();
simulation.next_step()?;
}
let uniform_probability = Probability::from(1. / simulation.possible_states.len() as f64);
let uniform_distribution: ReachableStates = ReachableStates::from(HashMap::from_iter(
simulation.possible_states.iter().map(|(state_hash, _)| {
let prob: (StateHash, Probability) = (*state_hash, uniform_probability);
prob
}),
));
let mut uniform_simulation = simulation.clone();
uniform_simulation.reachable_states = uniform_distribution;
let uniform_entropy = uniform_simulation.reachable_states.entropy();
uniform_simulation.next_step()?;
let uniform_entropy_after_step = uniform_simulation.reachable_states.entropy();
Ok(uniform_entropy == uniform_entropy_after_step)
}sourcepub fn next_step(&mut self) -> Result<(), ResourceCapacityError>
pub fn next_step(&mut self) -> Result<(), ResourceCapacityError>
Runs the simulation for one timestep.
Examples found in repository?
src/lib.rs (line 318)
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
pub fn is_doubly_statistical(&self) -> Result<bool, ResourceCapacityError> {
let mut simulation = Simulation::from(
self.resources.clone(),
self.initial_state.clone(),
self.rules.clone(),
)
.map_err(ResourceCapacityError::NotFound)?;
let mut current_reachable_states = simulation.reachable_states.clone();
while current_reachable_states.len() != self.reachable_states.len()
&& current_reachable_states
.iter()
.map(|(state_hash, _)| state_hash)
.all(|state_hash| self.reachable_states.contains(state_hash))
{
current_reachable_states = simulation.reachable_states.clone();
simulation.next_step()?;
}
let uniform_probability = Probability::from(1. / simulation.possible_states.len() as f64);
let uniform_distribution: ReachableStates = ReachableStates::from(HashMap::from_iter(
simulation.possible_states.iter().map(|(state_hash, _)| {
let prob: (StateHash, Probability) = (*state_hash, uniform_probability);
prob
}),
));
let mut uniform_simulation = simulation.clone();
uniform_simulation.reachable_states = uniform_distribution;
let uniform_entropy = uniform_simulation.reachable_states.entropy();
uniform_simulation.next_step()?;
let uniform_entropy_after_step = uniform_simulation.reachable_states.entropy();
Ok(uniform_entropy == uniform_entropy_after_step)
}sourcepub fn get_graph(&self) -> Graph<State, RuleName>
pub fn get_graph(&self) -> Graph<State, RuleName>
Gets a graph from the possible states with the nodes being the states and the directed edges being the rule names.
sourcepub fn is_doubly_statistical(&self) -> Result<bool, ResourceCapacityError>
pub fn is_doubly_statistical(&self) -> Result<bool, ResourceCapacityError>
Checks if the uniform distribution is a steady state i.e. if the transition rate matrix is doubly statistical.
Trait Implementations§
source§impl Clone for Simulation
impl Clone for Simulation
source§fn clone(&self) -> Simulation
fn clone(&self) -> Simulation
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for Simulation
impl Debug for Simulation
source§impl Default for Simulation
impl Default for Simulation
source§fn default() -> Simulation
fn default() -> Simulation
Returns the “default value” for a type. Read more