removal of equal patterns
authorMart Lubbers <mart@martlubbers.net>
Thu, 10 Jul 2014 19:12:35 +0000 (21:12 +0200)
committerMart Lubbers <mart@martlubbers.net>
Thu, 10 Jul 2014 19:12:35 +0000 (21:12 +0200)
program/regexex/fsm.py

index 4d06244..5f833e6 100644 (file)
@@ -153,9 +153,24 @@ class fsm():
                 # Remove the obsolete nodes
                 if result:
                     # Magic removal process
-                    print result
-                    print group
-
+                    res_nodes = [r[0] for r in result]
+                    remove = []
+                    for n in group[0]:
+                        if n not in res_nodes:
+                            remove.append(n)
+
+                    indices = []
+                    for i, k in enumerate(self.subgraphs['none'][0]):
+                        if k[0] in remove:
+                            indices.insert(0, i)
+                    for i in indices:
+                        del(self.subgraphs['none'][0][i])
+                    indices = []
+                    for i, c in enumerate(self.subgraphs['none'][1]):
+                        if c[0] in remove or c[1] in remove:
+                            indices.insert(0, i)
+                    for i in indices:
+                        del(self.subgraphs['none'][1][i])
 
     def process_multipath(self, path):
         """Looks for possible merge candidates
@@ -182,7 +197,6 @@ class fsm():
             # Magic
             pass
 
-
     def walk(self, current, conn, currents=[], strings=[], vis=set()):
         """Walk the graph and keep track of vis conn