pub struct Network<N: NodeType, L: Copy + Debug + Send + Sized, EXTID: Copy + Debug + Send + Sized + Ord = ExternalId> { /* private fields */ }Expand description
A directed, acylic network.
Implementations§
Source§impl<N: NodeType, L: Copy + Debug + Send + Sized, EXTID: Copy + Debug + Send + Sized + Ord> Network<N, L, EXTID>
impl<N: NodeType, L: Copy + Debug + Send + Sized, EXTID: Copy + Debug + Send + Sized + Ord> Network<N, L, EXTID>
pub fn new() -> Network<N, L, EXTID>
pub fn node_count(&self) -> usize
pub fn link_count(&self) -> usize
pub fn node(&self, node_idx: NodeIndex) -> &Node<N, EXTID>
pub fn node_mut(&mut self, node_idx: NodeIndex) -> &mut Node<N, EXTID>
pub fn link(&self, link_idx: LinkIndex) -> &Link<L, EXTID>
pub fn link_mut(&mut self, link_idx: LinkIndex) -> &mut Link<L, EXTID>
pub fn nodes(&self) -> &[Node<N, EXTID>]
pub fn each_node_with_index<F>(&self, f: F)
pub fn link_iter_for_node<'a>( &'a self, node_idx: NodeIndex, ) -> LinkIter<'a, L, EXTID> ⓘ
pub fn link_ref_iter_for_node<'a>( &'a self, node_idx: NodeIndex, ) -> LinkRefIter<'a, N, L, EXTID> ⓘ
pub fn each_active_forward_link_of_node<F>(&self, node_idx: NodeIndex, f: F)
pub fn each_link_ref<F>(&self, f: F)where
F: FnMut(LinkRefItem<'_, N, L, EXTID>),
pub fn each_link_mut<F>(&mut self, f: F)
Sourcepub fn random_inactive_link_index<R: Rng>(
&self,
rng: &mut R,
) -> Option<LinkIndex>
pub fn random_inactive_link_index<R: Rng>( &self, rng: &mut R, ) -> Option<LinkIndex>
§Complexity
O(number of links)
Sourcepub fn random_active_link_index<R: Rng>(&self, rng: &mut R) -> Option<LinkIndex>
pub fn random_active_link_index<R: Rng>(&self, rng: &mut R) -> Option<LinkIndex>
§Complexity
O(number of links)
Sourcepub fn remove_all_outgoing_links_of_node(&mut self, node_idx: NodeIndex)
pub fn remove_all_outgoing_links_of_node(&mut self, node_idx: NodeIndex)
Removes all outgoing links of node node_idx.
XXX: This can be optimized.
§Complexity
O(k), where k is the number of edges of node_idx.
Sourcepub fn remove_all_incoming_links_of_node(&mut self, node_idx: NodeIndex)
pub fn remove_all_incoming_links_of_node(&mut self, node_idx: NodeIndex)
Removes all incoming links to node node_idx.
XXX: This can be optimized.
Sourcepub fn remove_all_inout_links_of_node(&mut self, node_idx: NodeIndex)
pub fn remove_all_inout_links_of_node(&mut self, node_idx: NodeIndex)
Removes all links to and from node node_idx.
Sourcepub fn remove_node(&mut self, node_idx: NodeIndex)
pub fn remove_node(&mut self, node_idx: NodeIndex)
Remove the node with index node_idx including
all incoming and outgoing links.
Moves the last node in the nodes array into the empty place and rewires all links. As such, this is a quite heavy operation!
§Danger!
The external NodeIndex of the last node is changed!
§Complexity
Worst case O(e), where e is the total number of edges in the graph.
Sourcepub fn add_node(&mut self, node_type: N, external_node_id: EXTID) -> NodeIndex
pub fn add_node(&mut self, node_type: N, external_node_id: EXTID) -> NodeIndex
Adds a new node to the network with type node_type and the associated
id external_node_id. The external_node_id is stored in the node and
can be retrieved later on.
Sourcepub fn find_random_unconnected_link_no_cycle<R: Rng>(
&self,
rng: &mut R,
) -> Option<(NodeIndex, NodeIndex)>
pub fn find_random_unconnected_link_no_cycle<R: Rng>( &self, rng: &mut R, ) -> Option<(NodeIndex, NodeIndex)>
Returns a random link between two unconnected nodes, which would not introduce a cycle. Return None is no such exists.
Sourcepub fn link_would_cycle(
&self,
source_node_idx: NodeIndex,
target_node_idx: NodeIndex,
) -> bool
pub fn link_would_cycle( &self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, ) -> bool
Returns true if the introduction of this directed link would lead towards a cycle.
pub fn valid_link( &self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, ) -> Result<(), &'static str>
pub fn disable_link_index(&mut self, link_idx: LinkIndex) -> bool
pub fn enable_link_index(&mut self, link_idx: LinkIndex) -> bool
pub fn disable_link( &mut self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, ) -> bool
pub fn enable_link( &mut self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, ) -> bool
pub fn first_link_of_node(&self, node_idx: NodeIndex) -> Option<&Link<L, EXTID>>
pub fn last_link_of_node(&self, node_idx: NodeIndex) -> Option<&Link<L, EXTID>>
pub fn add_link( &mut self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, weight: L, external_link_id: EXTID, ) -> LinkIndex
pub fn add_link_unordered( &mut self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, weight: L, external_link_id: EXTID, ) -> LinkIndex
pub fn add_link_with_active( &mut self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, weight: L, external_link_id: EXTID, active: bool, ) -> LinkIndex
pub fn has_link( &self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, ) -> bool
Sourcepub fn remove_link_at(&mut self, link_index: LinkIndex)
pub fn remove_link_at(&mut self, link_index: LinkIndex)
Remove the link at index link_index.
Sourcepub fn remove_link(
&mut self,
source_node_idx: NodeIndex,
target_node_idx: NodeIndex,
) -> bool
pub fn remove_link( &mut self, source_node_idx: NodeIndex, target_node_idx: NodeIndex, ) -> bool
Remove the first link that matches source_node_idx and target_node_idx.
XXX