Struct cnetworks::Network [−][src]
pub struct Network { /* fields omitted */ }
Expand description
Network
is the main graph-like data structure.
Implementations
Get the weight of the link between nodes i and j.
Returns None
if such link does not exist and Err
if i and j are the same or do not
exist.
Establish a link between nodes i and j with current network’s weight. Returns the weight
if the requested link already exist, None
if it does not. Returns Err
if i
and j are the same or do not exist.
Establish a link between nodes i and j with specified weight
. Updates the link weight and
returns the old value if it already exist, None
otherwise. Returns Err
if i
and j are the same or do not exist, or if the weight is not in the range (0, 1].
Unsafely remove a link between two nodes. Does not perform a check whether the integrity of the network is preserved.
Returns the weight of the removed connection or None
if the connection does not exist and
Err
if i and j are the same or do not exist.
Safely remove a link between two nodes ensuring the network does not split. Performs a BFS search to check whether the integrity of the network is preserved.
Returns the weight of removed link or None
if the link does not exist or cannot be safely
removed. Returns Err
if i and j are the same or do not exist.
Unsafely disconnect a node from the network by removing all of its links. Does not check if the network integrity is perserved.
Returns the removed links as a HashMap
of (target, weight) pairs. Returns Err
if i
and j are the same or do not exist.
Safely disconnect a node from the network by removing all of its links. Performs a bfs search to ensure that the other nodes can stil all reach each other, ie. the integrity of the network is perserved.
Returns removed links as HashMap
of (target, weight) pairs or None
if node
cannot be
safely disconnected. Returns Err
if node
does not exist.
Removes ALL links in the network and sets the model
to Model::None
such that
the initial linking process can be conducted again, eg. using a different model in
combination with Network::init_*
.
Create a new network of given size and desired model. Use Model::None
if you want
a network with no connections.
Examples
Creating a network of chosen model and random link weight:
use cnetworks::*;
let net = Network::new(20, Model::ER { p: 0.4, whole: true }, Weight::Uniform);
println!("{:?}", net);
Creating a network with no links and establishing them “by hand”:
use cnetworks::*;
let mut net = Network::new(10, Model::None, Weight::Constant { c: 0.25 });
net.link(1, 2);
net.link(4, 7);
println!("{:?}", net);
Try to borrow the network-local rng thread from it’s RefCell
. This is effectively to
calling a RefCell::try_borrow_mut()
.
Return iterator containing the node indexes. Use nodes()
to iterate over the nodes
themselves and enumerated()
to use both indexes and values at once.
Return iterator containing the network nodes.
Return iterator containing the (index, node) pairs.
Returns immutable reference to a given node if it exists, Err
if it does not.
Return the number of connected nodes in the network, ie. ones that have at least one link
Calculate the arithmetical average of vertex degrees (ie. number of closest neighbors) in the network.
Get the total degree of the network, ie. sum of degrees over all of the nodes.
pub fn flag(
&mut self,
index: usize,
name: &str,
content: FlagContent
) -> Result<Option<FlagContent>, CNErr>
pub fn flag(
&mut self,
index: usize,
name: &str,
content: FlagContent
) -> Result<Option<FlagContent>, CNErr>
Set a flag with specified name and content. Updates existing flag and returns the old
contents, or None
if the flag was not set. Returns Err
if specified node does not
exist.
Remove a flag with specified name. Returns the contents or None
if flag was not set.
Returns Err
if specified node does not exist.
Get all nodes containing given flag. Returns HashMap of (node index, flag value) pairs.
Get all nodes not containing given flag. Returns vector of node indexes.
Clear the flag from all nodes. Returns iterator of the removed (node index, flag value) pairs.
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Enables easy non-mutable access to the nodes using the indexing operator.
Auto Trait Implementations
impl !RefUnwindSafe for Network
impl UnwindSafe for Network
Blanket Implementations
Mutably borrows from an owned value. Read more