BasicBelief

Struct BasicBelief 

Source
pub struct BasicBelief { /* private fields */ }
Expand description

An implementation of Belief.

Implementations§

Source§

impl BasicBelief

Source

pub fn new(name: String) -> Self

Create a new BasicBelief with random Uuid.

§Arguments
§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());
Source

pub fn new_with_uuid(name: String, uuid: Uuid) -> Self

Create a new BasicBelief with specified Uuid.

§Arguments
§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

Source§

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>

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>

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
§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>

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

Source§

fn clone(&self) -> BasicBelief

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BasicBelief

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<BasicBelief> for BeliefPtr

Source§

fn from(b: BasicBelief) -> Self

Convert from a BasicBelief into a BeliefPtr.

This consumes the BasicBelief.

§Arguments
§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

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Named for BasicBelief

Source§

fn name(&self) -> &str

Get the name of the BasicBelief.

Source§

fn set_name(&mut self, name: String)

Set the name of the BasicBelief.

Source§

impl PartialEq for BasicBelief

Source§

fn eq(&self, other: &Self) -> bool

Compare if two BasicBeliefs are equal, solely by their UUID.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl UUIDd for BasicBelief

Source§

fn uuid(&self) -> &Uuid

Get the UUID of the BasicBelief.

Source§

fn set_uuid(&mut self, u: Uuid)

Set the UUID of the BasicBelief.

Source§

impl Eq for BasicBelief

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V