Skip to main content

hypergraph_rs/core/
kinds.rs

1//! The two node kinds and membership edge type for the bipartite representation.
2
3use serde::{Deserialize, Serialize};
4
5/// The two roles in the bipartite structure.
6///
7/// `Agent` nodes are the hypergraph's nodes (entities). `Hyperedge` nodes
8/// are the hypergraph's edges — their members are exactly their `Agent`
9/// neighbors in the bipartite graph.
10#[derive(Clone, Debug, Serialize, Deserialize)]
11pub enum NodeKind<N, E> {
12    /// An entity node (XGI "node"). Carries its own attributes.
13    Agent(N),
14    /// A hyperedge node (XGI "edge"). The members of the hyperedge are
15    /// exactly the Agent neighbors.
16    Hyperedge(E),
17}
18
19/// A membership edge in the bipartite graph: Agent <-> Hyperedge.
20///
21/// Carries per-membership attributes (XGI's edge-member attrs).
22#[derive(Clone, Debug, Serialize, Deserialize)]
23pub struct MembershipEdge<M> {
24    /// The per-membership data (e.g., role, strength, visibility).
25    pub member_data: M,
26}
27
28/// The role of a node within a directed hyperedge.
29#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
30pub enum DiRole {
31    /// A sender: the node is in the edge's tail.
32    Tail,
33    /// A receiver: the node is in the edge's head.
34    Head,
35}
36
37/// A directed membership edge in the bipartite graph: always oriented
38/// Agent -> Hyperedge, with `role` distinguishing tail (sender) from head
39/// (receiver).
40#[derive(Clone, Debug, Serialize, Deserialize)]
41pub struct DiMembershipEdge<M> {
42    /// The per-membership data.
43    pub member_data: M,
44    /// Whether the agent is a sender (`Tail`) or receiver (`Head`) of the edge.
45    pub role: DiRole,
46}