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) const
    • void GetParents(const int node, std::vector<int>& par) const
    • void GetChildren(const int node, std::vector<int>& child) const
    • bool HasIncomingEdge(int to) const
    • bool HasOutgoingEdge(int from) const

Implementations§

source§

impl Pattern

source

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

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

pub fn get_edge(&self, from: usize, to: usize) -> Result<EdgeType>

Get EdgeType between two nodes

source

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

pub fn set_edge( &mut self, from: usize, to: usize, edge_type: EdgeType, ) -> Result<()>

Set an edge between two nodes to a specific EdgeType.

source

pub fn remove_edge(&mut self, from: usize, to: usize) -> Result<()>

Remove an edge between two nodes

source

pub fn direct_edge(&mut self, from: usize, to: usize) -> Result<()>

Direct an edge between two nodes

source

pub fn undirect_edge(&mut self, from: usize, to: usize) -> Result<()>

Undirect an edge between two nodes

source

pub fn to_dag(&mut self) -> Result<()>

Try to convert the pattern to a Directed Acyclic Graph

source

pub fn is_dag(&self) -> bool

Check if the pattern is a Directed Acyclic Graph

source

pub fn has_cycle(&self) -> bool

Check if the pattern has a cycle

source

pub fn get_node(&self, index: usize) -> Result<PatternNode<'_>>

Get a PatternNode for a specific node index

source

pub fn into_network(self) -> Result<Network>

Convert the pattern to a network

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.