本文整理汇总了Python中halp.directed_hypergraph.DirectedHypergraph.has_hyperedge方法的典型用法代码示例。如果您正苦于以下问题:Python DirectedHypergraph.has_hyperedge方法的具体用法?Python DirectedHypergraph.has_hyperedge怎么用?Python DirectedHypergraph.has_hyperedge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类halp.directed_hypergraph.DirectedHypergraph
的用法示例。
在下文中一共展示了DirectedHypergraph.has_hyperedge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_induced_subhypergraph
# 需要导入模块: from halp.directed_hypergraph import DirectedHypergraph [as 别名]
# 或者: from halp.directed_hypergraph.DirectedHypergraph import has_hyperedge [as 别名]
def test_get_induced_subhypergraph():
H = DirectedHypergraph()
H.read("tests/data/basic_directed_hypergraph.txt")
induce_on_nodes = H.get_node_set() - {'t'}
induced_H = H.get_induced_subhypergraph(induce_on_nodes)
induced_nodes = induced_H.get_node_set()
assert induced_nodes == H.get_node_set() - {'t'}
hyperedges = [(induced_H.get_hyperedge_tail(hyperedge_id),
induced_H.get_hyperedge_head(hyperedge_id))
for hyperedge_id in induced_H.get_hyperedge_id_set()]
for hyperedge in hyperedges:
tail, head = hyperedge
assert set(tail) - induce_on_nodes == set()
assert set(head) - induce_on_nodes == set()
assert H.has_hyperedge(tail, head)
示例2: convert_pnet_to_hypergraph
# 需要导入模块: from halp.directed_hypergraph import DirectedHypergraph [as 别名]
# 或者: from halp.directed_hypergraph.DirectedHypergraph import has_hyperedge [as 别名]
#.........这里部分代码省略.........
isSink = False
isSource = False
#check if transition is not a node in hg and add if needed
#if (not hg.has_node(get_transition_name(transition))):
#check if transition is start
inc_arcs = get_incoming_arcs(transition,pnet)
for inc_arc in inc_arcs:
source_place = get_element(get_arc_source(inc_arc),pnet)
place_inc = get_incoming_arcs(source_place,pnet)
if not place_inc:
isSource = True
logger.debug("Transition is START: {0}".format(get_transition_name(transition)))
#check if trsnasition is end event
out_arcs = get_outgoing_arcs(transition,pnet)
for out_arc in out_arcs:
sink_place = get_element(get_arc_target(out_arc),pnet)
place_out = get_outgoing_arcs(sink_place,pnet)
if not place_out:
isSink = True
logger.debug("Transition is END: {0}".format(get_transition_name(transition)))
#create node in hypergraph
logger.debug("STEP 2 - Creating transition node")
hg.add_node(get_transition_name(transition), source = isSource, sink = isSink, type = 'transition', name = get_transition_name(transition))
#look BACKWARD
if not isSource:
inc_arcs = get_incoming_arcs(transition,pnet)
tail = []
x_head = [get_transition_name(transition)]
xplace_list = []
otherp_list = []
xplace_tail = []
for inc_arc in inc_arcs:
place = get_element(get_arc_source(inc_arc),pnet)
#separate xor places from other forward places of this transition
if(hg.has_node(get_id(place))):
xplace_list.append(place)
xplace_tail.append(get_id(place))
else:
otherp_list.append(place)
#create forward hyperedge to possibly multiple xor nodes
he_from_xors_needed = False
for place in xplace_tail:
temp_tail = []
temp_tail.append(place)
if(not hg.has_hyperedge(temp_tail,x_head)):
he_from_xors_needed = True
if(he_from_xors_needed):
logger.debug("STEP 2 - Creating backward hyperedge to (multiple) xor - TAIL {0} -- HEAD {1} ".format(str(xplace_tail),str(x_head)))
hg.add_hyperedge(xplace_tail, x_head, name = " ", phero = 0.5)
#create forward normal hyperdge
tail = []
# for place in otherp_list:
# inc_arcs_l2 = get_incoming_arcs(place)
# for inc_arc_l2 in inc_arcs_l2:
# trans2 = get_element(get_arc_source(inc_arc_l2))
# tail.append(get_transition_name(trans2))
# if(tail):
# logger.info("STEP 2 - Creating real backward hyperedge - TAIL {0} -- HEAD {1} ".format(str(tail),str(x_head)))
# hg.add_hyperedge(tail, x_head, name = " ", phero = 0.0, cost = 0.4, avail = 0.6, qual = 0.2, time = 0.99)
#look FORWARD
if not isSink:
out_arcs = get_outgoing_arcs(transition,pnet)
head = []
x_tail = [get_transition_name(transition)]
xplace_list = []
otherp_list = []
xplace_head = []
for out_arc in out_arcs:
place = get_element(get_arc_target(out_arc),pnet)
#separate xor places from other forward places of this transition
if(hg.has_node(get_id(place))):
xplace_list.append(place)
xplace_head.append(get_id(place))
else:
otherp_list.append(place)
#create forward hyperedge to possibly multiple xor nodes
he_to_xors_needed = False
for place in xplace_head:
temp_head = []
temp_head.append(place)
if(not hg.has_hyperedge(x_tail,temp_head)):
he_to_xors_needed = True
if(he_to_xors_needed):
logger.debug("STEP 2 - Creating forward hyperedge to (multiple) xor - TAIL {0} -- HEAD {1} ".format(str(x_tail),str(xplace_head)))
hg.add_hyperedge(x_tail, xplace_head, name = " ", phero = 0.5)
#create forward normal hyperdge
head = []
for place in otherp_list:
out_arcs_l2 = get_outgoing_arcs(place,pnet)
for out_arc_l2 in out_arcs_l2:
trans2 = get_element(get_arc_target(out_arc_l2),pnet)
head.append(get_transition_name(trans2))
if(head):
logger.debug("STEP 2 - Creating real forward hyperedge - TAIL {0} -- HEAD {1} ".format(str(x_tail),str(head)))
hg.add_hyperedge(x_tail, head, name = " ", phero = 0.5, cost = 0.4, avail = 0.6, qual = 0.2, time = 0.99)
""" POST PROCESSING of tau-split/join generated by inductive miner """
hg = tau_post_processing(hg)
""" reduction of tau split/join """
#hg = tau_reduction(hg)
return hg