summaryrefslogtreecommitdiff
path: root/monkey
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-02-18 16:45:18 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:02 +0200
commit63ed3cceec22c354887fbdea398ca322d149bca0 (patch)
tree2a621140f713357aa214b7c66e302ec914f87b0b /monkey
parent56d32ee32b70ac311910db22a29d6edaa4f8f14a (diff)
Cleanups
Diffstat (limited to 'monkey')
-rw-r--r--monkey/edits.py78
-rwxr-xr-xmonkey/test.py2
2 files changed, 1 insertions, 79 deletions
diff --git a/monkey/edits.py b/monkey/edits.py
index 1b5633d..cf2bc66 100644
--- a/monkey/edits.py
+++ b/monkey/edits.py
@@ -243,84 +243,6 @@ def classify_edits(edits):
changes[(before, after)] = cost
return inserts, removes, changes
-# Simplify an edit graph with given nodes: remove empty leaf nodes and other
-# fluff. The function is called recursively until no more changes are done.
-def clean_graph(nodes):
- changed = False
-
- # A
- # | --> A (when B is an empty leaf)
- # B
- for node in nodes:
- if len(node.eout) == 0 and len(node.ein) == 1 and len(node.data[2]) == 0:
- parent = node.ein[0]
- parent.eout.remove(node)
- nodes.remove(node)
- changed = True
- break
-
- # A
- # | --> A
- # A
- for node in nodes:
- if len(node.ein) == 1:
- parent = node.ein[0]
- if len(parent.eout) == 1 and node.data[2] == parent.data[2]:
- parent.eout = node.eout
- for child in parent.eout:
- child.ein = [parent if node == node else node for node in child.ein]
- nodes.remove(node)
- changed = True
- break
-
- # A A
- # |\ |
- # | C --> | (when C is empty)
- # |/ |
- # B B
- for node in nodes:
- if len(node.data[2]) == 0 and len(node.ein) == 1 and len(node.eout) == 1:
- parent = node.ein[0]
- child = node.eout[0]
- if len(parent.eout) == 2 and len(child.ein) == 2:
- parent.eout = [n for n in parent.eout if n != node]
- child.ein = [n for n in child.ein if n != node]
- nodes.remove(node)
- changed = True
- break
-
- # A
- # |
- # C --> A
- # |
- # A
- for node in nodes:
- if len(node.data[2]) == 0 and len(node.ein) == 1 and len(node.eout) == 1:
- parent = node.ein[0]
- child = node.eout[0]
- if len(parent.eout) == 1 and len(child.ein) == 1 and parent.data[2] == child.data[2]:
- parent.eout = [child]
- child.ein = [parent]
- nodes.remove(node)
- changed = True
- break
-
- if changed:
- # go again until nothing changes
- clean_graph(nodes)
- else:
- # compact node ranks
- ranks = set([node.data[0] for node in nodes])
- missing = set(range(1,max(ranks)+1)) - ranks
-
- for node in nodes:
- diff = 0
- for rank in sorted(missing):
- if rank >= node.data[0]:
- break
- diff += 1
- node.data[0] -= diff
-
if __name__ == '__main__':
import os
import pickle
diff --git a/monkey/test.py b/monkey/test.py
index 16d635f..eb91e3c 100755
--- a/monkey/test.py
+++ b/monkey/test.py
@@ -12,7 +12,7 @@ from .edits import classify_edits, edit_graph, get_edits_from_traces
from .graph import graphviz
from .monkey import fix
from prolog.engine import test
-from prolog.util import Token, compose, decompose, stringify
+from prolog.util import Token, compose, decompose, stringify
from .util import indent
# Load django models.