Algorithm-Search
view release on metacpan or search on metacpan
example/15.pl view on Meta::CPAN
else {
print "not in final\n";
}
my $fifteen_search = new Algorithm::Search();
$fifteen_search->search({search_this=>$puzzle,
solutions_to_find=>1,
search_type => 'bfs'
});
print "Solution found :\n";
use Data::Dumper;
print Dumper($fifteen_search->path)."\n";
$puzzle->set_position(
'10 12 7 3
5 13 8 4
9 11 2 0
15 14 1 6');
print "pvalue is ".$puzzle->value."\n";
$fifteen_search->search({search_this=>$puzzle,
solutions_to_find=>1,
search_type => 'bfs',
do_not_repeat_values => 1,
max_steps => 200000
});
print "Solution found :\n";
use Data::Dumper;
print Dumper($fifteen_search->path)."\n";
lib/Algorithm/Search.pm view on Meta::CPAN
$self->{moving_forward} = 0;
return;
}
}
my $new_commit;
if ($self->{committing}) {
$new_commit = $search_this->commit_level;
}
if ($self->{return_search_trace}) {
#use Data::Dumper;
#print STDERR "si ".Dumper($self->{info})."\n";
push @{$self->{trace}}, {
cost => $new_cost,
commit => $new_commit,
value_after => $value,
value_before => $self->{info}->[-1]->[0],
move => $next_move,
};
}
else {
# print "s2 not in final\n";
}
my $fifteen_search = new Algorithm::Search();
$fifteen_search->search({search_this=>$puzzle,
solutions_to_find=>1,
search_type => 'bfs'
});
# print "Solution found :\n";
# use Data::Dumper;
# print Dumper($fifteen_search->path)."\n";
is_deeply ($fifteen_search->path,
[
[
3,
3
]
], 'one move problem');
# $puzzle->set_position(
#15 14 1 6');
#
# print "pvalue is ".$puzzle->value."\n";
# $fifteen_search->search({search_this=>$puzzle,
# solutions_to_find=>1,
# search_type => 'bfs',
# do_not_repeat_values => 1,
# max_steps => 200000
# });
# print "NSolution found :\n";
# use Data::Dumper;
# print Dumper($fifteen_search->path)."\n";
# is_deeply($fifteen_search->path,
# [
# [
# 2,
# 2
# ],
# [
# 3,
# 2
## my $self = shift;
## my $steps = shift;
## if ($steps % 5000 == 0) {
## print STDERR "steps is $steps and self is ".$self->value."\n";
## }
## return 0;
## },
# max_steps => 200000
# });
# print "NSolution found :\n";
## use Data::Dumper;
## print STDERR Dumper($fifteen_search->path)."\n";
# is_deeply($fifteen_search->path,
# [
# [
# 2,
# 2
# ],
# [
# 3,
# 2
$fifteen_search->continue_search({additional_steps =>2898});
is($fifteen_search->{steps}, 25210, 'number of steps 6');
is($fifteen_search->{search_completed},0,'search still not completed ');
$fifteen_search->continue_search({additional_steps =>2});
is($fifteen_search->{steps}, 25211, 'number of steps 7');
is($fifteen_search->{search_completed},1,'search completed ');
# use Data::Dumper;
# print STDERR Dumper($fifteen_search->path)."\n";
is_deeply ( $fifteen_search->path,
[
[
1,
2
],
[
2,
2
my $puzzle_search = new Algorithm::Search();
$puzzle_search->search({search_this=>$puzzle,
max_steps=>1000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'bfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
# print STDERR "board 1 is\n".$puzzle_search->last_object->board_out."\n\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3R R1D
L2D L1L U3L D2D
D3D U1R R2U D3D
D1 L3U L2L D1L
",
"board 1 bfs");
$puzzle_search->search({search_this=>$puzzle,
max_steps=>3000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'bfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 2 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1D L1 L3L U2L
D2D U1R R2D U1U
D3D U3U D3D U3U
D1R R2U D1R R2U
",
"board 2 bfs");
$puzzle_search->search({search_this=>$puzzle,
max_steps=>3000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'bfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 3 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3D U1
L3D L2L D1L U3U
D1D U1R R2D U2U
D2R R3U D3R R1U
",
"board 3 bfs");
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'bfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 4 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1D L1 L3L U2L
D2D U1R R2D U1U
D3D U3U D3D U3U
D1R R2U D1R R2U
",
"board 4 bfs");
$puzzle_search->search({search_this=>$puzzle,
max_steps=>200000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'bfs'
});
# print STDERR "search done found :\n";
# print STDERR "puzzle 5 steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 5 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1D U3R R1R R2R R3D
D2D L2U U1L L2D D1L
D3D U2R R3U D3R R1D
D1D U1U L3D U2L D2D
D2R R3U D1 L1U D3L
",
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'bfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 6 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "distance 6 is\n".$puzzle_search->last_object->distance_to_final_state."\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3R R1R R2D
L2D L1L L3L U2L D3D
D3D U2R R3D U1U D1D
D1D U1U D1D L3U D2L
D2R R3U D2R R3R R1
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'bfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 7 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "distance 7 is\n".$puzzle_search->last_object->distance_to_final_state."\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3R R1R R2D
U2R R3R R1D L1D D3L
U1U L3D D2L D2R R3D
U3U D1 L2D U1L D1D
L2U L1L D3L L3U D2L
#TAKESTOOLONG#
#TAKESTOOLONG# $puzzle_search->search({search_this=>$puzzle,
#TAKESTOOLONG# max_steps=>300000,
#TAKESTOOLONG# solutions_to_find=>1,
#TAKESTOOLONG# no_value_function => 1,
#TAKESTOOLONG# search_type => 'bfs'
#TAKESTOOLONG# });
#TAKESTOOLONG## print STDERR "search done found :\n";
#TAKESTOOLONG# print STDERR "steps taken ".$puzzle_search->steps."\n";
#TAKESTOOLONG# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
#TAKESTOOLONG# use Data::Dumper;
#TAKESTOOLONG## print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
#TAKESTOOLONG# print STDERR "board 8 is\n".$puzzle_search->last_object->board_out."\n\n";
#TAKESTOOLONG# print STDERR "distance 8 is\n".$puzzle_search->last_object->distance_to_final_state."\n";
#TAKESTOOLONG## print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
#TAKESTOOLONG# is ($puzzle_search->last_object->board_out,
#TAKESTOOLONG#"1R R2R R3D U2R R3D U3
#TAKESTOOLONG#L3D L2L D1L U1U D1R R2U
#TAKESTOOLONG#D1D U2R R3D L3U L2L U1L
#TAKESTOOLONG#D2D U1U D1R R2R R3D U3U
#TAKESTOOLONG#D3D U3U L3D L2L D1L U2U
##
## $puzzle_search->search({search_this=>$puzzle,
## max_steps=>300000,
## solutions_to_find=>1,
## no_value_function => 1,
## search_type => 'bfs'
## });
### print STDERR "search done found :\n";
### print STDERR "steps taken ".$puzzle_search->steps."\n";
### print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
## use Data::Dumper;
### print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
### print STDERR "board 9 is\n".$puzzle_search->last_object->board_out."\n\n";
### print STDERR "distance 9 is\n".$puzzle_search->last_object->distance_to_final_state."\n";
### print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
## is ($puzzle_search->last_object->board_out,
##"1R R2R R3R R1D U1R R2D
##U3 L1D U3L D2R R3U D3D
##U2U D2D U2U L2D U1L D1D
##L1U D3L L1U D3L U3U D2D
##U1R R2R R3R R1R R2U D3D
$puzzle_search->search({search_this=>$puzzle,
max_steps=>1000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
# print STDERR "board 1 is\n".$puzzle_search->last_object->board_out."\n\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3R R1D
L2D L1L U3L D2D
D3D U1R R2U D3D
D1 L3U L2L D1L
",
"board 1 dfs");
$puzzle_search->search({search_this=>$puzzle,
max_steps=>3000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 2 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1D L1 L3L U2L
D2D U1R R2D U1U
D3D U3U D3D U3U
D1R R2U D1R R2U
",
"board 2 dfs");
$puzzle_search->search({search_this=>$puzzle,
max_steps=>3000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 3 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3D U1
L3D L2L D1L U3U
D1D U1R R2D U2U
D2R R3U D3R R1U
",
"board 3 dfs");
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 4 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1D L1 L3L U2L
D2D U1R R2D U1U
D3D U3U D3D U3U
D1R R2U D1R R2U
",
"board 4 dfs");
$puzzle_search->search({search_this=>$puzzle,
max_steps=>200000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "puzzle 5 steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 5 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1D U3R R1R R2R R3D
D2D L2U U1L L2D D1L
D3D U2R R3U D3R R1D
D1D U1U L3D U2L D2D
D2R R3U D1 L1U D3L
",
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 6 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "distance 6 is\n".$puzzle_search->last_object->distance_to_final_state."\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3R R1R R2D
L2D L1L L3L U2L D3D
D3D U2R R3D U1U D1D
D1D U1U D1D L3U D2L
D2R R3U D2R R3R R1
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 7 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "distance 7 is\n".$puzzle_search->last_object->distance_to_final_state."\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3R R1R R2D
U2R R3R R1D L1D D3L
U1U L3D D2L D2R R3D
U3U D1 L2D U1L D1D
L2U L1L D3L L3U D2L
#TAKESTOOLONG#
#TAKESTOOLONG# $puzzle_search->search({search_this=>$puzzle,
#TAKESTOOLONG# max_steps=>300000,
#TAKESTOOLONG# solutions_to_find=>1,
#TAKESTOOLONG# no_value_function => 1,
#TAKESTOOLONG# search_type => 'dfs'
#TAKESTOOLONG# });
#TAKESTOOLONG## print STDERR "search done found :\n";
#TAKESTOOLONG# print STDERR "steps taken ".$puzzle_search->steps."\n";
#TAKESTOOLONG# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
#TAKESTOOLONG# use Data::Dumper;
#TAKESTOOLONG## print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
#TAKESTOOLONG# print STDERR "board 8 is\n".$puzzle_search->last_object->board_out."\n\n";
#TAKESTOOLONG# print STDERR "distance 8 is\n".$puzzle_search->last_object->distance_to_final_state."\n";
#TAKESTOOLONG## print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
#TAKESTOOLONG# is ($puzzle_search->last_object->board_out,
#TAKESTOOLONG#"1R R2R R3D U2R R3D U3
#TAKESTOOLONG#L3D L2L D1L U1U D1R R2U
#TAKESTOOLONG#D1D U2R R3D L3U L2L U1L
#TAKESTOOLONG#D2D U1U D1R R2R R3D U3U
#TAKESTOOLONG#D3D U3U L3D L2L D1L U2U
$puzzle_search->search({search_this=>$puzzle,
max_steps=>300000,
solutions_to_find=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 9 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "distance 9 is\n".$puzzle_search->last_object->distance_to_final_state."\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
is ($puzzle_search->last_object->board_out,
"1R R2R R3R R1D U1R R2D
U3 L1D U3L D2R R3U D3D
U2U D2D U2U L2D U1L D1D
L1U D3L L1U D3L U3U D2D
U1R R2R R3R R1R R2U D3D
$puzzle_search->search({search_this=>$puzzle,
max_steps=>1000,
solutions_to_find=>2,
preserve_solutions=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "Path: ".Dumper($puzzle_search->path)."\n";
# print STDERR "board 1 is\n".$puzzle_search->last_object->board_out."\n\n";
is (scalar($puzzle_search->paths), 1, "board 1 solutions");
$in_moves = [];
$fixed_value = [];
$in_moves->[2][1] = {U=>['U'],D=>['D']};
$in_moves->[1][1] = {U=>['L','R','U'],D=>['D'],L=>['D'],R=>['D']};
$in_moves->[3][1] = {D=>['L','R'],L=>['U'],R=>['U']};
$puzzle_search->search({search_this=>$puzzle,
max_steps=>3000,
solutions_to_find=>2,
preserve_solutions=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 2 is\n".$puzzle_search->last_object->board_out."\n\n";
# print STDERR "board 2\n";
is (scalar($puzzle_search->paths), 1, "board 2 solutions");
$in_moves = [];
$fixed_value = [];
$in_moves->[1][0] = {D=>['R'],U=>['R'],L=>['U','D']};
$in_moves->[1][1] = {L=>['L'],R=>['R']};
$puzzle_search->search({search_this=>$puzzle,
max_steps=>3000,
solutions_to_find=>2,
preserve_solutions=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 3\n";
is (scalar($puzzle_search->paths), 1, "board 3 solutions");
$in_moves = [];
$fixed_value = [];
$in_moves->[0][1] = {L=>['L','D'],R=>['R'],U=>['R']};
$in_moves->[1][0] = {L=>['D'],D=>['D'],U=>['R']};
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>2,
preserve_solutions=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 4\n";
is (scalar($puzzle_search->paths), 1, "board 4 solutions");
#puzzle 5
$in_moves = [];
$fixed_value = [];
$puzzle_search->search({search_this=>$puzzle,
max_steps=>200000,
solutions_to_find=>2,
preserve_solutions=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "puzzle 5 steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 5\n";
is (scalar($puzzle_search->paths), 1, "board 5 solutions");
$in_moves = [];
$fixed_value = [];
$in_moves->[1][0] = {U=>['R'],D=>['R'], L=>['D','U']};
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>2,
preserve_solutions=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 6\n";
is (scalar($puzzle_search->paths), 1, "board 6 solutions");
$in_moves = [];
$fixed_value = [];
$puzzle_search->search({search_this=>$puzzle,
max_steps=>10000,
solutions_to_find=>2,
preserve_solutions=>1,
no_value_function => 1,
search_type => 'dfs'
});
# print STDERR "search done found :\n";
# print STDERR "steps taken ".$puzzle_search->steps."\n";
# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
# use Data::Dumper;
# print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
# print STDERR "board 7\n";
is (scalar($puzzle_search->paths), 1, "board 7 solutions");
#TAKESTOOLONG#
#TAKESTOOLONG#
#TAKESTOOLONG# $puzzle_search->search({search_this=>$puzzle,
#TAKESTOOLONG# max_steps=>300000,
#TAKESTOOLONG# solutions_to_find=>2,
#TAKESTOOLONG# preserve_solutions=>1,
#TAKESTOOLONG# no_value_function => 1,
#TAKESTOOLONG# search_type => 'dfs'
#TAKESTOOLONG# });
#TAKESTOOLONG## print STDERR "search done found :\n";
#TAKESTOOLONG# print STDERR "steps taken ".$puzzle_search->steps."\n";
#TAKESTOOLONG# print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
#TAKESTOOLONG# use Data::Dumper;
#TAKESTOOLONG## print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
#TAKESTOOLONG# print STDERR "board 8\n";
#TAKESTOOLONG# is (scalar($puzzle_search->paths), 1, "board 8 solutions");
#TAKESTOOLONG#
#TAKESTOOLONG#
##
## $puzzle_search->search({search_this=>$puzzle,
## max_steps=>300000,
## solutions_to_find=>2,
## preserve_solutions=>1,
## no_value_function => 1,
## search_type => 'dfs'
## });
### print STDERR "search done found :\n";
### print STDERR "steps taken ".$puzzle_search->steps."\n";
### print STDERR "lo moves ".$puzzle_search->last_object->{moves}."\n";
## use Data::Dumper;
### print STDERR "lo is ".Dumper($puzzle_search->last_object)."\n";
### print STDERR "board 9\n";
## is (scalar($puzzle_search->paths), 1, "board 9 solutions");
##
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
", 'max depth dfs');
#use Data::Dumper;
#print STDERR "x: ".Dumper($travel_search->search_trace)."\n";
is_deeply($travel_search->search_trace,
[
{
'commit' => undef,
'cost' => undef,
'move' => undef,
'value_before' => undef,
'value_after' => 'Minneapolis'
},
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
", 'bfs max depth');
#use Data::Dumper;
#print STDERR "y: ".Dumper($travel_search->search_trace)."\n";
is_deeply($travel_search->search_trace,
[
{
'commit' => undef,
'cost' => undef,
'move' => undef,
'value_before' => undef,
'value_after' => 'Minneapolis'
},
# 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'
},
my @letters = split //,$word;
my $add_to_tree = $tree;
foreach my $letter (@letters) {
#print STDERR "Letter $letter\n";
$add_to_tree->{$letter} = $add_to_tree->{$letter} || {};
$add_to_tree = $add_to_tree->{$letter};
}
#print STDERR "end of word $word\n";
}
close $fh;
#use Data::Dumper;
#print STDERR Dumper($tree)."\n";
#print STDERR "is AD a word? ";
#print STDERR $word_list{'AD'};
#print STDERR "\n";
#exit;
# print STDERR "Word count ".scalar(keys %word_list);
sub new {return bless {}}
sub set_position {
( run in 0.456 second using v1.01-cache-2.11-cpan-a5abf4f5562 )