Пример #1
0
def test_alpha_form2():
    Sets = []
    alpha_expand = [('not', ('box', ('and', 'p', ('diamond', 'q')))), 's', 'q', ('diamond', 't')]
    str_psi = "(~B(p ^ Dq) ^ (s ^ (q ^ Dt))) "
    psi = syntax.parse_formula(SET, str_psi)
    Sets.append(sols.recursivealpha(psi))
    assert Sets[0] == alpha_expand
Пример #2
0
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')]
Пример #3
0
def alpha_node(graph):
    for node in graph.nodes():
        set = []
        value_list = graph.node[node]
        for i in range(0, len(value_list)):
            if isinstance(value_list[i], tuple):
                alpha = sols.recursivealpha(value_list[i])
                for j in alpha:
                    if isinstance(j, tuple):
                        if j not in set:
                            set.append(j)
                    else:
                        for prop in alpha:
                            set.append(prop)
            elif isinstance(value_list[i], str):
                set.append(value_list[i])
        graph.node[node] = remove_duplicates(set)
Пример #4
0
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']
Пример #5
0
def alpha_node_solve(graph,node):
    set = [] # array to store expanded alphas
    value_list = graph.node[node]
    for i in range(0,len(value_list)):
        if isinstance(value_list[i], tuple):
            alpha = sols.recursivealpha(value_list[i])
            for j in alpha:
                if isinstance(j, tuple):
                    if j not in set:
                        set.append(j)
            else:
                for prop in alpha:
                    if prop not in set:
                        set.append(prop)
        elif isinstance(value_list[i], str):
            if value_list[i] not in set:
                set.append(value_list[i])
    graph.node[node] = set
Пример #6
0
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')]
Пример #7
0
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']
Пример #8
0
graph_formulas = []  # list of dictionaries-used formulas in node for graph
formulas = {}  # single dictionary
formulas[1] = []  # first list for node 1
graph_formulas.append(formulas)  # add it to list of dictionaries

"""
    :Input String:
"""
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
"""