Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ coverage.xml
docs/_build/

/main.py

# Test artifacts
test_directed_read_and_write.txt
test_undirected_read_and_write.txt
test_mixed_read_and_write.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
halp: Hypergraph Algorithms Package<br>
==========

_halp_ is a Python software package that provides both a directed and an undirected hypergraph implementation, as well as several important and canonical algorithms that operate on these hypergraphs.
_halp_ is a Python software package that provides directed, undirected, and mixed hypergraph implementations, as well as several important and canonical algorithms that operate on these hypergraphs.

See [http://murali-group.github.io/halp/](http://murali-group.github.io/halp/) for documentation, code examples, and more information.

4 changes: 2 additions & 2 deletions halp/algorithms/directed_random_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def stationary_distribution(H, pi=None, P=None):
it will be created.
:returns: list -- list of the stationary probabilities for all nodes
in the hypergraph.
:raises: TypeError -- Algorithm only applicable to undirected hypergraphs
:raises: TypeError -- Algorithm only applicable to directed hypergraphs
:raises: AssertionError -- Each node must have at least 1 outgoing
hyperedge (even if it's only a self-loop).

"""
if not isinstance(H, DirectedHypergraph):
raise TypeError("Algorithm only applicable to undirected hypergraphs")
raise TypeError("Algorithm only applicable to directed hypergraphs")

for node in H.node_iterator():
if len(H.get_forward_star(node)) == 0:
Expand Down
17 changes: 11 additions & 6 deletions halp/directed_hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ def add_node(self, node, attr_dict=None, **attr):
:param attr: keyword arguments of attributes of the node;
attr's values will override attr_dict's values
if both are provided.
:note: Following the NetworkX model, we allow both a dictionary
of attributes to be passed in by the user as well as key-value
pairs of attributes to be passed in by the user to provide
greater flexibility. This pattern is followed in methods such
as add_nodes, add_hyperedge, and add_hyperedges.

Examples:
::
Expand Down Expand Up @@ -344,7 +349,7 @@ def remove_nodes(self, nodes):
self.remove_node(node)

def trim_node(self, node):
"""Removes a node from the hypergraph. Modifies hypredges with the
"""Removes a node from the hypergraph. Modifies hyperedges with the
trimmed node in their head or tail so that they no longer include
the trimmed node. If a hyperedge has solely the trimmed node in its
head or tail, that hyperedge is removed.
Expand All @@ -361,10 +366,6 @@ def trim_node(self, node):
>>> H.trim_node('A')
"""

fs = self.get_forward_star(node)
bs = self.get_backward_star(node)
remove_set = set()

def get_attrs(H, hyperedge):
#copies the attribute dictionary of a hyperedge except for the head and tail
new_attrs = {}
Expand All @@ -374,6 +375,10 @@ def get_attrs(H, hyperedge):
if key not in {'head', 'tail'}:
new_attrs[key] = old_attrs[key]
return new_attrs

remove_set = set()
fs = self.get_forward_star(node)
bs = self.get_backward_star(node)

for hedge in fs:
tail = set(self.get_hyperedge_tail(hedge))
Expand Down Expand Up @@ -1244,7 +1249,7 @@ def _check_hyperedge_attributes_consistency(self):
raise ValueError(
'Consistency Check 1.7 Failed: hyperedge ' +
'id ' + hyperedge_id + ' is not in the ' +
'backward star of head node ' + tail_node)
'backward star of head node ' + head_node)

def _check_node_attributes_consistency(self):
"""Consistency Check 2: consider all nodes listed in
Expand Down
Loading