Struct nice_smile::pattern::Pattern
source · pub struct Pattern { /* private fields */ }Expand description
A pattern, otherwise called an essential graph, is a collection of nodes and edges that can be either directed
Following methods have been implemented:
-
enum EdgeType {None,Undirected,Directed} -
int GetSize() const -
EdgeType GetEdge(int from, int to) const -
void SetEdge(int from, int to, EdgeType type) -
bool HasDirectedPath(int from, int to) const -
bool HasCycle() const -
bool IsDAG() const -
bool ToDAG() -
void Set(DSL_network &input) -
bool ToNetwork(const DSL_dataset &ds, DSL_network &net) -
void Print() const
Differences from the original API:
- Method
void SetSize(int size)has not been implemented, as the default way to construct a Pattern is to call Pattern::with_capacity - Following methods have been implemented on super::PatternNode:
void GetAdjacentNodes(const int node, std::vector<int>& adj) constvoid GetParents(const int node, std::vector<int>& par) constvoid GetChildren(const int node, std::vector<int>& child) constbool HasIncomingEdge(int to) constbool HasOutgoingEdge(int from) const
Implementations§
source§impl Pattern
impl Pattern
sourcepub fn with_capacity(node_count: usize) -> Self
pub fn with_capacity(node_count: usize) -> Self
Create a new pattern with no nodes or edges
Example usage:
// Create a pattern with 5 nodes
let mut pattern = Pattern::with_capacity(5);sourcepub fn get_node_count(&self) -> usize
pub fn get_node_count(&self) -> usize
Get the number of nodes in the pattern
Example usage:
let mut pattern = Pattern::with_capacity(5);
assert_eq!(pattern.get_node_count(), 5);sourcepub fn get_edge(&self, from: usize, to: usize) -> Result<EdgeType>
pub fn get_edge(&self, from: usize, to: usize) -> Result<EdgeType>
Get EdgeType between two nodes
sourcepub fn has_directed_path(&self, from: usize, to: usize) -> Result<bool>
pub fn has_directed_path(&self, from: usize, to: usize) -> Result<bool>
Check if there is a directed path from one node to another.
Example usage:
let mut pattern = Pattern::with_capacity(3);
pattern.remove_edge(0, 2); // Remove edge A --- C
pattern.direct_edge(0, 1); // Direct edge A --> B
pattern.direct_edge(1, 2); // Direct edge B --> C
// Assert directed path A --> B --> C
assert_eq!(pattern.has_directed_path(0, 2), Ok(true));sourcepub fn set_edge(
&mut self,
from: usize,
to: usize,
edge_type: EdgeType,
) -> Result<()>
pub fn set_edge( &mut self, from: usize, to: usize, edge_type: EdgeType, ) -> Result<()>
Set an edge between two nodes to a specific EdgeType.
sourcepub fn remove_edge(&mut self, from: usize, to: usize) -> Result<()>
pub fn remove_edge(&mut self, from: usize, to: usize) -> Result<()>
Remove an edge between two nodes
sourcepub fn direct_edge(&mut self, from: usize, to: usize) -> Result<()>
pub fn direct_edge(&mut self, from: usize, to: usize) -> Result<()>
Direct an edge between two nodes
sourcepub fn undirect_edge(&mut self, from: usize, to: usize) -> Result<()>
pub fn undirect_edge(&mut self, from: usize, to: usize) -> Result<()>
Undirect an edge between two nodes
sourcepub fn get_node(&self, index: usize) -> Result<PatternNode<'_>>
pub fn get_node(&self, index: usize) -> Result<PatternNode<'_>>
Get a PatternNode for a specific node index
sourcepub fn into_network(self) -> Result<Network>
pub fn into_network(self) -> Result<Network>
Convert the pattern to a network
Auto Trait Implementations§
impl Freeze for Pattern
impl !RefUnwindSafe for Pattern
impl !Send for Pattern
impl !Sync for Pattern
impl Unpin for Pattern
impl UnwindSafe for Pattern
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more