Hypergraphs Core API
Hypergraph Core
- class graphcalc.hypergraphs.core.basics.Hypergraph(*, rank_max: int | None = None, allow_empty: bool = False, allow_singletons: bool = False, auto_add_vertices: bool = True, V: Iterable[Hashable] | None = None, E: Iterable[Iterable[Hashable]] | None = None)[source]
Bases:
objectFinite simple undirected hypergraph represented as a set system.
The hypergraph is stored as a pair
(V, E)whereVis a set of vertices andEis a set of hyperedges, each represented as afrozensetof vertices.Conventions
simple: duplicate hyperedges are ignored
undirected: hyperedges are sets
empty hyperedges are disallowed by default
singleton hyperedges are disallowed by default
an optional upper bound on hyperedge size may be enforced via
rank_max
- param rank_max:
Optional maximum allowed hyperedge size.
- type rank_max:
int | None, default=None
- param allow_empty:
Whether the empty hyperedge is permitted.
- type allow_empty:
bool, default=False
- param allow_singletons:
Whether singleton hyperedges are permitted.
- type allow_singletons:
bool, default=False
- param auto_add_vertices:
If True, vertices appearing in added hyperedges are automatically inserted into
V. If False, each hyperedge must already be a subset ofV.- type auto_add_vertices:
bool, default=True
- param V:
Initial vertex set.
- type V:
iterable, optional
- param E:
Initial hyperedge set.
- type E:
iterable of iterables, optional
Notes
The internal sets are stored privately as
_Vand_E. Public access is provided through read-only properties.- property E: FrozenSet[FrozenSet[Hashable]]
Return the hyperedge set as a read-only frozenset.
- property V: FrozenSet[Hashable]
Return the vertex set as a read-only frozenset.
- copy() Hypergraph[source]
Return a shallow copy of the hypergraph.
- dual() Hypergraph[source]
Return the dual hypergraph.
The vertices of the dual are the hyperedges of the original, indexed as integers
0, 1, ..., m-1in the iteration order ofself._E.Notes
The dual may contain singleton or empty hyperedges even if the original hypergraph disallows them, so the dual is constructed with
allow_empty=Trueandallow_singletons=True.
- classmethod from_edges(edges: Iterable[Iterable[Hashable]], *, vertices: Iterable[Hashable] | None = None, rank_max: int | None = None, allow_empty: bool = False, allow_singletons: bool = False, auto_add_vertices: bool = True) Hypergraph[source]
Construct a hypergraph from an iterable of hyperedges.
- induced_subhypergraph(vertices: Iterable[Hashable]) Hypergraph[source]
Return the induced subhypergraph on a vertex subset.
Hyperedges are intersected with the subset and only valid resulting hyperedges are retained.
- property is_empty: bool
Return True iff the hypergraph has no hyperedges.
- is_incidence_connected() bool[source]
Test connectivity of the incidence bipartite graph.
Isolated vertices count: if
Vcontains an isolated vertex, then the incidence graph is disconnected unless the whole hypergraph is empty.
- is_uniform(k: int | None = None) bool[source]
Return whether the hypergraph is uniform.
If
kis provided, test whether every hyperedge has sizek. Otherwise, test whether all hyperedges have the same size.
- property m: int
Number of hyperedges.
- property n: int
Number of vertices.
- property rank: int
Maximum hyperedge size present, or 0 if there are no hyperedges.
- remove_vertex(v: Hashable, *, drop_incident_edges: bool = True) None[source]
Remove a vertex.
- Parameters:
v (hashable) – Vertex to remove.
drop_incident_edges (bool, default=True) – If True, remove every incident hyperedge. If False, remove the vertex from each incident hyperedge and re-validate the result.