def test_graph_form1(): Graphs = [] Sets = [] G = nx.MultiDiGraph() str_psi = "(~Bp ^ Dq) " psi = syntax.parse_formula(SET, str_psi) Sets.append(sols.recursivealpha(psi)) gr.create_graph_K(G,Sets) Graphs.append(G) #check if there is new graph assert len(Graphs) == 1 #check if the graph has correct formula at node 1 assert G.node[1] == [('not', ('box', 'p')), ('diamond', 'q')]
def test_graph_form2(): Graphs = [] Sets = [] formulas_in = {} formulas_in[1] = [] G = nx.MultiDiGraph() str_psi = "(Bp ^ Dq) " psi = syntax.parse_formula(SET, str_psi) Sets.append(sols.recursivealpha(psi)) gr.create_graph_K(G,Sets) Graphs.append(G) #apply delta expansion l.delta_node_solve(G, 1 ,formulas_in) #check if node 1 has correct formula assert G.node[1] == [('box', 'p'), ('diamond', 'q')] #check new node contains expanded delta and gamma formulas assert G.node[2] == ['q','p']
def test_graph_form3(): l.Graphs = [] Sets = [] formulas_in = {} formulas_in[1] = [] G = nx.MultiDiGraph() str_psi = "(Bp V Dq)" psi = syntax.parse_formula(SET, str_psi) Sets.append(sols.recursivealpha(psi)) gr.create_graph_K(G,Sets) l.Graphs.append(G) #apply beta expansion l.beta_node_solve(G, 1 ,formulas_in) #check if there are 2 graphs assert len(l.Graphs) == 2 #check if there are correct formulas in node 1 assert l.Graphs[1].node[1] == [('diamond', 'q')] assert l.Graphs[0].node[1] == [('box', 'p')]
def test_graph_form4(): l.Graphs = [] Sets = [] formulas_in = {} formulas_in[1] = [] G = nx.MultiDiGraph() str_psi = "(Bp > (Dq ^ Bt))" psi = syntax.parse_formula(SET, str_psi) Sets.append(sols.recursivealpha(psi)) gr.create_graph_K(G,Sets) l.Graphs.append(G) #apply beta expansion l.beta_node_solve(G, 1 ,formulas_in) l.delta_node_solve(l.Graphs[0],1,formulas_in) l.delta_node_solve(l.Graphs[1],1,formulas_in) #check if there are 2 graphs assert len(l.Graphs) == 2 #check node 1 of graph 1 and graph 2 assert l.Graphs[0].node[1] == [('not',('box', 'p'))] assert l.Graphs[1].node[1] == [('diamond', 'q'),('box','t')] #check node 2 of graph 1 assert l.Graphs[0].node[2] == [('not', 'p')] #check node 2 of graph 2 assert l.Graphs[1].node[2] == ['q','t']
str_psi = "((~DDB~p V (~BDp ^ DDq)) > (D~BDs ^ D~Bt)) " print "formula input: ", (str_psi) """ :Parsed string into tuple and list """ psi = syntax.parse_formula(SET, str_psi) Sets.append(sols.recursivealpha(psi)) """ :creating initial graph """ G = nx.MultiDiGraph() uniq_Sets = [list(OrderedDict.fromkeys(l)) for l in Sets] gr.create_graph_K(G, uniq_Sets) Graphs.append(G) """ :functions to remove duplicates from the list """ def remove_duplicates(lista): return list(set(lista)) def remove_dups_graph(graph): for node in graph.nodes(): value_list = graph.node[node] unique_list = remove_duplicates(value_list)