diff options
| author | Patrick Simianer <patrick@lilt.com> | 2026-02-24 17:14:37 +0100 |
|---|---|---|
| committer | Patrick Simianer <patrick@lilt.com> | 2026-02-24 17:14:37 +0100 |
| commit | e76951f21263eb7010a2898b9744364e989e90b8 (patch) | |
| tree | 5adae64ca2981d4d42e52ba0ac74b4df61741083 /prototype | |
| parent | 77666a09c0f82b231605da463a946a5a5fcd09b6 (diff) | |
Deduplicate all_paths by reachable edge set
The Cartesian product over all nodes produces duplicate derivations when
edges differ only in nodes unreachable from the top. Walk reachable edges
from the top edge of each path and drop paths with identical reachable sets.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'prototype')
| -rw-r--r-- | prototype/hypergraph.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/prototype/hypergraph.rb b/prototype/hypergraph.rb index fdaba5a..08d1a29 100644 --- a/prototype/hypergraph.rb +++ b/prototype/hypergraph.rb @@ -189,7 +189,21 @@ def HG::all_paths hypergraph, root paths = new_paths } - return paths + seen = Set.new + paths.select { |p| + reachable = Set.new + mark_reachable p, p.last, reachable + key = reachable.map(&:object_id).sort + !seen.include?(key) && seen.add(key) + } +end + +def HG::mark_reachable path, edge, used + used << edge + edge.tails.each { |t| + child = path.find { |e| e.head == t } + mark_reachable path, child, used if child && !used.include?(child) + } end def HG::derive path, cur, carry |
