From f9fc6da5c9a30ac848204308c4aef9c42cd7618b Mon Sep 17 00:00:00 2001
From: Fize Jacques <jacques.fize@cirad.fr>
Date: Wed, 20 Feb 2019 10:20:04 +0100
Subject: [PATCH] DEBUG MultiDiGraph issue

---
 gmatch4py/graph.pyx                |  8 ++++----
 test/gmatch4py_performance_test.py | 26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 test/gmatch4py_performance_test.py

diff --git a/gmatch4py/graph.pyx b/gmatch4py/graph.pyx
index ac03d69..0364cf4 100644
--- a/gmatch4py/graph.pyx
+++ b/gmatch4py/graph.pyx
@@ -39,7 +39,7 @@ cdef class Graph:
             self.edge_attr_key = edge_attr_key
             self.edges_attr_list = [attr_dict[edge_attr_key] for attr_dict in self.attr_edges]
             self.unique_edge_attr_vals=set(self.edges_attr_list)
-        
+
         # NODE Information init
         #######################
         
@@ -57,7 +57,6 @@ cdef class Graph:
         if self.is_edge_attr:
             self.degree_per_attr={attr_v:{n:{"in":0,"out":0} for n in self.nodes_list} for attr_v in self.unique_edge_attr_vals}
             self.degree_per_attr_weighted={attr_v:{n:{"in":0,"out":0} for n in self.nodes_list} for attr_v in self.unique_edge_attr_vals}
-            
         # Retrieving Degree Information
         self.edges_of_nodes={}
         for n in self.nodes_list:
@@ -114,7 +113,7 @@ cdef class Graph:
             if not e1 in self.edges_hash_map:self.edges_hash_map[e1]={}
             
             hash_=self.hash_edge_attr(e1,e2,self.edges_attr_list[ix]) if self.is_edge_attr else self.hash_edge(e1,e2)
-            if self.is_multi:
+            if self.is_multi and self.is_edge_attr:
                 if not e2 in self.edges_hash_map[e1]:self.edges_hash_map[e1][e2]={}
                 self.edges_hash_map[e1][e2][self.edges_attr_list[ix]]=hash_
             else:
@@ -122,9 +121,10 @@ cdef class Graph:
             self.edges_hash_idx[hash_]=ix 
             self.edges_hash.append(hash_) 
         self.edges_hash_set=set(self.edges_hash)
-        
+
         self.edges_weight={}
         for e1,e2,attr_dict in list(G.edges(data=True)):
+            print(e1,e2,attr_dict)
             hash_=self.hash_edge_attr(e1,e2,attr_dict[self.edge_attr_key]) if self.is_edge_attr else self.hash_edge(e1,e2)
             self.edges_weight[hash_]=attr_dict["weight"] if "weight" in attr_dict else 1 
         
diff --git a/test/gmatch4py_performance_test.py b/test/gmatch4py_performance_test.py
new file mode 100644
index 0000000..860cd7a
--- /dev/null
+++ b/test/gmatch4py_performance_test.py
@@ -0,0 +1,26 @@
+from gmatch4py import *
+import networkx as nx
+import time
+from tqdm import tqdm
+import pandas as pd
+max_=500
+size_g=10
+graphs_all=[nx.random_tree(size_g) for i in range(max_)]
+result_compiled=[]
+for size_ in tqdm(range(50,max_,50)):
+    graphs=graphs_all[:size_]
+    comparator=None
+    for class_ in [BagOfNodes,WeisfeleirLehmanKernel,GraphEditDistance,  GreedyEditDistance, HED, BP_2  Jaccard, MCS, VertexEdgeOverlap]:
+        deb=time.time()
+        if class_ in (GraphEditDistance, BP_2, GreedyEditDistance, HED):
+            comparator = class_(1, 1, 1, 1)
+        elif class_ == WeisfeleirLehmanKernel:
+            comparator = class_(h=2)
+        else:
+            comparator=class_()
+        matrix = comparator.compare(graphs,None)
+        print([class_.__name__,size_,time.time()-deb])
+        result_compiled.append([class_.__name__,size_,time.time()-deb])
+
+df=pd.DataFrame(result_compiled,columns="algorithm size_data time_exec_s".split())
+df.to_csv("new_gmatch4py_res_{0}graphs_{1}size.csv".format(max_,size_g))
\ No newline at end of file
-- 
GitLab