You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.py 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #export LD_LIBRARY_PATH=.:/export/home/lambertn/Documents/gedlibpy/lib/fann/:/export/home/lambertn/Documents/gedlibpy/lib/libsvm.3.22:/export/home/lambertn/Documents/gedlibpy/lib/nomad
  2. #Pour que "import script" trouve les librairies qu'a besoin GedLib
  3. #Equivalent à définir la variable d'environnement LD_LIBRARY_PATH sur un bash
  4. import gedlibpy.librariesImport
  5. from gedlibpy import gedlibpy
  6. import networkx as nx
  7. def init() :
  8. print("List of Edit Cost Options : ")
  9. for i in gedlibpy.list_of_edit_cost_options :
  10. print (i)
  11. print("")
  12. print("List of Method Options : ")
  13. for j in gedlibpy.list_of_method_options :
  14. print (j)
  15. print("")
  16. print("List of Init Options : ")
  17. for k in gedlibpy.list_of_init_options :
  18. print (k)
  19. print("")
  20. def test():
  21. gedlibpy.load_GXL_graphs('include/gedlib-master/data/datasets/Mutagenicity/data/', 'collections/MUTA_10.xml')
  22. listID = gedlibpy.get_all_graph_ids()
  23. gedlibpy.set_edit_cost("CHEM_1")
  24. gedlibpy.init()
  25. gedlibpy.set_method("IPFP", "")
  26. gedlibpy.init_method()
  27. g = listID[0]
  28. h = listID[1]
  29. gedlibpy.run_method(g, h)
  30. print("Node Map : ", gedlibpy.get_node_map(g,h))
  31. print("Forward map : " , gedlibpy.get_forward_map(g, h), ", Backward map : ", gedlibpy.get_backward_map(g, h))
  32. print("Assignment Matrix : ")
  33. print(gedlibpy.get_assignment_matrix(g, h))
  34. print ("Upper Bound = " + str(gedlibpy.get_upper_bound(g,h)) + ", Lower Bound = " + str(gedlibpy.get_lower_bound(g, h)) + ", Runtime = " + str(gedlibpy.get_runtime(g, h)))
  35. def convertGraph(G):
  36. G_new = nx.Graph()
  37. for nd, attrs in G.nodes(data=True):
  38. G_new.add_node(str(nd), chem=attrs['atom'])
  39. for nd1, nd2, attrs in G.edges(data=True):
  40. G_new.add_edge(str(nd1), str(nd2), valence=attrs['bond_type'])
  41. return G_new
  42. def testNxGrapĥ():
  43. from gklearn.utils.graphfiles import loadDataset
  44. ds = {'name': 'MUTAG', 'dataset': '../datasets/MUTAG/MUTAG_A.txt',
  45. 'extra_params': {}} # node/edge symb
  46. Gn, y_all = loadDataset(ds['dataset'], extra_params=ds['extra_params'])
  47. gedlibpy.restart_env()
  48. for graph in Gn:
  49. g_new = convertGraph(graph)
  50. gedlibpy.add_nx_graph(g_new, "")
  51. listID = gedlibpy.get_all_graph_ids()
  52. gedlibpy.set_edit_cost("CHEM_1")
  53. gedlibpy.init()
  54. gedlibpy.set_method("IPFP", "")
  55. gedlibpy.init_method()
  56. print(listID)
  57. g = listID[0]
  58. h = listID[1]
  59. gedlibpy.run_method(g, h)
  60. print("Node Map : ", gedlibpy.get_node_map(g, h))
  61. print("Forward map : " , gedlibpy.get_forward_map(g, h), ", Backward map : ", gedlibpy.get_backward_map(g, h))
  62. print ("Upper Bound = " + str(gedlibpy.get_upper_bound(g, h)) + ", Lower Bound = " + str(gedlibpy.get_lower_bound(g, h)) + ", Runtime = " + str(gedlibpy.get_runtime(g, h)))
  63. #test()
  64. init()
  65. #testNxGrapĥ()

A Python package for graph kernels, graph edit distances and graph pre-image problem.