Struct cnetworks::Network [−][src]
pub struct Network { /* fields omitted */ }
Expand description
Network
is the main graph-like data structure.
Implementations
impl Network
[src]
impl Network
[src]pub fn get_link(&self, i: usize, j: usize) -> Result<Option<f64>, Error>
[src]
pub fn get_link(&self, i: usize, j: usize) -> Result<Option<f64>, Error>
[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.
pub fn link(&mut self, i: usize, j: usize) -> Result<(), Error>
[src]
pub fn link(&mut self, i: usize, j: usize) -> Result<(), Error>
[src]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
.
pub fn link_exact(
&mut self,
i: usize,
j: usize,
w: f64
) -> Result<Option<f64>, Error>
[src]
pub fn link_exact(
&mut self,
i: usize,
j: usize,
w: f64
) -> Result<Option<f64>, Error>
[src]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.
pub fn unlink(&mut self, i: usize, j: usize) -> Result<Option<f64>, Error>
[src]
pub fn unlink(&mut self, i: usize, j: usize) -> Result<Option<f64>, Error>
[src]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.
pub fn unlink_safe(&mut self, i: usize, j: usize) -> Result<Option<f64>, Error>
[src]
pub fn unlink_safe(&mut self, i: usize, j: usize) -> Result<Option<f64>, Error>
[src]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]
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]
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]
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]
impl Network
[src]pub fn new(size: usize, model: Model, weight: Weight) -> Self
[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]
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]
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 avg_deg(&self) -> f64
[src]
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]
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]
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 get_healthy(&self) -> HashSet<usize>
[src]
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]
pub fn get_infected(&self) -> HashSet<usize>
[src]Return a HashSet
with indexes of infected nodes.
pub fn get_weight(&self) -> Weight
[src]
pub fn get_weight(&self) -> Weight
[src]Return the type of link weight
Trait Implementations
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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,