pub struct Dag { /* private fields */ }Expand description
Static directed acyclic graph over variables.
Implementations§
Source§impl Dag
impl Dag
Sourcepub fn ancestors_of(
&self,
nodes: &[DenseNodeId],
out: &mut BitSet,
ws: &mut GraphWorkspace,
)
pub fn ancestors_of( &self, nodes: &[DenseNodeId], out: &mut BitSet, ws: &mut GraphWorkspace, )
Collect all ancestors of nodes (including nodes themselves) into out.
Sourcepub fn descendants_of(
&self,
nodes: &[DenseNodeId],
out: &mut BitSet,
ws: &mut GraphWorkspace,
)
pub fn descendants_of( &self, nodes: &[DenseNodeId], out: &mut BitSet, ws: &mut GraphWorkspace, )
Collect all descendants of nodes (including nodes) into out.
Sourcepub fn is_ancestor(&self, anc: DenseNodeId, desc: DenseNodeId) -> bool
pub fn is_ancestor(&self, anc: DenseNodeId, desc: DenseNodeId) -> bool
Whether anc is an ancestor of desc (or equal).
Sourcepub fn markov_blanket(
&self,
node: DenseNodeId,
out: &mut BitSet,
) -> Result<(), GraphError>
pub fn markov_blanket( &self, node: DenseNodeId, out: &mut BitSet, ) -> Result<(), GraphError>
Markov blanket of node: parents ∪ children ∪ spouses (co-parents of
children). Does not include node itself.
§Errors
Unknown node id.
Sourcepub fn markov_blanket_nodes(
&self,
node: DenseNodeId,
) -> Result<Vec<DenseNodeId>, GraphError>
pub fn markov_blanket_nodes( &self, node: DenseNodeId, ) -> Result<Vec<DenseNodeId>, GraphError>
Sourcepub fn mutilate(&self, intervened: &[DenseNodeId]) -> Result<Dag, GraphError>
pub fn mutilate(&self, intervened: &[DenseNodeId]) -> Result<Dag, GraphError>
Mutilate the graph under intervention: remove all edges into each intervened node. Returns a new DAG (nodes preserved).
Prefer Dag::view with GraphOverlay::do_intervention on hot paths
to avoid cloning adjacency.
§Errors
Unknown node ids.
Source§impl Dag
impl Dag
Sourcepub fn with_variables(n: u32) -> Self
pub fn with_variables(n: u32) -> Self
Build a DAG with one static node per variable 0..n.
Sourcepub fn from_named_edges(
schema: &CausalSchema,
edges: &[(&str, &str)],
) -> Result<Self, GraphError>
pub fn from_named_edges( schema: &CausalSchema, edges: &[(&str, &str)], ) -> Result<Self, GraphError>
Build a DAG with one static node per schema variable (VariableId raw == dense id),
then insert directed edges named by schema variable names.
§Errors
Unknown names, duplicate edges, or cycles.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes.
Sourcepub fn add_node(&mut self, node: NodeRef) -> Result<DenseNodeId, GraphError>
pub fn add_node(&mut self, node: NodeRef) -> Result<DenseNodeId, GraphError>
Sourcepub fn insert_directed(
&mut self,
from: DenseNodeId,
to: DenseNodeId,
) -> Result<(), GraphError>
pub fn insert_directed( &mut self, from: DenseNodeId, to: DenseNodeId, ) -> Result<(), GraphError>
Insert a directed edge from -> to if it preserves acyclicity.
§Errors
Unknown nodes, duplicates, or cycles.
Sourcepub fn remove_directed(&mut self, from: DenseNodeId, to: DenseNodeId)
pub fn remove_directed(&mut self, from: DenseNodeId, to: DenseNodeId)
Remove a directed edge if present.
Sourcepub fn children(&self, id: DenseNodeId) -> &[DenseNodeId]
pub fn children(&self, id: DenseNodeId) -> &[DenseNodeId]
Children of id.
Sourcepub fn parents(&self, id: DenseNodeId) -> &[DenseNodeId]
pub fn parents(&self, id: DenseNodeId) -> &[DenseNodeId]
Parents of id.
Sourcepub fn reaches(&self, from: DenseNodeId, to: DenseNodeId) -> bool
pub fn reaches(&self, from: DenseNodeId, to: DenseNodeId) -> bool
Whether from can reach to via directed edges.
Sourcepub fn reaches_with(
&self,
from: DenseNodeId,
to: DenseNodeId,
ws: &mut GraphWorkspace,
) -> bool
pub fn reaches_with( &self, from: DenseNodeId, to: DenseNodeId, ws: &mut GraphWorkspace, ) -> bool
Reachability using a reusable workspace.
Sourcepub fn topological_order(&self) -> Option<Vec<DenseNodeId>>
pub fn topological_order(&self) -> Option<Vec<DenseNodeId>>
Topological order (Kahn). Returns None if a cycle slipped in.
Sourcepub fn validate(&self) -> Result<(), GraphError>
pub fn validate(&self) -> Result<(), GraphError>
Sourcepub fn edges(&self) -> impl Iterator<Item = MarkedEdge> + '_
pub fn edges(&self) -> impl Iterator<Item = MarkedEdge> + '_
Iterate directed edges as marked edges.
Sourcepub fn directed_paths(
&self,
from: DenseNodeId,
to: DenseNodeId,
max_paths: usize,
max_len: usize,
) -> Result<Vec<Vec<DenseNodeId>>, GraphError>
pub fn directed_paths( &self, from: DenseNodeId, to: DenseNodeId, max_paths: usize, max_len: usize, ) -> Result<Vec<Vec<DenseNodeId>>, GraphError>
Enumerate simple directed paths from from to to (inclusive endpoints).
Bounded by max_paths and max_len (number of nodes on the path).
The returned set is silently truncated when either bound binds. Callers whose
correctness depends on seeing every path — e.g. a recanting-witness test, which
concludes “no witness exists” from the absence of one — must use
Self::directed_paths_with_budget and fail closed on truncation instead.
§Errors
Unknown nodes.
Sourcepub fn directed_paths_with_budget(
&self,
from: DenseNodeId,
to: DenseNodeId,
max_paths: usize,
max_len: usize,
) -> Result<(Vec<Vec<DenseNodeId>>, bool), GraphError>
pub fn directed_paths_with_budget( &self, from: DenseNodeId, to: DenseNodeId, max_paths: usize, max_len: usize, ) -> Result<(Vec<Vec<DenseNodeId>>, bool), GraphError>
Self::directed_paths plus a flag reporting whether enumeration was cut short.
The flag is true when max_paths stopped the search with candidates still
pending, or when max_len pruned a partial path that had not yet reached to.
It is deliberately conservative: true means “the path set may be incomplete”,
never “it is definitely incomplete”.
§Errors
Unknown nodes.
Source§impl Dag
impl Dag
Sourcepub fn is_d_separated(
&self,
x: DenseNodeId,
y: DenseNodeId,
z: &[DenseNodeId],
ws: &mut DSeparationWorkspace,
) -> Result<bool, GraphError>
pub fn is_d_separated( &self, x: DenseNodeId, y: DenseNodeId, z: &[DenseNodeId], ws: &mut DSeparationWorkspace, ) -> Result<bool, GraphError>
Whether x is d-separated from y given z (boolean; no path alloc).
If Z ∩ {x,y} ≠ ∅ the query is ill-posed and this returns false
(not separated), matching PAG m-separation / definite-status activity.
§Errors
Unknown node ids.
Sourcepub fn is_d_separated_batch(
&self,
queries: &[(DenseNodeId, DenseNodeId, &[DenseNodeId])],
out: &mut [bool],
ws: &mut DSeparationWorkspace,
) -> Result<(), GraphError>
pub fn is_d_separated_batch( &self, queries: &[(DenseNodeId, DenseNodeId, &[DenseNodeId])], out: &mut [bool], ws: &mut DSeparationWorkspace, ) -> Result<(), GraphError>
Batch boolean d-separation. out[i] corresponds to queries[i] = (x,y,z).
§Errors
Unknown nodes; or out.len() != queries.len().