Struct cnetworks::Network[][src]

pub struct Network { /* fields omitted */ }
Expand description

Network is the main graph-like data structure.

Implementations

impl Network[src]

Get the weight of the link between nodes i and j.

Returns None if such link does not exist and Err if either i or j does not exist in the network.

Establish a link between nodes i and j with current network’s weight. Returns Err if either i or j does not exist in the network. Does nothing if the requested link already exist.

This is a more user-friendly interface to the public-in-super _link.

Establish a link between nodes i and j with sepcified weight. Updates the link weight and returns the old value if it already exist, None otherwise. Returns Err if either i or j does not exist in the network.

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 either i or j does not exist in the network.

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 either i or j does not exist in the network.

pub fn disconnect(&mut self, node: usize) -> Result<HashMap<usize, f64>, Error>[src]

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 node does not exist in the network.

pub fn disconnect_safe(
    &mut self,
    node: usize
) -> Result<Option<HashMap<usize, f64>>, Error>
[src]

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 in the network.

pub fn disconnect_all(&mut self)[src]

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_*.

impl Network[src]

pub fn new(size: usize, model: Model, weight: Weight) -> Self[src]

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

pub fn init_er(net: &mut Network, p: f64, whole: bool)[src]

Initialize (or reinitialize) the network’s links according to the Erdos-Renyi model. See the Model for more detailed model explanation.

If whole is true then the network is artificially stitched together after initialization, otherwise there is no guarantee that there are no ‘outsiders’ or even separate networks.

Beware that the network is not cleared before linking.

pub fn init_ba(net: &mut Network, m0: usize, m: usize)[src]

Initialize (or reinitialize) the network’s links according to the Barabasi-Albert model. See the Model for more detailed model explanation.

The links are cleared before re-linking because of the nautre of initialization algorithm

pub fn edges(&self) -> usize[src]

Return the total number of edges in the network.

pub fn avg_deg(&self) -> f64[src]

Calculate the arithmetical average of vertex degrees (ie. number of closest neighbors) in the network.

pub fn deg_distr(&self) -> HashMap<usize, usize>[src]

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

pub fn clusters(&self) -> Vec<HashSet<usize>>[src]

Obtain vector of clusters present in the network, ordered largest to smallest.

A random element of net is chosen as the root and the initial cluster is the first (explored) set returned by explore(net, root). From the second (unexplored) set a new node is chosen as the new root, and the process is repeated until there are no more unexplored nodes.

Examples

use cnetworks::*;
let net = Network::new(100, Model::ER { p: 0.05, whole: false }, Weight::Constant { c: 1.0});
let clusters = net.clusters();
println!("Largest cluster: {:?}", clusters.first().expect("No clusters"));
println!("Smallest cluster: {:?}", clusters.last().expect("No clusters"));

pub fn clear(&mut self)[src]

Set the infected on all nodes to false.

pub fn get_healthy(&self) -> HashSet<usize>[src]

Return a HashSet with indexes of healthy (not infected) nodes.

pub fn get_infected(&self) -> HashSet<usize>[src]

Return a HashSet with indexes of infected nodes.

pub fn get_model(&self) -> Model[src]

Return the model of the network

pub fn get_weight(&self) -> Weight[src]

Return the type of link weight

Trait Implementations

impl Clone for Network[src]

fn clone(&self) -> Network[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Network[src]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl RefUnwindSafe for Network

impl Send for Network

impl Sync for Network

impl Unpin for Network

impl UnwindSafe for Network

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

pub fn vzip(self) -> V