pub struct VoterModel {
pub n_states: usize,
}Expand description
Voter model: each agent copies a random neighbor’s opinion.
Fields§
§n_states: usizeNumber of opinion states (default 2 for binary).
Implementations§
Source§impl VoterModel
impl VoterModel
Sourcepub fn run(
&self,
graph: &NetworkGraph,
opinions: &mut Vec<usize>,
steps: usize,
seed: u64,
)
pub fn run( &self, graph: &NetworkGraph, opinions: &mut Vec<usize>, steps: usize, seed: u64, )
Runs steps asynchronous updates on integer opinions (values 0..n_states-1).
Sourcepub fn fraction(&self, opinions: &[usize], state: usize) -> f64
pub fn fraction(&self, opinions: &[usize], state: usize) -> f64
Returns fraction of agents holding opinion state.
Sourcepub fn is_consensus(&self, opinions: &[usize]) -> bool
pub fn is_consensus(&self, opinions: &[usize]) -> bool
Returns true if all agents hold the same opinion (consensus).
Auto Trait Implementations§
impl Freeze for VoterModel
impl RefUnwindSafe for VoterModel
impl Send for VoterModel
impl Sync for VoterModel
impl Unpin for VoterModel
impl UnsafeUnpin for VoterModel
impl UnwindSafe for VoterModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.