Algorithm-Search
view release on metacpan or search on metacpan
foreach my $path ($travel_search->paths) {
# print "Path ".$path_count++." ";
# print join("..", @{$path})."\n";
$full_path .= join("..", @{$path})."\n";
}
}
is ($full_path,
"St. Paul..Madison..Rockford..Bloomington..Champaign..Urbana
St. Paul..Madison..Rockford..Bloomington..Champaign..Chicago..Urbana
St. Paul..Madison..Chicago..Urbana
Duluth..Chicago..Urbana
", 'ts2 cost minneapolis to urbana paths');
$travel_search->search({search_this => $driver,
search_type => 'cost',
initial_cost => $driver->distance_to_urbana,
solutions_to_find => 2,
});
#print "sf \n";
$full_path = '';
if ($travel_search->solution_found) { #should be true, path to Urbana
#print "found path from Minneapolis to Urbana\n";
# print join("..", @{$travel_search->path})."\n";
my $path_count = 0;
foreach my $path ($travel_search->paths) {
# print "Path ".$path_count++." ";
# print join("..", @{$path})."\n";
$full_path .= join("..", @{$path})."\n";
}
}
is ($full_path,
"St. Paul..Madison..Rockford..Bloomington..Champaign..Urbana
St. Paul..Madison..Rockford..Bloomington..Champaign..Chicago..Urbana
", 'ts2 cost limit 2');
$travel_search->search({search_this => $driver,
solutions_to_find => 0,
search_type => 'cost',
initial_cost => $driver->distance_to_urbana,
maximum_depth => 5,
return_search_trace => 1,
});
#print "md \n";
$full_path = '';
if ($travel_search->solution_found) { #should be true, path to Urbana
#print "found path from Minneapolis to Urbana\n";
# print join("..", @{$travel_search->path})."\n";
my $path_count = 0;
foreach my $path ($travel_search->paths) {
# print "Path ".$path_count++." ";
# print join("..", @{$path})."\n";
$full_path .= join("..", @{$path})."\n";
}
}
is ($full_path,
"St. Paul..Madison..Chicago..Urbana
Duluth..Chicago..Urbana
", 'ts2 cost max depth');
#use Data::Dumper;
#print STDERR "q: ".Dumper($travel_search->search_trace)."\n";
is_deeply($travel_search->search_trace,
[
{
'commit' => undef,
'cost' => 515,
'move' => undef,
'value_before' => undef,
'value_after' => 'Minneapolis'
},
{
'commit' => undef,
'cost' => 515,
'move' => 'Duluth',
'value_before' => 'Minneapolis',
'value_after' => 'Duluth'
},
{
'commit' => undef,
'cost' => 515,
'move' => 'St. Paul',
'value_before' => 'Minneapolis',
'value_after' => 'St. Paul'
},
{
'commit' => undef,
'cost' => 505,
'move' => 'Madison',
'value_before' => 'St. Paul',
'value_after' => 'Madison'
},
{
'commit' => undef,
'cost' => 252,
'move' => 'Rockford',
'value_before' => 'Madison',
'value_after' => 'Rockford'
},
{
'commit' => undef,
'cost' => 185,
'move' => 'Bloomington',
'value_before' => 'Rockford',
'value_after' => 'Bloomington'
},
{
'commit' => undef,
'cost' => 252,
'move' => 'Chicago',
'value_before' => 'Madison',
'value_after' => 'Chicago'
},
{
'commit' => undef,
'cost' => 140,
'move' => 'Urbana',
'value_before' => 'Chicago',
'value_after' => 'Urbana'
},
{
( run in 0.713 second using v1.01-cache-2.11-cpan-39bf76dae61 )