Struct cnetworks::Network[][src]

pub struct Network { /* fields omitted */ }

Network is a graph-like data structure, containing a Vec of Node objects.

Implementations

impl Network[src]

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

Removes 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>, String>[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>>, String>
[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 NetworkModel::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: NetworkModel, weight: LinkWeight) -> Self[src]

Create a new network of given size and desired model. Use NetworkModel::None if you want a network with no connections.

Examples

Creating a network of chosen model and link weight:

let net = Network::new(20, NetworkModel::ER { p: 0.4, true }, LinkWeight::Uniform);
println!("{:?}", net);

Creating a network with no links and establishing them “by hand”:

let net = Network::new(10, NetworkModel::None, LinkWeight::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 NetworkModel 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 NetworkModel 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]

Calculates the arithmetical average of vertex degrees (ie. number of closest neighbors) over the network.

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

Returns the degree distribution of the network as a HashMap of histogram bins where key - degree, value - number of occurences in the network.

pub fn clear(&mut self)[src]

Sets the infected on all nodes to false.

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

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

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

Returns a HashSet with indexes of infected nodes.

Trait Implementations

impl Clone for Network[src]

impl Debug for Network[src]

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]

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.

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