Algorithm-Pair-Best2
view release on metacpan or search on metacpan
lib/Algorithm/Pair/Best2.pm view on Meta::CPAN
push @scores, $self->get_score(@w_idxs[$idx..$idx+1]);
}
last;
}
}
return wantarray ? @results : \@results;
}
# find best pairing of @idxs. try the first item in @idxs against every
# other item in the array. after picking the first and the current second
# item, recursively find the best arrangement of all the remaining items.
# the return values are the score followed by the new arrangment.
sub _r_best {
my ($self, $depth, $best_score, @idxs) = @_;
if (@idxs <= 2) {
croak sprintf("%d items left", scalar @idxs) if (@idxs <= 1);
return ($self->get_score(@idxs), @idxs);
}
lib/Algorithm/Pair/Best2.pm view on Meta::CPAN
## $self->print_items(@best_trial) if ($depth < 2);
}
else {
## printf "%2d %2d Not best %8.5f idxs %s\n",
## $depth,
## $idx,
## $trial_score,
## $self->print_items($trial_0, $trial_1, @trial_tail) if ($depth < 2);
}
# hold $trial_0 in slot 0, rotate all items below it
push @tail, $trial_1; # add second item to end of tail
$trial_1 = shift @tail; # move third item into second slot
### pop @head;
}
### pop @head;
### my $key = $self->make_key(@best_trial);
### print "best: $key = $best_score\n" if ($depth == 0);
return ($best_score, @best_trial);
}
1;
( run in 0.520 second using v1.01-cache-2.11-cpan-39bf76dae61 )