Advertisement
Guest User

Untitled

a guest
May 30th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import networkx as nx
  3.  
  4. def searchGraph(graph, node):
  5. reachables= nx.ancestors(graph, node)
  6. return reachables
  7. def nfaToDfa(graph, node, ancestors):
  8. inE= list()
  9. inE2 = graph.in_edges(graph.nodes())
  10. inE=inE2
  11. print(inE)
  12. for eS in inE:
  13. if "char" in graph[eS[0]][eS[1]]:
  14. source, target = eS
  15. print(target)
  16. B = nx.dag.ancestors(graph, graph.nodes[target])
  17. break
  18. source, target = inE[0]
  19. B=nx.dag.ancestors(graph,graph.nodes[target])
  20. return B
  21. DG = nx.DiGraph()
  22. DG.add_edges_from([(8,6),(8,9),(6,1), (6,4),(1,2, {'char': 'a'}),(2,3,{'char': 'b'}),(3,7)
  23. ,(4,5,{'char':'c'}),(5,7),(7,6),(7,9)])
  24. DG.nodes[8]["starting"]=True
  25. DG.nodes[9]["accepting"]=True
  26. plt.subplot(111)
  27. #NG = nfaToDfa(DG)
  28. d = nx.dag.ancestors(DG, DG.nodes[8]["starting"])
  29. H=DG.subgraph(d)
  30. print(d)
  31. listOfLists = []
  32. listOfLists.append(nfaToDfa(H, H.nodes[8], d))
  33. print(listOfLists)
  34. #nx.draw(DG, with_labels=True, font_weight="bold")
  35. pos = nx.spring_layout(DG, scale=2)
  36. nx.draw(H, pos, with_labels=True)
  37. nx.draw_networkx_edge_labels(H, pos, labels=nx.get_edge_attributes(DG, 'char'))
  38.  
  39. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement