From fc4f96ea1f20b88575772dd7824e686f04a121fc Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Fri, 6 Jun 2003 14:20:52 +0000 Subject: [PATCH] Fix a bug in ambiguity detection. Add a report of subgraphs causing ambiguity at the end. [SVN r18699] --- generators_prototype.py | 21 ++++++++++++++++++++- v2/generators_prototype.py | 21 ++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/generators_prototype.py b/generators_prototype.py index e27514cb9..ee7f68062 100644 --- a/generators_prototype.py +++ b/generators_prototype.py @@ -439,7 +439,7 @@ def _examine_edge(states, queue, g): print 'discarding %s due to lower cost state(%s)' % (g, v.group) elif not (g.generator or v.group.generator) \ - and _sort_tuple(g.atoms()) != _sort_tuple(v.group.atoms()): + and _sort_tuple(g.atoms()) == _sort_tuple(v.group.atoms()): # These are two different ways of combining the same groups of # a given type to produce a larger group, without using a generator if debug: @@ -601,6 +601,17 @@ def graph(group, indent = 0, visited = None): [graph(g,indent+1,visited) for g in group.parents]) return s +def ambiguities(group): + """Returns a list of groups that caused ambiguities with this one + or its constituents. + """ + result = [] + for g in group.parents: + result.extend(ambiguities(g)) + if group.ambiguous and type(group.ambiguous) is not type(1): + result.append(group.ambiguous) + return result + def search(generators, targets, sources): import sys global queue_moves @@ -610,6 +621,14 @@ def search(generators, targets, sources): for g in optimal_graphs(targets, sources, generators): print 80 * '=' print graph(g) + + if g.ambiguous: + print 40 * '-' + print 'ambiguities:' + for a in ambiguities(g): + print graph(a) + print + print queue_moves, 'queue_moves' print 80 * '=' sys.stdout.flush() diff --git a/v2/generators_prototype.py b/v2/generators_prototype.py index e27514cb9..ee7f68062 100644 --- a/v2/generators_prototype.py +++ b/v2/generators_prototype.py @@ -439,7 +439,7 @@ def _examine_edge(states, queue, g): print 'discarding %s due to lower cost state(%s)' % (g, v.group) elif not (g.generator or v.group.generator) \ - and _sort_tuple(g.atoms()) != _sort_tuple(v.group.atoms()): + and _sort_tuple(g.atoms()) == _sort_tuple(v.group.atoms()): # These are two different ways of combining the same groups of # a given type to produce a larger group, without using a generator if debug: @@ -601,6 +601,17 @@ def graph(group, indent = 0, visited = None): [graph(g,indent+1,visited) for g in group.parents]) return s +def ambiguities(group): + """Returns a list of groups that caused ambiguities with this one + or its constituents. + """ + result = [] + for g in group.parents: + result.extend(ambiguities(g)) + if group.ambiguous and type(group.ambiguous) is not type(1): + result.append(group.ambiguous) + return result + def search(generators, targets, sources): import sys global queue_moves @@ -610,6 +621,14 @@ def search(generators, targets, sources): for g in optimal_graphs(targets, sources, generators): print 80 * '=' print graph(g) + + if g.ambiguous: + print 40 * '-' + print 'ambiguities:' + for a in ambiguities(g): + print graph(a) + print + print queue_moves, 'queue_moves' print 80 * '=' sys.stdout.flush()