def DuoBA_from_ltls(hard_spec, soft_spec): hard_buchi = buchi_from_ltl(hard_spec, 'hard_buchi') soft_buchi = buchi_from_ltl(soft_spec, 'soft_buchi') hard_symbols = hard_buchi.graph['symbols'] soft_symbols = soft_buchi.graph['symbols'] symbols = set(hard_symbols).union(set(soft_symbols)) DuoBA = DiGraph(type='safe_buchi', hard=hard_buchi, soft=soft_buchi, symols=symbols) initial = set() accept = set() for (h_node, s_node, l) in cartesian_product(hard_buchi.nodes(), soft_buchi.nodes(), [1, 2]): DuoNode = (h_node, s_node, l) DuoBA.add_node(DuoNode, hard=h_node, soft=s_node, level=l) if (h_node in hard_buchi.graph['initial'] and s_node in soft_buchi.graph['initial'] and l == 1): initial.add(DuoNode) if (h_node in hard_buchi.graph['accept'] and l == 1): accept.add(DuoNode) DuoBA.graph['accept'] = accept DuoBA.graph['initial'] = initial for f_duonode in DuoBA.nodes_iter(): for t_duonode in DuoBA.nodes_iter(): f_h_node, f_s_node, f_level = check_duo_attr(DuoBA, f_duonode) t_h_node, t_s_node, t_level = check_duo_attr(DuoBA, t_duonode) if (t_h_node not in DuoBA.graph['hard'].neighbors(f_h_node) or t_s_node not in DuoBA.graph['soft'].neighbors(f_s_node)): continue # relaxed because no common input alphabets are enabled hardguard = DuoBA.graph['hard'].edge[f_h_node][t_h_node]['guard'] softguard = DuoBA.graph['soft'].edge[f_s_node][t_s_node]['guard'] if ((f_h_node not in DuoBA.graph['hard'].graph['accept'] and f_level == 1 and t_level == 1) or (f_h_node in DuoBA.graph['hard'].graph['accept'] and f_level == 1 and t_level == 2) or (f_s_node not in DuoBA.graph['soft'].graph['accept'] and f_level == 2 and t_level == 2) or (f_s_node in DuoBA.graph['soft'].graph['accept'] and f_level == 2 and t_level == 1)): DuoBA.add_edge(f_duonode, t_duonode, hardguard=hardguard, softguard=softguard) return DuoBA
def DuoBA_from_ltls(hard_spec, soft_spec): hard_buchi = buchi_from_ltl(hard_spec, 'hard_buchi') soft_buchi = buchi_from_ltl(soft_spec, 'soft_buchi') hard_symbols = hard_buchi.graph['symbols'] soft_symbols = soft_buchi.graph['symbols'] symbols = set(hard_symbols).union(set(soft_symbols)) DuoBA = DiGraph(type='safe_buchi', hard=hard_buchi, soft=soft_buchi, symols=symbols) initial = set() accept = set() for (h_node, s_node, l) in cartesian_product(hard_buchi.nodes(), soft_buchi.nodes(), [1, 2]): DuoNode = (h_node, s_node, l) DuoBA.add_node(DuoNode,hard=h_node, soft=s_node, level=l) if (h_node in hard_buchi.graph['initial'] and s_node in soft_buchi.graph['initial'] and l == 1): initial.add(DuoNode) if (h_node in hard_buchi.graph['accept'] and l == 1): accept.add(DuoNode) DuoBA.graph['accept'] = accept DuoBA.graph['initial'] = initial for f_duonode in DuoBA.nodes_iter(): for t_duonode in DuoBA.nodes_iter(): f_h_node, f_s_node, f_level = check_duo_attr(DuoBA, f_duonode) t_h_node, t_s_node, t_level = check_duo_attr(DuoBA, t_duonode) if (t_h_node not in DuoBA.graph['hard'].neighbors(f_h_node) or t_s_node not in DuoBA.graph['soft'].neighbors(f_s_node)): continue # relaxed because no common input alphabets are enabled hardguard = DuoBA.graph['hard'].edge[f_h_node][t_h_node]['guard'] softguard = DuoBA.graph['soft'].edge[f_s_node][t_s_node]['guard'] if ((f_h_node not in DuoBA.graph['hard'].graph['accept'] and f_level == 1 and t_level == 1) or (f_h_node in DuoBA.graph['hard'].graph['accept'] and f_level == 1 and t_level == 2) or (f_s_node not in DuoBA.graph['soft'].graph['accept'] and f_level == 2 and t_level == 2) or (f_s_node in DuoBA.graph['soft'].graph['accept'] and f_level == 2 and t_level == 1)): DuoBA.add_edge(f_duonode, t_duonode, hardguard=hardguard, softguard=softguard) return DuoBA
def get_variance_example_1(): g = DiGraph() g.add_edges_from([(0, 1), (0, 2), (2, 3), (3, 4), (2, 'dummy'), ('dummy', 5)]) g.node['dummy']['dummy'] = True for n in (0, 1, 2, 5): # topic 1 g.node[n]['repr'] = np.array([0, 0]) for n in (3, 4): # topic 2 g.node[n]['repr'] = np.array([1, 1]) for n in g.nodes_iter(): g.node[n]['r'] = 1 # correct is (0, 1, 2, 5) for cost 0 U = [0, 42] expected_edge_set = [set(g.edges()) - {(2, 3), (3, 4)}, set(g.edges())] return (g, U, expected_edge_set)
def get_variance_example_1(): g = DiGraph() g.add_edges_from([ (0, 1), (0, 2), (2, 3), (3, 4), (2, 'dummy'), ('dummy', 5) ]) g.node['dummy']['dummy'] = True for n in (0, 1, 2, 5): # topic 1 g.node[n]['repr'] = np.array([0, 0]) for n in (3, 4): # topic 2 g.node[n]['repr'] = np.array([1, 1]) for n in g.nodes_iter(): g.node[n]['r'] = 1 # correct is (0, 1, 2, 5) for cost 0 U = [0, 42] expected_edge_set = [ set(g.edges()) - {(2, 3), (3, 4)}, set(g.edges()) ] return (g, U, expected_edge_set)