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 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 librariesImport
  5. 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. init()
  21. def afficheMatrix(mat) :
  22. for i in mat :
  23. line = ""
  24. for j in i :
  25. line+=str(j)
  26. line+=" "
  27. print(line)
  28. def createNxGraph() :
  29. G = nx.Graph()
  30. G.add_node("1", chem = "C")
  31. G.add_node("2", chem = "0")
  32. G.add_edge("1", "2", valence = "1")
  33. G.add_node("3", chem = "N")
  34. G.add_node("4", chem = "C")
  35. G.add_edge("3", "4", valence = "1")
  36. G.add_edge("3", "2", valence = "1")
  37. return G
  38. #G = createNxGraph()
  39. def addGraphTest() :
  40. gedlibpy.restart_env()
  41. gedlibpy.load_GXL_graphs('include/gedlib-master/data/datasets/Mutagenicity/data/', 'collections/MUTA_10.xml')
  42. currentID = gedlibpy.add_graph()
  43. print(currentID)
  44. gedlibpy.add_node(currentID, "_1", {"chem" : "C"})
  45. gedlibpy.add_node(currentID, "_2", {"chem" : "O"})
  46. gedlibpy.add_edge(currentID,"_1", "_2", {"valence": "1"} )
  47. listID = gedlibpy.get_all_graph_ids()
  48. print(listID)
  49. print(gedlibpy.get_graph_node_labels(10))
  50. print(gedlibpy.get_graph_edges(10))
  51. for i in listID :
  52. print(gedlibpy.get_graph_node_labels(i))
  53. print(gedlibpy.get_graph_edges(i))
  54. #addGraphTest()
  55. def shortTest() :
  56. gedlibpy.restart_env()
  57. print("Here is the mini Python function !")
  58. gedlibpy.load_GXL_graphs("include/gedlib-master/data/datasets/Mutagenicity/data/", "include/gedlib-master/data/collections/Mutagenicity.xml")
  59. listID = gedlibpy.get_all_graph_ids()
  60. gedlibpy.set_edit_cost("CHEM_1")
  61. gedlibpy.init()
  62. gedlibpy.set_method("BIPARTITE", "")
  63. gedlibpy.init_method()
  64. g = listID[0]
  65. h = listID[1]
  66. gedlibpy.run_method(g,h)
  67. print("Node Map : ", gedlibpy.get_node_map(g,h))
  68. print("Assignment Matrix : ")
  69. afficheMatrix(gedlibpy.get_assignment_matrix(g,h))
  70. 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)))
  71. #shortTest()
  72. def classiqueTest() :
  73. gedlibpy.restart_env()
  74. gedlibpy.load_GXL_graphs('include/gedlib-master/data/datasets/Mutagenicity/data/', 'collections/MUTA_10.xml')
  75. listID = gedlibpy.get_all_graph_ids()
  76. afficheId = ""
  77. for i in listID :
  78. afficheId+=str(i) + " "
  79. print("Number of graphs = " + str(len(listID)) + ", list of Ids = " + afficheId)
  80. gedlibpy.set_edit_cost("CHEM_1")
  81. gedlibpy.init()
  82. gedlibpy.set_method("IPFP", "")
  83. gedlibpy.init_method()
  84. g = listID[0]
  85. h = listID[0]
  86. gedlibpy.run_method(g,h)
  87. liste = gedlibpy.get_all_map(g,h)
  88. print("Forward map : " , gedlibpy.get_forward_map(g,h), ", Backward map : ", gedlibpy.get_backward_map(g,h))
  89. print("Node Map : ", gedlibpy.get_node_map(g,h))
  90. 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)))
  91. #classiqueTest()
  92. def nxTest(dataset) :
  93. gedlibpy.restart_env()
  94. for graph in dataset :
  95. gedlibpy.add_nx_graph(graph, "")
  96. listID = gedlibpy.get_all_graph_ids()
  97. gedlibpy.set_edit_cost("CHEM_1")
  98. gedlibpy.init()
  99. gedlibpy.set_method("IPFP", "")
  100. gedlibpy.init_method()
  101. print(listID)
  102. g = listID[0]
  103. h = listID[1]
  104. gedlibpy.run_method(g,h)
  105. print("Node Map : ", gedlibpy.get_node_map(g,h))
  106. 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)))
  107. #dataset = [createNxGraph(), createNxGraph()]
  108. #nxTest(dataset)
  109. def LSAPETest(matrixCost) :
  110. result = gedlibpy.hungarian_LSAPE(matrixCost)
  111. print("Rho = ", result[0], " Varrho = ", result[1], " u = ", result[2], " v = ", result[3])
  112. #LSAPETest([[2,3,4], [5,1,9], [7,10,3]])
  113. def LSAPTest(matrixCost) :
  114. result = gedlibpy.hungarian_LSAP(matrixCost)
  115. print("Rho = ", result[0], " Varrho = ", result[1], " u = ", result[2], " v = ", result[3])
  116. #LSAPETest([[2,3,4], [5,1,9], [7,10,3]])

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