Algorithm-TravelingSalesman-BitonicTour
view release on metacpan or search on metacpan
lib/Algorithm/TravelingSalesman/BitonicTour.pm view on Meta::CPAN
package Algorithm::TravelingSalesman::BitonicTour;
use strict;
use warnings FATAL => 'all';
use base 'Class::Accessor::Fast';
use Carp 'croak';
use List::Util 'reduce';
use Params::Validate qw/ validate_pos SCALAR /;
use Regexp::Common;
our $VERSION = '0.05';
__PACKAGE__->mk_accessors(qw/ _points _sorted_points _tour /);
=head1 NAME
Algorithm::TravelingSalesman::BitonicTour - solve the euclidean traveling-salesman problem with bitonic tours
lib/Algorithm/TravelingSalesman/BitonicTour.pm view on Meta::CPAN
Example:
# add point at position (x=2, y=3) to the problem
$ts->add_point(2,3);
=cut
sub add_point {
my $self = shift;
my $valid = { type => SCALAR, regexp => $RE{num}{real} };
my ($x, $y) = validate_pos(@_, ($valid) x 2);
if (exists $self->_points->{$x}) {
my $py = $self->_points->{$x};
croak "FAIL: point ($x,$y) duplicates previous point ($x,$py)";
}
else {
$self->_sorted_points(undef); # clear any previous cache of sorted points
$self->_points->{$x} = $y;
return [$x, $y];
}
}
( run in 0.484 second using v1.01-cache-2.11-cpan-a5abf4f5562 )