Method: HG.all_paths
- Defined in:
- lib/zipf/hypergraph.rb
.all_paths(hypergraph, root, semiring = ViterbiSemiring.new) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/zipf/hypergraph.rb', line 152 def HG::all_paths hypergraph, root, semiring=ViterbiSemiring.new toposorted = topological_sort hypergraph.nodes paths = [[]] toposorted.each { |n| next if n.incoming.empty? new_paths = [] while !paths.empty? p = paths.pop n.incoming.each { |e| new_paths << p+[e] } end paths = new_paths } return paths end |