Struct cnetworks::Network [−][src]
pub struct Network { /* fields omitted */ }
Expand description
Network
is the main graph-like data structure.
Implementations
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()
.
pub fn indexes(
&self
) -> impl DoubleEndedIterator<Item = usize> + ExactSizeIterator<Item = usize> + '_
pub fn indexes(
&self
) -> impl DoubleEndedIterator<Item = usize> + ExactSizeIterator<Item = usize> + '_
Return iterator containing the node indexes.
Use Network::nodes()
to iterate over the nodes themselves and Network::enumerate()
to use both indexes
and values at once.
Keep in mind that nodes are always ordered by their index, but it’s possible to have a network of nodes with non-sequential indexes, such as (0,2,3) or (100, 101, 150), but not (10, 0 1).
pub fn nodes(
&self
) -> impl DoubleEndedIterator<Item = &Node> + ExactSizeIterator<Item = &Node>
pub fn nodes(
&self
) -> impl DoubleEndedIterator<Item = &Node> + ExactSizeIterator<Item = &Node>
Return iterator containing the network nodes, ordered by their index.
Return iterator containing the (index, node) pairs. Note that this is not strictly
equivalent to Network::nodes().enumerate()
, since a node’s index doesn’t always
equal it’s position in the iterator, even though nodes are always ordered by their index.
For instance, it’s possible to have a network of nodes with indexes (0, 2, 3) or (100, 101, 150), but not (10, 0, 1).
Return 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.
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
using 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) pairsm 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_*
.
Attach new nodes with specified indexes. Note that the nodes must be connected to the rest of the network manually, as no links will be automatically established.
Returns Err
if there already exists a node with any of the specified indexes. No nodes
will be attached in that case.
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 a given flag. Returns HashMap of (node index, flag value) pairs.
Get all nodes not containing a 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