AI-Pathfinding-OptimizeMultiple

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use Module::Build 0.28;
 
 
my %module_build_args = (
  "build_requires" => {
    "Module::Build" => "0.28"
  },
  "configure_requires" => {
    "Module::Build" => "0.28"
  },
  "dist_abstract" => "optimize path finding searches for a large set of initial conditions (for better average performance).",
  "dist_author" => [
    "Shlomi Fish <shlomif\@cpan.org>"
  ],
  "dist_name" => "AI-Pathfinding-OptimizeMultiple",
  "dist_version" => "0.0.17",
  "license" => "mit",
  "module_name" => "AI::Pathfinding::OptimizeMultiple",
  "recursive_test_files" => 1,
  "requires" => {
    "Carp" => 0,

META.json  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
{
   "abstract" : "optimize path finding searches for a large set of initial conditions (for better average performance).",
   "author" : [
      "Shlomi Fish <shlomif@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 6.024, CPAN::Meta::Converter version 2.150010",
   "license" : [
      "mit"
   ],
   "meta-spec" : {

META.yml  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
---
abstract: 'optimize path finding searches for a large set of initial conditions (for better average performance).'
author:
  - 'Shlomi Fish <shlomif@cpan.org>'
build_requires:
  File::Spec: '0'
  IO::Handle: '0'
  IPC::Open3: '0'
  Module::Build: '0.28'
  Test::Differences: '0'
  Test::More: '0.88'
configure_requires:

README  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
This archive contains the distribution AI-Pathfinding-OptimizeMultiple,
version 0.0.17:
 
  optimize path finding searches for a large set of initial conditions (for better average performance).
 
This software is Copyright (c) 2012 by Shlomi Fish.
 
This is free software, licensed under:
 
  The MIT (X11) License
 
 
This README file was generated by Dist::Zilla::Plugin::Readme v6.024.

lib/AI/Pathfinding/OptimizeMultiple.pm  view on Meta::CPAN

448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
my $min_avg;
 
( $min_avg, undef, $selected_scan_idx, undef ) =
    $solved_moves_avgs->minmaximum();
 
$last_avg = $min_avg;
 
push @{ $self->chosen_scans() },
    $self->_calc_chosen_scan( $selected_scan_idx, $iters_quota );
 
$flares_num_iters->set( $selected_scan_idx,
    $flares_num_iters->at($selected_scan_idx) + $iters_quota );
$self->_selected_scans()->[$selected_scan_idx]->mark_as_used();
 
$iters_quota = 0;
 
my $num_solved = $solved_moves_counts->at($selected_scan_idx);
 
my $flares_num_iters_repeat =
    $flares_num_iters->dummy( 0, $self->_num_boards() );

lib/AI/Pathfinding/OptimizeMultiple.pm  view on Meta::CPAN

648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
__END__
 
=pod
 
=encoding UTF-8
 
=head1 NAME
 
AI::Pathfinding::OptimizeMultiple - optimize path finding searches for a large
set of initial conditions (for better average performance).
 
=head1 VERSION
 
version 0.0.17
 
=head1 SYNOPSIS
 
    use AI::Pathfinding::OptimizeMultiple
 
    my @scans =

lib/AI/Pathfinding/OptimizeMultiple.pm  view on Meta::CPAN

686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
        scans_iters_pdls =>
        {
            first_search => $first_search_pdl,
            second_search => $second_search_pdl,
        },
        quotas => [400, 300, 200],
        selected_scans =>
        [
            AI::Pathfinding::OptimizeMultiple::Scan->new(
                id => 'first_search',
                cmd_line => "--preset first_search",
            ),
            AI::Pathfinding::OptimizeMultiple::Scan->new(
                id => 'second_search',
                cmd_line => "--preset second_search",
            ),
            AI::Pathfinding::OptimizeMultiple::Scan->new(
                id => 'third_search',
                cmd_line => "--preset third_search",
            ),
        ],
    }
);
 
$obj->calc_meta_scan();
 
foreach my $scan_alloc (@{$self->chosen_scans()})
{
    printf "Run %s for %d iterations.\n",

lib/AI/Pathfinding/OptimizeMultiple.pm  view on Meta::CPAN

791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
Moo leftover. B<INTERNAL USE>.
 
=head1 SEE ALSO
 
=over 4
 
=item * L<Freecell Solver|http://fc-solve.shlomifish.org/>
 
For which this code was first written and used.
 
 
An Alternative implementation in C#/.NET, which was written because the
performance of the Perl/PDL code was too slow.
 
=item * L<PDL> - Perl Data Language
 
Used here.
 
=back

lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm  view on Meta::CPAN

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
has argv             => ( isa => 'ArrayRef[Str]', is => 'ro', required => 1, );
has _arbitrator      => ( is  => 'rw' );
has _add_horne_prune => ( isa => 'Bool',     is => 'rw' );
has _chosen_scans    => ( isa => 'ArrayRef', is => 'rw' );
has _should_exit_immediately =>
    ( isa => 'Bool', is => 'rw', default => sub { 0; }, );
has input_obj_class  => ( isa => 'Str', is => 'rw' );
has _input_obj       => ( is  => 'rw' );
has _is_flares       => ( is  => 'rw'isa => 'Bool', default => sub { 0; }, );
has _num_boards      => ( isa => 'Int', is  => 'rw' );
has _offset_quotas   => ( isa => 'Int', is  => 'rw' );
has _optimize_for    => ( isa => 'Str', is  => 'rw' );
has _output_filename => ( isa => 'Str', is  => 'rw' );
has _post_processor => (
    isa => 'Maybe[AI::Pathfinding::OptimizeMultiple::PostProcessor]',
    is  => 'rw'
);
has _quotas_are_cb        => ( isa => 'Bool',       is => 'rw' );
has _quotas_expr          => ( isa => 'Maybe[Str]', is => 'rw' );
has _should_rle_be_done   => ( isa => 'Bool',       is => 'rw' );
has _should_trace_be_done => ( isa => 'Bool',       is => 'rw' );

lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm  view on Meta::CPAN

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Command line parameters
my $_start_board         = 1;
my $num_boards           = 32000;
my $output_filename      = "-";
my $should_trace_be_done = 0;
my $should_rle_be_done   = 1;
my $_quotas_expr         = undef;
my $quotas_are_cb        = 0;
my $optimize_for         = "speed";
my $offset_quotas        = 0;
my $simulate_to          = undef;
my $_add_horne_prune     = 0;
my $input_obj_class = 'AI::Pathfinding::OptimizeMultiple::DataInputObj';
my %stats_factors;
 
my $help = 0;
my $man  = 0;
GetOptionsFromArray(
    $self->argv(),
    'help|h'          => \$help,
    man               => \$man,
    "o|output=s"      => \$output_filename,
    "num-boards=i"    => \$num_boards,
    "trace"           => \$should_trace_be_done,
    "rle!"            => \$should_rle_be_done,
    "start-board=i"   => \$_start_board,
    "quotas-expr=s"   => \$_quotas_expr,
    "quotas-are-cb"   => \$quotas_are_cb,
    "offset-quotas"   => \$offset_quotas,
    "opt-for=s"       => \$optimize_for,
    "simulate-to=s"   => \$simulate_to,
    "sprtf"           => \$_add_horne_prune,
    "input-class=s"   => \$input_obj_class,
    "stats-factors=f" => \%stats_factors,
) or die "Extracting options from ARGV array failed - $!";
 
if ($help)
{
    $self->_should_exit_immediately(1);

lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm  view on Meta::CPAN

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
}
 
$self->_start_board($_start_board);
$self->_num_boards($num_boards);
$self->_output_filename($output_filename);
$self->_should_trace_be_done($should_trace_be_done);
$self->_should_rle_be_done($should_rle_be_done);
$self->_quotas_expr($_quotas_expr);
$self->_quotas_are_cb($quotas_are_cb);
$self->_optimize_for($optimize_for);
$self->_offset_quotas($offset_quotas);
$self->_simulate_to($simulate_to);
$self->_add_horne_prune($_add_horne_prune);
$self->_stats_factors( \%stats_factors );
$self->input_obj_class($input_obj_class);
 
{
    my $class = $self->input_obj_class();
    if ( $class !~ m{\A$_module_re\z} )
    {
        Carp::confess(

lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm  view on Meta::CPAN

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
                    num_boards  => $self->_num_boards(),
                }
            )
        );
    }
 
    $self->_post_processor(
        AI::Pathfinding::OptimizeMultiple::PostProcessor->new(
            {
                do_rle        => $self->_should_rle_be_done(),
                offset_quotas => $self->_offset_quotas(),
            }
        )
    );
 
    return;
}
 
sub _selected_scans
{
    my $self = shift;

lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm  view on Meta::CPAN

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
            } @$lines_aref
        ],
    );
}
 
sub _calc_iter_quota
{
    my $self  = shift;
    my $quota = shift;
 
    if ( $self->_offset_quotas() )
    {
        return $quota + 1;
    }
    else
    {
        return $quota;
    }
}
 
sub _map_scan_idx_to_id

lib/AI/Pathfinding/OptimizeMultiple/PostProcessor.pm  view on Meta::CPAN

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$AI::Pathfinding::OptimizeMultiple::PostProcessor::VERSION = '0.0.17';
use strict;
 
use 5.012;
 
use MooX qw/late/;
 
has _should_do_rle =>
    ( isa => 'Bool', is => 'ro', init_arg => 'do_rle', required => 1 );
has _offset_quotas => (
    isa      => 'Bool',
    is       => 'ro',
    init_arg => 'offset_quotas',
    required => 1
);
 
sub scans_rle
{
    my $self = shift;
 
    my @scans_list = @{ shift() };
 
    my $scan = shift(@scans_list);

lib/AI/Pathfinding/OptimizeMultiple/PostProcessor.pm  view on Meta::CPAN

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
sub process
{
    my $self = shift;
 
    my $scans_orig = shift;
 
    # clone the scans.
    my $scans = [ map { $_->clone(); } @{$scans_orig} ];
 
    if ( $self->_offset_quotas )
    {
        $scans = [
            map {
                my $ret = $_->clone();
                $ret->iters( $ret->iters() + 1 );
                $ret;
            } @$scans
        ];
    }



( run in 0.644 second using v1.01-cache-2.11-cpan-87723dcf8b7 )