本文整理汇总了Python中halp.directed_hypergraph.DirectedHypergraph.get_hyperedge_tail方法的典型用法代码示例。如果您正苦于以下问题:Python DirectedHypergraph.get_hyperedge_tail方法的具体用法?Python DirectedHypergraph.get_hyperedge_tail怎么用?Python DirectedHypergraph.get_hyperedge_tail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类halp.directed_hypergraph.DirectedHypergraph
的用法示例。
在下文中一共展示了DirectedHypergraph.get_hyperedge_tail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_hyperedge_tail
# 需要导入模块: from halp.directed_hypergraph import DirectedHypergraph [as 别名]
# 或者: from halp.directed_hypergraph.DirectedHypergraph import get_hyperedge_tail [as 别名]
def test_get_hyperedge_tail():
node_a = 'A'
node_b = 'B'
node_c = 'C'
node_d = 'D'
tail1 = set([node_a, node_b])
head1 = set([node_c, node_d])
frozen_tail1 = frozenset(tail1)
frozen_head1 = frozenset(head1)
tail2 = set([node_b, node_c])
head2 = set([node_d, node_a])
frozen_tail2 = frozenset(tail2)
frozen_head2 = frozenset(head2)
attrib = {'weight': 6, 'color': 'black'}
common_attrib = {'sink': False}
hyperedges = [(tail1, head1, attrib), (tail2, head2)]
H = DirectedHypergraph()
hyperedge_names = \
H.add_hyperedges(hyperedges, common_attrib, color='white')
retrieved_tail1 = H.get_hyperedge_tail('e1')
retrieved_tail2 = H.get_hyperedge_tail('e2')
assert retrieved_tail1 == tail1
assert retrieved_tail2 == tail2
示例2: test_to_networkx_digraph
# 需要导入模块: from halp.directed_hypergraph import DirectedHypergraph [as 别名]
# 或者: from halp.directed_hypergraph.DirectedHypergraph import get_hyperedge_tail [as 别名]
def test_to_networkx_digraph():
H = DirectedHypergraph()
H.read("tests/data/basic_directed_hypergraph.txt")
G = directed_graph_transformations.to_networkx_digraph(H)
H_nodes = H.get_node_set()
G_nodes = G.node.keys()
assert H_nodes == set(G_nodes)
H_nodes_attributes = [H.get_node_attributes(node) for node in H_nodes]
for node in G_nodes:
assert G.node[node] in H_nodes_attributes
for hyperedge_id in H.hyperedge_id_iterator():
tail_set = H.get_hyperedge_tail(hyperedge_id)
head_set = H.get_hyperedge_head(hyperedge_id)
for tail_node in tail_set:
for head_node in head_set:
assert G[tail_node][head_node]
# Try transforming an invalid directed hypergraph
try:
directed_graph_transformations.to_networkx_digraph("invalid H")
assert False
except TypeError:
pass
except BaseException as e:
assert False, e
示例3: test_read_and_write
# 需要导入模块: from halp.directed_hypergraph import DirectedHypergraph [as 别名]
# 或者: from halp.directed_hypergraph.DirectedHypergraph import get_hyperedge_tail [as 别名]
def test_read_and_write():
# Try writing the following hypergraph to a file
node_a = 'A'
node_b = 'B'
node_c = 'C'
attrib_c = {'alt_name': 1337}
common_attrib = {'common': True, 'source': False}
node_list = [node_a, (node_b, {'source': True}), (node_c, attrib_c)]
node_d = 'D'
H = DirectedHypergraph()
H.add_nodes(node_list, common_attrib)
tail1 = set([node_a, node_b])
head1 = set([node_c, node_d])
frozen_tail1 = frozenset(tail1)
frozen_head1 = frozenset(head1)
tail2 = set([node_b, node_c])
head2 = set([node_d, node_a])
frozen_tail2 = frozenset(tail2)
frozen_head2 = frozenset(head2)
attrib = {'weight': 6, 'color': 'black'}
common_attrib = {'sink': False}
hyperedges = [(tail1, head1, attrib), (tail2, head2)]
hyperedge_names = \
H.add_hyperedges(hyperedges, common_attrib, color='white')
H.write("test_directed_read_and_write.txt")
# Try reading the hypergraph that was just written into a new hypergraph
new_H = DirectedHypergraph()
new_H.read("test_directed_read_and_write.txt")
assert H._node_attributes.keys() == new_H._node_attributes.keys()
for new_hyperedge_id in new_H.get_hyperedge_id_set():
new_hyperedge_tail = new_H.get_hyperedge_tail(new_hyperedge_id)
new_hyperedge_head = new_H.get_hyperedge_head(new_hyperedge_id)
new_hyperedge_weight = new_H.get_hyperedge_weight(new_hyperedge_id)
found_matching_hyperedge = False
for hyperedge_id in H.get_hyperedge_id_set():
hyperedge_tail = H.get_hyperedge_tail(hyperedge_id)
hyperedge_head = H.get_hyperedge_head(hyperedge_id)
hyperedge_weight = H.get_hyperedge_weight(hyperedge_id)
if new_hyperedge_tail == hyperedge_tail and \
new_hyperedge_head == hyperedge_head and \
new_hyperedge_weight == hyperedge_weight:
found_matching_hyperedge = True
continue
assert found_matching_hyperedge
remove("test_directed_read_and_write.txt")
# Try reading an invalid hypergraph file
invalid_H = DirectedHypergraph()
try:
invalid_H.read("tests/data/invalid_directed_hypergraph.txt")
assert False
except IOError:
pass
except BaseException as e:
assert False, e