Dear Limbic,
I tried the following graph and predertimined start and position in code below. But why It gives empty result? Please refer to the visualization of the graph here (http://graph.gafol.net/cESwUMeNd) .
my %graph2 = ( 'read145404_1' => [ 'read231054_2', 'read250449_2' ], 'read250449_2' => [ 'read359463_1', 'read691358_1', 'read937013_1' ], 'read231054_2' => [ 'read691358_1', 'read359463_1', 'read937013_1' ] ); my $routes = find_paths('read145404_1', 'read691358_1', \%graph2); sub find_paths { my ($beg, $end, $graph) = @_; my $n; my %node_to_int = map {$_ => $n++} keys %graph; my (@work, @solution); for (@{$graph->{$beg}}) { if ($_ eq $end) { push @solution, "$beg->$end"; next; } my $seen = ''; vec($seen, $node_to_int{$_}, 1) = 1; vec($seen, $node_to_int{$beg}, 1) = 1; push @work, ["$beg->$_", $_, $seen]; } while (@work) { my $item = pop @work; my ($path, $curr, $seen) = @$item; for my $node (@{$graph->{$curr}}) { my $bit = $node_to_int{$node}; next if vec($seen, $bit, 1); if ($node eq $end) { push @solution, "$path $end"; next; } my $new_seen = $seen; vec($new_seen, $bit, 1) = 1; push @work, ["$path->$node", $node, $new_seen]; } } # Return print Dumper \@solution; return \@solution; }


---
neversaint and everlastingly indebted.......

In reply to Re^6: Finding All Paths From a Graph From a Given Source and End Node by neversaint
in thread Finding All Paths From a Graph From a Given Source and End Node by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.