http://www.perlmonks.org?node_id=1068209


in reply to Re^3: Travelling problem (Anyone better 86850?)
in thread Travelling problem

I have the impression that a little branch and bound with just the 3 or 4 shortest edges per node (instead of just one) would quickly produce much better results.

Prove it! (You've done a great job of quoting wikipedia; how about putting some of your reading into practice?)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^4: Travelling problem (Anyone better 86850?)

Replies are listed 'Best First'.
Re^5: Travelling problem (Anyone better 86850?)
by hdb (Monsignor) on Dec 23, 2013 at 18:09 UTC

    Branch & Bound with the two shortest edges finds the following in less than 30 seconds:

    95166 90498 90298 89653 88925 88838 86867 85294 84860

      There's thems that talk, and thems that do :)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Speaking of which...

        I am looking at my code in Re^6: Travelling problem (Anyone better 86850?) and I am wondering whether it is simple to make it multi-threaded. In the definition of sub path_recursive there is a call to path_recursive. Would it be possible to kick a new thread of for each of these, if the maximal number of threads is not yet encountered and execute it directly if we are at the maximum already?

        All the threads need to share the global variable $glength which stores the length of the best path so far.

        I have no experience with threads in Perl yet, so if there is a simple modification of my script, I would be grateful for hints...

        Update: this is what I am trying and it seems faster:

        use strict; use warnings; use threads; use threads::shared; use List::Util qw( sum min ); my $glength :shared; my @dist = <DATA>; $_ = [ split /\s+/ ] and shift @$_ for @dist; $glength = 0.5 * sum map { sum @$_ } @dist; sub path_recursive { my( $bound, $len, $path, $end, $tbv, $dist, $in_a_thread ) = @_; if( !@$tbv ) { $len += $dist->[ $path->[-1] ]->[$end]; if( $len < $glength ) { $glength = $len; print "$len: @$path $end ",scalar(localtime),"\n"; } threads->exit() if $in_a_thread; return; } my $last = $dist->[ $path->[-1] ]; my @sorted = sort { $last->[$a] <=> $last->[$b] } @$tbv; for (1..min($bound,@sorted)){ my $next = shift @sorted; if( scalar( threads->list(threads::running) ) < 15 ) { threads->create( \&path_recursive, $bound, $len + $last->[$next] +, [ @$path, $next ], $end, [ @sorted ], $dist, 1 ); } else { path_recursive( $bound, $len + $last->[$next], [ @$path, $next ] +, $end, [ @sorted ], $dist, 0 ); } push @sorted, $next; } } path_recursive shift(), 0, [ 1 ], 24, [ 2..23 ], \@dist, 0; sleep 10 while threads->list(threads::running); __DATA__
        Well brain vs muscles?

        Cheers Rolf

        ( addicted to the Perl Programming Language)

Re^5: Travelling problem (Anyone better 86850?)
by LanX (Saint) on Dec 23, 2013 at 16:47 UTC
    And what have you "proven" so far except dropping numbers and (most probably) miscalculating the lower bound?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      except dropping numbers

      Check it yourself:

      86850 [ 0 5 13 22 8 3 12 20 16 11 6 1 10 15 7 18 2 19 17 14 4 9 21 23 +]

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      Or even:
      85923 [1,2,11,16,7,8,12,17,21,6,13,4,9,23,14,10,22,15,5,18,20,3,19,24]