def symmetric_gamma_node(graph, node, formulas_in): value_list = graph.node[node] size = len(value_list) index = 0 for i in range(index,size): value = value_list[i] if value[0] == 'box': formula = value[1] if value not in formulas_in[node]: formulas_in[node].append(value) try: graph.successors(node) except: break next_node = graph.successors(node) for single_node in next_node: if single_node < node: #take the initial size of list to check whether it expanded initial_size = len(graph.node[single_node]) if formula not in graph.node[single_node]: graph.node[single_node].append(formula) alpha_node_solve(graph,single_node) beta_node_solve(graph,single_node, formulas_in) final_size = len(graph.node[single_node]) #take diff to scan for these new entries diff_size = final_size-initial_size if diff_size > 0: value_list_single_node_initial= graph.node[single_node] value_list_single_node = value_list_single_node_initial[-diff_size:] for value in value_list_single_node: if isinstance(value,tuple) and value[0] == 'box': part = value[1] if part not in graph.node[node]: graph.node[node].append(part) elif isinstance(value,tuple) and value[0] == 'not' and value[1][0] == 'diamond': part = ('not',value[1][1]) if part not in graph.node[node]: graph.node[node].append(part) elif isinstance(value, tuple) and value[0] == 'diamond': part = value[1] new_node= graph.number_of_nodes()+1 #adding new world graph.add_edge(single_node,(new_node)) #adding symmetric edge graph.add_edge((new_node),single_node) formulas_in[new_node] = [] graph.node[single_node] = value_list_single_node_initial graph.node[new_node] = [part] #expand new delta formulae previous = graph.predecessors(new_node) for num in previous: set = graph.node[num]; for j in range(0,len(set)): if set[j][0] == 'not' and set[j][1][0] == 'diamond': formula = ('not',set[j][1][1]) if formula not in graph.node[new_node]: graph.node[new_node].append(formula) alpha_node_solve(graph,new_node) beta_node_solve(graph,new_node, formulas_in) elif set[j][0] == 'box': if set[j][1] not in graph.node[new_node]: graph.node[new_node].append(set[j][1]) alpha_node_solve(graph,new_node) beta_node_solve(graph,new_node, formulas_in) elif isinstance(value,tuple) and value[0] == 'not' and value[1][0] == 'box': part = ('not', value[1][1]) new_node= graph.number_of_nodes()+1 #adding new world graph.add_edge(single_node,(new_node)) #adding symmetric edge graph.add_edge((new_node),single_node) formulas_in[new_node] = [] graph.node[single_node] = value_list_single_node_initial graph.node[new_node] = [part] previous = graph.predecessors(new_node) for num in previous: set = graph.node[num]; for j in range(0,len(set)): if set[j][0] == 'not' and set[j][1][0] == 'diamond': formula = ('not',set[j][1][1]) if formula not in graph.node[new_node]: graph.node[new_node].append(formula) alpha_node_solve(graph,new_node) beta_node_solve(graph,new_node, formulas_in) elif set[j][0] == 'box': if set[j][1] not in graph.node[new_node]: graph.node[new_node].append(set[j][1]) alpha_node_solve(graph,new_node) beta_node_solve(graph,new_node, formulas_in) alpha_node_solve(graph, node) beta_node_solve(graph, node, formulas_in) delta_node_solve(graph, node, formulas_in) elif value[0] == 'not' and value[1][0] == 'diamond': formula = ('not', value[1][1]) if value not in formulas_in[node]: formulas_in[node].append(value) try: graph.successors(node) except: break next_node = graph.successors(node) for single_node in next_node: if single_node < node: #take the initial size of list to check whether it expanded initial_size = len(graph.node[single_node]) if formula not in graph.node[single_node]: graph.node[single_node].append(formula) alpha_node_solve(graph, single_node) beta_node_solve(graph, single_node, formulas_in) final_size = len(graph.node[single_node]) #take diff to scan for these new entries diff_size = final_size-initial_size if diff_size > 0: value_list_single_node_initial= graph.node[single_node] value_list_single_node = value_list_single_node_initial[-diff_size:] for value in value_list_single_node: if isinstance(value,tuple) and value[0] == 'box': part = value[1] if part not in graph.node[node]: graph.node[node].append(part) elif isinstance(value,tuple) and value[0] == 'not' and value[1][0] == 'diamond': part = ('not',value[1][1]) if part not in graph.node[node]: graph.node[node].append(part) elif isinstance(value, tuple) and value[0] == 'diamond': part = value[1] new_node= graph.number_of_nodes()+1 #adding new world graph.add_edge(single_node,(new_node)) #adding symmetric edge graph.add_edge((new_node),single_node) formulas_in[new_node] = [] graph.node[single_node] = value_list_single_node_initial graph.node[new_node] = [part] previous = graph.predecessors(new_node) for num in previous: set = graph.node[num]; for j in range(0,len(set)): if set[j][0] == 'not' and set[j][1][0] == 'diamond': formula = ('not',set[j][1][1]) if formula not in graph.node[new_node]: graph.node[new_node].append(formula) alpha_node_solve(graph,new_node) beta_node_solve(graph,new_node, formulas_in) elif set[j][0] == 'box': if set[j][0] not in graph.node[new_node]: graph.node[new_node].append(set[j][1]) alpha_node_solve(graph,new_node) beta_node_solve(graph,new_node, formulas_in) elif isinstance(value,tuple) and value[0] == 'not' and value[1][0] == 'box': part = ('not', value[1][1]) new_node= graph.number_of_nodes()+1 #adding new world graph.add_edge(single_node,(new_node)) #adding symmetric edge graph.add_edge((new_node),single_node) formulas_in[new_node] = [] graph.node[single_node] = value_list_single_node_initial graph.node[new_node] = [part] previous = graph.predecessors(new_node) for num in previous: set = graph.node[num]; for j in range(0,len(set)): if set[j][0] == 'not' and set[j][1][0] == 'diamond': formula = ('not',set[j][1][1]) if formula not in graph.node[new_node]: graph.node[new_node].append(formula) alpha_node_solve(graph,new_node) beta_node_solve(graph,new_node, formulas_in) elif set[j][0] == 'box': if set[j][0] not in graph.node[new_node]: graph.node[new_node].append(set[j][1]) alpha_node_solve(graph,new_node) beta_node_solve(graph,new_node, formulas_in) alpha_node_solve(graph, node) beta_node_solve(graph, node, formulas_in) delta_node_solve(graph, node, formulas_in)
def delta_node_solve(graph, node, formulas_in): delta_list = graph.node[node] for i in range(len(delta_list)-1,-1,-1): part1 = delta_list[i][0] if part1 == 'diamond': sub = delta_list[i] if sub not in formulas_in[node]: formulas_in[node].append(sub) part2 = delta_list[i][1] new_node= graph.number_of_nodes()+1 graph.add_edge(node,(new_node)) #adding new world and relation Rxx' graph.add_edge((new_node), node) #add symmetric edge graph.node[node] = delta_list graph.node[new_node] = [part2] formulas_in[new_node] = [] alpha_node_solve(graph, node) beta_node_solve(graph, node, formulas_in) previous = graph.predecessors(new_node) for num in previous: set = graph.node[num]; for j in range(0,len(set)): if set[j][0] == 'not' and set[j][1][0] == 'diamond': formula = ('not',set[j][1][1]) if formula not in graph.node[new_node]: graph.node[new_node].append(formula) alpha_node_solve(graph, new_node) beta_node_solve(graph, new_node, formulas_in) elif set[j][0] == 'box': if set[j][1] not in graph.node[new_node]: graph.node[new_node].append(set[j][1]) alpha_node_solve(graph, new_node) beta_node_solve(graph, new_node, formulas_in) elif part1 == 'not' and delta_list[i][1][0] == 'box': sub = delta_list[i] if sub not in formulas_in[node]: formulas_in[node].append(sub) part2 = ('not', delta_list[i][1][1]) new_node= graph.number_of_nodes()+1 graph.add_edge(node,(new_node)) #adding new world and relation Rxx' graph.add_edge((new_node), node) #add symmetric edge graph.node[node] = delta_list graph.node[new_node] = [part2] formulas_in[new_node] = [] alpha_node_solve(graph, node) beta_node_solve(graph, node, formulas_in) previous = graph.predecessors(new_node) for num in previous: set = graph.node[num]; for j in range(0,len(set)): if set[j][0] == 'not' and set[j][1][0] == 'diamond': formula = ('not',set[j][1][1]) if formula not in graph.node[new_node]: graph.node[new_node].append(formula) alpha_node_solve(graph, new_node) beta_node_solve(graph, new_node, formulas_in) elif set[j][0] == 'box': if set[j][1] not in graph.node[new_node]: graph.node[new_node].append(set[j][1]) alpha_node_solve(graph, new_node) beta_node_solve(graph, new_node, formulas_in)