pub struct BasicBelief { /* private fields */ }Expand description
An implementation of Belief.
Implementations§
Source§impl BasicBelief
impl BasicBelief
Sourcepub fn new(name: String) -> Self
pub fn new(name: String) -> Self
Create a new BasicBelief with random Uuid.
§Arguments
name: The name of the BasicBelief.
§Returns
The new BasicBelief with a Uuid generated using
uuid::Uuid::new_v4.
§Examples
use belief_spread::BasicBelief;
let b = BasicBelief::new("Belief 1".to_string());Sourcepub fn new_with_uuid(name: String, uuid: Uuid) -> Self
pub fn new_with_uuid(name: String, uuid: Uuid) -> Self
Create a new BasicBelief with specified Uuid.
§Arguments
name: The name of the BasicBelief.uuid: The Uuid of the BasicBelief.
§Returns
The new BasicBelief.
§Examples
use belief_spread::BasicBelief;
use uuid::Uuid;
let b = BasicBelief::new_with_uuid("Belief 1".to_string(), Uuid::new_v4());Trait Implementations§
Source§impl Belief for BasicBelief
impl Belief for BasicBelief
Source§fn get_perception(&self, behaviour: &BehaviourPtr) -> Option<f64>
fn get_perception(&self, behaviour: &BehaviourPtr) -> Option<f64>
Gets the perception, returning a f64 if found.
The perception is the amount an agent performing the behaviour can be assumed to be driven by this belief.
This is a value between -1 and +1.
§Arguments
behaviour: The behaviour.
§Returns
The value, if found.
§Examples
use belief_spread::{BasicBelief, BasicBehaviour, Belief, BehaviourPtr};
let mut b = BasicBelief::new("Belief 1".to_string());
let behaviour = BasicBehaviour::new("Behaviour 1".to_string());
let beh_ptr: BehaviourPtr = behaviour.into();
b.set_perception(beh_ptr.clone(), Some(0.1));
assert_eq!(b.get_perception(&beh_ptr).unwrap(), 0.1);Source§fn set_perception(
&mut self,
behaviour: BehaviourPtr,
perception: Option<f64>,
) -> Result<(), OutOfRangeError>
fn set_perception( &mut self, behaviour: BehaviourPtr, perception: Option<f64>, ) -> Result<(), OutOfRangeError>
Sets the perception.
The perception is the amount an agent performing the behaviour can be assumed to be driven by this belief.
Deletes a behaviour if no perception is supplied.
This is a value between -1 and +1.
§Arguments
behaviour: The BehaviourPtr.perception: The new perception.
§Returns
A Result, Ok if nothing is wrong, or an Err with a OutOfRangeError, if the perception is not in range [-1, +1].
§Examples
use belief_spread::{BasicBelief, BasicBehaviour, Belief, BehaviourPtr};
let mut b = BasicBelief::new("Belief 1".to_string());
let behaviour = BasicBehaviour::new("Behaviour 1".to_string());
let beh_ptr: BehaviourPtr = behaviour.into();
b.set_perception(beh_ptr.clone(), Some(0.1));
assert_eq!(b.get_perception(&beh_ptr).unwrap(), 0.1);Source§fn get_relationship(&self, belief: &BeliefPtr) -> Option<f64>
fn get_relationship(&self, belief: &BeliefPtr) -> Option<f64>
Gets the relationship, returning a f64 if found.
The relationship is the amount another belief can be deemed to be compatible with holding this belief, given that you already hold this belief.
This is a value between -1 and +1.
§Arguments
belief: The other Belief.
§Returns
The value, if found.
§Examples
use belief_spread::{BasicBelief, BasicBehaviour, Belief, UUIDd, Named, BeliefPtr};
let mut b = BasicBelief::new("Belief 1".to_string());
let b2 = BasicBelief::new("Belief 2". to_string());
let b2_ptr: BeliefPtr = b2.into();
b.set_relationship(b2_ptr.clone(), Some(0.1));
assert_eq!(b.get_relationship(&b2_ptr).unwrap(), 0.1);Source§fn set_relationship(
&mut self,
belief: BeliefPtr,
relationship: Option<f64>,
) -> Result<(), OutOfRangeError>
fn set_relationship( &mut self, belief: BeliefPtr, relationship: Option<f64>, ) -> Result<(), OutOfRangeError>
Sets the relationship.
The relationship is the amount another belief can be deemed to be compatible with holding this belief, given that you already hold this belief.
Deletes a belief is no relationship is supplied.
This is a value between -1 and +1.
§Arguments
belief: The other Belief.relationship: The new relationship
§Returns
A Result, Ok if nothing is wrong, or an Err with a OutOfRangeError, if the relationship is not in range [-1, +1].
§Examples
use belief_spread::{BasicBelief, BasicBehaviour, Belief, UUIDd, Named, BeliefPtr};
let mut b = BasicBelief::new("Belief 1".to_string());
let b2 = BasicBelief::new("Belief 2". to_string());
let b2_ptr: BeliefPtr = b2.into();
b.set_relationship(b2_ptr.clone(), Some(0.1));
assert_eq!(b.get_relationship(&b2_ptr).unwrap(), 0.1);Source§impl Clone for BasicBelief
impl Clone for BasicBelief
Source§fn clone(&self) -> BasicBelief
fn clone(&self) -> BasicBelief
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BasicBelief
impl Debug for BasicBelief
Source§impl From<BasicBelief> for BeliefPtr
impl From<BasicBelief> for BeliefPtr
Source§fn from(b: BasicBelief) -> Self
fn from(b: BasicBelief) -> Self
Convert from a BasicBelief into a BeliefPtr.
This consumes the BasicBelief.
§Arguments
b: The BasicBelief to convert.
§Returns
The BeliefPtr.
§Examples
use belief_spread::{BasicBelief, BeliefPtr};
let b = BasicBelief::new("Belief 1".to_string());
let b_ptr = BeliefPtr::from(b);use belief_spread::{BasicBelief, BeliefPtr};
let b = BasicBelief::new("Belief 1".to_string());
let b_ptr: BeliefPtr = b.into();Source§impl Hash for BasicBelief
impl Hash for BasicBelief
Source§impl Named for BasicBelief
impl Named for BasicBelief
Source§fn name(&self) -> &str
fn name(&self) -> &str
Get the name of the BasicBelief.
Source§fn set_name(&mut self, name: String)
fn set_name(&mut self, name: String)
Set the name of the BasicBelief.
Source§impl PartialEq for BasicBelief
impl PartialEq for BasicBelief
Source§impl UUIDd for BasicBelief
impl UUIDd for BasicBelief
Source§fn uuid(&self) -> &Uuid
fn uuid(&self) -> &Uuid
Get the UUID of the BasicBelief.
Source§fn set_uuid(&mut self, u: Uuid)
fn set_uuid(&mut self, u: Uuid)
Set the UUID of the BasicBelief.