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);

Return the network size, ie. the total number of nodes.

Return the model of the network

Return the type of link weight

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 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).

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

Return the total number of edges in the network.

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.

Return the degree distribution of the network as a HashMap of (degree, occurrences) pairs.

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.

Completely remove the node with specified index from the network, disconnecting it first.

Returns Err if node with specified index does not exist.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Enables easy non-mutable access to the nodes using the indexing operator.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.