AI-Pathfinding-OptimizeMultiple

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN


# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v6.024.
use strict;
use warnings;

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,
    "Exception::Class" => 0,
    "File::Path" => 0,
    "Getopt::Long" => 0,
    "IO::File" => 0,
    "MooX" => 0,
    "MooX::Types::MooseLike::Base" => 0,
    "MooX::late" => "0.007",
    "PDL" => 0,
    "PDL::IO::FastRaw" => 0,
    "Scalar::Util" => 0,
    "autodie" => 0,
    "perl" => "5.012",
    "strict" => 0,
    "vars" => 0,
    "warnings" => 0
  },
  "script_files" => [
    "bin/optimize-game-ai-multi-tasking"
  ],
  "test_requires" => {
    "File::Spec" => 0,
    "IO::Handle" => 0,
    "IPC::Open3" => 0,
    "Test::Differences" => 0,
    "Test::More" => "0.88"
  }
);


my %fallback_build_requires = (
  "File::Spec" => 0,
  "IO::Handle" => 0,
  "IPC::Open3" => 0,
  "Module::Build" => "0.28",
  "Test::Differences" => 0,
  "Test::More" => "0.88"
);


unless ( eval { Module::Build->VERSION(0.4004) } ) {
  delete $module_build_args{test_requires};
  $module_build_args{build_requires} = \%fallback_build_requires;
}

my $build = Module::Build->new(%module_build_args);


$build->create_build_script;

LICENSE  view on Meta::CPAN


This is free software, licensed under:

  The MIT (X11) License

The MIT License

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to
whom the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT

META.json  view on Meta::CPAN

   "license" : [
      "mit"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
      "version" : 2
   },
   "name" : "AI-Pathfinding-OptimizeMultiple",
   "prereqs" : {
      "build" : {
         "requires" : {
            "Module::Build" : "0.28"
         }
      },
      "configure" : {
         "requires" : {
            "Module::Build" : "0.28"
         }
      },
      "develop" : {
         "requires" : {
            "Pod::Coverage::TrustPod" : "0",
            "Test::CPAN::Changes" : "0.19",
            "Test::EOL" : "0",
            "Test::More" : "0.96",
            "Test::NoTabs" : "0",
            "Test::Pod" : "1.41",
            "Test::Pod::Coverage" : "1.08",
            "Test::TrailingSpace" : "0.0203"
         }
      },
      "runtime" : {
         "requires" : {
            "Carp" : "0",
            "Exception::Class" : "0",
            "File::Path" : "0",
            "Getopt::Long" : "0",
            "IO::File" : "0",
            "MooX" : "0",
            "MooX::Types::MooseLike::Base" : "0",
            "MooX::late" : "0.007",
            "PDL" : "0",
            "PDL::IO::FastRaw" : "0",
            "Scalar::Util" : "0",
            "autodie" : "0",
            "perl" : "5.012",
            "strict" : "0",
            "vars" : "0",
            "warnings" : "0"
         }
      },
      "test" : {
         "requires" : {
            "File::Spec" : "0",
            "IO::Handle" : "0",
            "IPC::Open3" : "0",
            "Test::Differences" : "0",
            "Test::More" : "0.88"
         }
      }
   },
   "provides" : {
      "AI::Pathfinding::OptimizeMultiple" : {

META.json  view on Meta::CPAN

      "AI::Pathfinding::OptimizeMultiple::ScanRun" : {
         "file" : "lib/AI/Pathfinding/OptimizeMultiple/ScanRun.pm",
         "version" : "v0.0.17"
      },
      "AI::Pathfinding::OptimizeMultiple::SimulationResults" : {
         "file" : "lib/AI/Pathfinding/OptimizeMultiple/SimulationResults.pm",
         "version" : "v0.0.17"
      }
   },
   "release_status" : "stable",
   "resources" : {
      "bugtracker" : {
         "web" : "https://github.com/shlomif/fc-solve/issues"
      },
      "homepage" : "http://metacpan.org/release/AI-Pathfinding-OptimizeMultiple",
      "repository" : {
         "type" : "git",
         "url" : "ssh://git@github.com/shlomif/fc-solve.git",
         "web" : "http://github.com/shlomif/fc-solve"
      }
   },

META.json  view on Meta::CPAN

   "x_Dist_Zilla" : {
      "perl" : {
         "version" : "5.034001"
      },
      "plugins" : [
         {
            "class" : "Dist::Zilla::Plugin::Prereqs",
            "config" : {
               "Dist::Zilla::Plugin::Prereqs" : {
                  "phase" : "test",
                  "type" : "requires"
               }
            },
            "name" : "@Filter/TestMoreDoneTesting",
            "version" : "6.024"
         },
         {
            "class" : "Dist::Zilla::Plugin::AutoPrereqs",
            "name" : "@Filter/AutoPrereqs",
            "version" : "6.024"
         },

META.json  view on Meta::CPAN

            "class" : "Dist::Zilla::Plugin::MetaProvides::Package",
            "config" : {
               "Dist::Zilla::Plugin::MetaProvides::Package" : {
                  "finder_objects" : [
                     {
                        "class" : "Dist::Zilla::Plugin::FinderCode",
                        "name" : "@Filter/MetaProvides::Package/AUTOVIV/:InstallModulesPM",
                        "version" : "6.024"
                     }
                  ],
                  "include_underscores" : 0
               },
               "Dist::Zilla::Role::MetaProvider::Provider" : {
                  "$Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.002004",
                  "inherit_missing" : 1,
                  "inherit_version" : 1,
                  "meta_noindex" : 1
               },
               "Dist::Zilla::Role::ModuleMetadata" : {
                  "Module::Metadata" : "1.000037",
                  "version" : "0.006"

META.json  view on Meta::CPAN

         {
            "class" : "Dist::Zilla::Plugin::AutoPrereqs",
            "name" : "AutoPrereqs",
            "version" : "6.024"
         },
         {
            "class" : "Dist::Zilla::Plugin::Prereqs",
            "config" : {
               "Dist::Zilla::Plugin::Prereqs" : {
                  "phase" : "runtime",
                  "type" : "requires"
               }
            },
            "name" : "Prereqs",
            "version" : "6.024"
         },
         {
            "class" : "Dist::Zilla::Plugin::PruneCruft",
            "name" : "PruneCruft",
            "version" : "6.024"
         },

META.json  view on Meta::CPAN

      "zilla" : {
         "class" : "Dist::Zilla::Dist::Builder",
         "config" : {
            "is_trial" : 0
         },
         "version" : "6.024"
      }
   },
   "x_generated_by_perl" : "v5.34.1",
   "x_serialization_backend" : "Cpanel::JSON::XS version 4.26",
   "x_spdx_expression" : "MIT"
}

META.yml  view on Meta::CPAN

---
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:
  Module::Build: '0.28'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.024, CPAN::Meta::Converter version 2.150010'
license: mit
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: AI-Pathfinding-OptimizeMultiple
provides:
  AI::Pathfinding::OptimizeMultiple:

META.yml  view on Meta::CPAN

    version: v0.0.17
  AI::Pathfinding::OptimizeMultiple::Scan:
    file: lib/AI/Pathfinding/OptimizeMultiple/Scan.pm
    version: v0.0.17
  AI::Pathfinding::OptimizeMultiple::ScanRun:
    file: lib/AI/Pathfinding/OptimizeMultiple/ScanRun.pm
    version: v0.0.17
  AI::Pathfinding::OptimizeMultiple::SimulationResults:
    file: lib/AI/Pathfinding/OptimizeMultiple/SimulationResults.pm
    version: v0.0.17
requires:
  Carp: '0'
  Exception::Class: '0'
  File::Path: '0'
  Getopt::Long: '0'
  IO::File: '0'
  MooX: '0'
  MooX::Types::MooseLike::Base: '0'
  MooX::late: '0.007'
  PDL: '0'
  PDL::IO::FastRaw: '0'
  Scalar::Util: '0'
  autodie: '0'
  perl: '5.012'
  strict: '0'
  vars: '0'
  warnings: '0'
resources:
  bugtracker: https://github.com/shlomif/fc-solve/issues
  homepage: http://metacpan.org/release/AI-Pathfinding-OptimizeMultiple
  repository: ssh://git@github.com/shlomif/fc-solve.git
version: 0.0.17
x_Dist_Zilla:
  perl:
    version: '5.034001'
  plugins:
    -
      class: Dist::Zilla::Plugin::Prereqs
      config:
        Dist::Zilla::Plugin::Prereqs:
          phase: test
          type: requires
      name: '@Filter/TestMoreDoneTesting'
      version: '6.024'
    -
      class: Dist::Zilla::Plugin::AutoPrereqs
      name: '@Filter/AutoPrereqs'
      version: '6.024'
    -
      class: Dist::Zilla::Plugin::ExecDir
      name: '@Filter/ExecDir'
      version: '6.024'

META.yml  view on Meta::CPAN

      version: '6.024'
    -
      class: Dist::Zilla::Plugin::MetaProvides::Package
      config:
        Dist::Zilla::Plugin::MetaProvides::Package:
          finder_objects:
            -
              class: Dist::Zilla::Plugin::FinderCode
              name: '@Filter/MetaProvides::Package/AUTOVIV/:InstallModulesPM'
              version: '6.024'
          include_underscores: 0
        Dist::Zilla::Role::MetaProvider::Provider:
          $Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.002004'
          inherit_missing: '1'
          inherit_version: '1'
          meta_noindex: '1'
        Dist::Zilla::Role::ModuleMetadata:
          Module::Metadata: '1.000037'
          version: '0.006'
      name: '@Filter/MetaProvides::Package'
      version: '2.004003'

META.yml  view on Meta::CPAN

      version: '6.024'
    -
      class: Dist::Zilla::Plugin::AutoPrereqs
      name: AutoPrereqs
      version: '6.024'
    -
      class: Dist::Zilla::Plugin::Prereqs
      config:
        Dist::Zilla::Plugin::Prereqs:
          phase: runtime
          type: requires
      name: Prereqs
      version: '6.024'
    -
      class: Dist::Zilla::Plugin::PruneCruft
      name: PruneCruft
      version: '6.024'
    -
      class: Dist::Zilla::Plugin::PruneFiles
      name: PruneFiles
      version: '6.024'

META.yml  view on Meta::CPAN

      class: Dist::Zilla::Plugin::FinderCode
      name: '@Filter/MetaProvides::Package/AUTOVIV/:InstallModulesPM'
      version: '6.024'
  zilla:
    class: Dist::Zilla::Dist::Builder
    config:
      is_trial: '0'
    version: '6.024'
x_generated_by_perl: v5.34.1
x_serialization_backend: 'YAML::Tiny version 1.73'
x_spdx_expression: MIT

bin/optimize-game-ai-multi-tasking  view on Meta::CPAN


To be written.

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

bin/optimize-game-ai-multi-tasking  view on Meta::CPAN

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

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

        return $self->_quotas()->($iter);
    }
}

sub _calc_get_iter_state_param_method
{
    my $self = shift;

    my $optimize_for = $self->_optimize_for();

    my %resolve = (
        len        => "_get_iter_state_params_len",
        minmax_len => "_get_iter_state_params_minmax_len",
        speed      => "_get_iter_state_params_speed",
    );

    return $resolve{$optimize_for};
}

sub _get_iter_state_params
{
    my $self = shift;

    my $method = $self->_calc_get_iter_state_param_method();

    return $self->$method();
}

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

                    $self->_stats_factors->{
                        ( $self->_selected_scans->[$selected_scan_idx]->id() ),
                    } // 1
                )
            ),
            scan_idx => $selected_scan_idx,
        }
    );
}

sub calc_flares_meta_scan
{
    my $self = shift;

    $self->chosen_scans( [] );

    $self->_total_boards_solved(0);
    $self->_total_iters(0);

    $self->_status("iterating");

    my $iters_quota      = 0;
    my $flares_num_iters = PDL::Core::pdl( [ (0) x $self->_get_num_scans() ] );
    my $ones_constant =
        PDL::Core::pdl( [ map { [1] } ( 1 .. $self->_get_num_scans() ) ] );

    my $next_num_iters_for_each_scan_x_scan =
        ( ( $ones_constant x $flares_num_iters ) );

    my $num_moves = $self->_scans_data->slice(":,:,1");

    # The number of moves for dimension 0,1,2 above.
    my $num_moves_repeat = $num_moves->clump( 1 .. 2 )->xchg( 0, 1 )
        ->dummy( 0, $self->_get_num_scans() );

    my $selected_scan_idx;

    my $loop_iter_num = 0;

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


    my $last_avg = $UNSOLVED_NUM_MOVES_CONSTANT;

FLARES_LOOP:
    while ( my $q_more = $self->_get_next_quota() )
    {
        $iters_quota += $q_more;

        # Next number of iterations for each scan x scan combination.
        my $next_num_iters = (
            ( $ones_constant x $flares_num_iters ) + (
                PDL::MatrixOps::identity( $self->_get_num_scans() ) *
                    $iters_quota
            )
        );

        # print "\$next_num_iters = $next_num_iters\n";

        my $iters = $self->_scans_data()->slice(":,:,0");

        my $iters_repeat =

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

        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() );

        # A boolean tensor:
        # Dimension 0 - board.
        # Dimension 1 - scans.
        my $solved_with_which_iter =
            ( $flares_num_iters_repeat >= $iters->clump( 1 .. 2 ) ) &
            ( $iters->clump( 1 .. 2 ) >= 0 );

        my $total_num_iters = (
            ( $solved_with_which_iter * $flares_num_iters_repeat )->sum() + (
                $solved_with_which_iter->not()->andover() *
                    $flares_num_iters->sum()
            )->sum()
        );

        print "Finished ", $loop_iter_num++,
" ; #Solved = $num_solved ; Iters = $total_num_iters ; Avg = $min_avg\n";
        STDOUT->flush();
    }
}

sub calc_board_iters

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

            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


=over 4

=item * L<https://groups.google.com/group/comp.ai.games/msg/41e899e9beea5583?dmode=source&output=gplain&noredirect>

=item * L<http://www.shlomifish.org/lecture/Perl/Lightning/Opt-Multi-Task-in-PDL/>

=back

Given statistics on the performance of several game AI searches (or scans)
across a representative number of initial cases, find a scan
that solves most deals with close-to-optimal performance, by using switch
tasking.

=head1 SUBROUTINES/METHODS

=head2 my $chosen_scans_array_ref = $self->chosen_scans()

Returns the scans that have been chosen to perform the iteration. Each one is
a AI::Pathfinding::OptimizeMultiple::ScanRun object.

=head2 $calc_meta_scan->calc_meta_scan()

Calculates the meta-scan after initialisation. See here for the details
of the algorithm:

L<http://www.shlomifish.org/lecture/Freecell-Solver/The-Next-Pres/slides/multi-tasking/best-meta-scan/>

=head2 $self->calc_flares_meta_scan()

This function calculates the flares meta-scan: i.e: assuming that all atomic
scans are run one after the other and the shortest solutions of all
successful scans are being picked.

=head2 $calc_meta_scan->calc_board_iters($board_idx)

Calculates the iterations of the board $board_idx in all the scans.

Returns a hash_ref containing the key 'per_scan_iters' for the iterations
per scan, and 'board_iters' for the total board iterations when ran in the
scans.

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

=over 4

=item * "solved_all"

=item * "iterating"

=item * "out_of_quotas"

=back

=head2 my $sim_results_obj = $calc_meta_scan->simulate_board($board_idx, $args)

Simulates the board No $board_idx through the scan. Returns a
L<AI::Pathfinding::OptimizeMultiple::SimulationResults> object.

$args is an optional hash reference. It may contain a value with the key of
C<'chosen_scans'> that may specify an alternative scans to traverse.

=head2 my $n = $calc_meta_scan->get_total_iters()

Returns the total iterations count so far.

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

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.

=item * L<Alternative Implementation in C#/.NET|https://bitbucket.org/shlomif/fc-solve/src/cc5b428ed9bad0132d7a7bc1a14fc6d3650edf45/fc-solve/presets/soft-threads/meta-moves/auto-gen/optimize-seq?at=master>

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.pm  view on Meta::CPAN

B<popl> from Freenode's #perl for trying to dig some references to an existing
algorithm in the scientific literature.

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

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

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

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

use warnings;

use MooX qw/late/;

use Getopt::Long qw(GetOptionsFromArray);
use IO::File     ();

use AI::Pathfinding::OptimizeMultiple                ();
use AI::Pathfinding::OptimizeMultiple::PostProcessor ();

# TODO : restore later.
# use MyInput;

use Carp ();

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' );

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


sub _get_scan_line
{
    my ( $self, $line ) = @_;

    return
          $line->{'cmd_line'}
        . " -step 500 "
        . join( " ",
        map { $_, $line->{'id'} }
            ( "--st-name", ( $self->_is_flares() ? "--flare-name" : () ) ) );
}

sub _get_lines_of_scan_defs
{
    my $self = shift;
    return [ map { $self->_get_scan_line($_) } @{ $self->_get_used_scans() } ];
}

sub _scan_def_line_mapping
{
    my ( $self, $lines_aref ) = @_;

    return $self->_map_all_but_last(
        sub {
            my ($line) = @_;

            return $line . ' ' . ( $self->_is_flares() ? "-nf" : "-nst" );
        },
        [
            map {
                my $line = $_;

                # Add the -sp r:tf flag to each scan if specified - it enhances
                # performance, but timing the scans with it makes the total
                # scan sub-optimal.
                if ( $self->_add_horne_prune() )
                {

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

    return $self->_selected_scans()->[$index]->id();
}

sub _format_prelude_iter
{
    my $self = shift;

    my $iter = shift;

    return
          ( $self->_is_flares() ? "Run:" : "" )
        . $iter->iters() . '@'
        . $self->_map_scan_idx_to_id( $iter->scan_idx() );
}

sub _get_line_of_prelude
{
    my $self = shift;
    return
        +( $self->_is_flares() ? "--flares-plan" : "--prelude" ) . qq{ "}
        . join( ",",
        map { $self->_format_prelude_iter($_) } @{ $self->_chosen_scans() } )
        . "\"";
}

sub _calc_script_lines
{
    my $self = shift;
    return [
        $self->_get_line_of_command(),

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

        $self->_post_processor->process( $self->_arbitrator->chosen_scans() );

    $self->_chosen_scans($scans);
}

sub _do_trace_for_board
{
    my $self  = shift;
    my $board = shift;

    my $results = $self->_arbitrator()->calc_board_iters($board);
    print "\@info=" . join( ",", @{ $results->{per_scan_iters} } ) . "\n";
    print +( $board + $self->_start_board() ) . ": "
        . $results->{board_iters} . "\n";
}

sub _real_do_trace
{
    my $self = shift;
    foreach my $board ( 0 .. $self->_num_boards() - 1 )
    {
        $self->_do_trace_for_board($board);
    }
}

sub _do_trace
{
    my $self = shift;

    # Analyze the results

    if ( $self->_should_trace_be_done() )
    {
        $self->_real_do_trace();
    }
}

sub _get_run_string
{
    my $self    = shift;
    my $results = shift;

    return join(
        "",
        map {
            sprintf( '%i@%i,',
                $_->iters(), $self->_map_scan_idx_to_id( $_->scan_idx() ) )
        } @{ $self->_post_processor->process( $results->scan_runs() ) },
    );
}

sub _do_simulation_for_board
{
    my ( $self, $board ) = @_;

    my $results = $self->_arbitrator()->simulate_board($board);

    my $scan_mapper = sub {
        my $index = shift;

        return $self->_map_scan_idx_to_id($index);
    };

    return sprintf( "%i:%s:%s:%i",
        $board + 1,
        $results->get_status(),
        $self->_get_run_string($results),
        $results->get_total_iters(),
    );
}

sub _real_do_simulation
{
    my $self = shift;

    open my $simulate_out_fh, ">", $self->_simulate_to()
        or Carp::confess( "Could not open " . $self->_simulate_to() . " - $!" );

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


    close($simulate_out_fh);

    return;
}

sub _do_simulation
{
    my $self = shift;

    # Analyze the results

    if ( defined( $self->_simulate_to() ) )
    {
        $self->_real_do_simulation();
    }

    return;
}

sub run

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

    $self->_init_arbitrator();
    $self->_arbitrator_process();
    $self->_report_total_iters();
    $self->_write_script();
    $self->_do_trace();
    $self->_do_simulation();

    return 0;
}

sub run_flares
{
    my $self = shift;

    $self->_optimize_for("len");
    $self->_is_flares(1);

    $self->_init_arbitrator();

    $self->_arbitrator()->calc_flares_meta_scan();

    my $scans =
        $self->_post_processor->process( $self->_arbitrator->chosen_scans() );

    $self->_chosen_scans($scans);
    $self->_report_total_iters();
    $self->_write_script();
    $self->_do_trace();
    $self->_do_simulation();

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

=head1 VERSION

version 0.0.17

=head1 SUBROUTINES/METHODS

=head2 $self->run()

For internal use.

=head2 $self->run_flares()

For internal use.

=head2 $self->argv()

An array ref of command line arguments.

=head2 $self->input_obj_class()

The class to handle the input data - by default -

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


Moo leftover. B<INTERNAL USE>.

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

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

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

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

$scan_id is a string and lookup_scan_idx_based_on_id() looks up its index
in the scans.

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

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

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

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

    my @dims = $scans_data->dims();

    return $scans_data->slice(
        join( ",", ":", $self->_scan_idx(), ( ("(0)") x ( @dims - 2 ) ) ) );
}

sub update_total_iters
{
    my $state = shift;

    # $r is the result of this scan.
    my $r = $state->idx_slice();

    # Add the total iterations for all the states that were solved by
    # this scan.
    $state->_main()
        ->_add_to_total_iters(
        PDL::sum( ( ( $r <= $state->_quota() ) & ( $r > 0 ) ) * $r ) );

    # Find all the states that weren't solved.
    my $indexes = PDL::which( ( $r > $state->_quota() ) | ( $r < 0 ) );

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


Internal use.

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

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

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

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


For internal use.

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

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

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

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

Returns the path to the data file of the scan, where the numbers of iterations
per board are stored.

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

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

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

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

B<popl> from Freenode's #perl for trying to dig some references to an existing
algorithm in the scientific literature.

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

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

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

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

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

AI::Pathfinding::OptimizeMultiple::SimulationResults - the simulation results.

=head1 VERSION

version 0.0.17

=head1 SYNOPSIS

=head1 DESCRIPTION

A class for simulation results.

=head1 SUBROUTINES/METHODS

=head2 $scan_run->status()

The status.

=head2 $scan_run->total_iters()

The total iterations count so far.

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


Shlomi Fish, L<http://www.shlomifish.org/> .

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.

=over 4

=item *

MetaCPAN

A modern, open-source CPAN search engine, useful to view POD in HTML format.

L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>

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

CPAN Testers

The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.

L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>

=item *

CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>

=back

=head2 Bugs / Feature Requests

Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
progress on the request by the system.

=head2 Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)

L<http://github.com/shlomif/fc-solve>

  git clone ssh://git@github.com/shlomif/fc-solve.git

rejects.pod  view on Meta::CPAN

# lib/AI/Pathfinding/OptimizeMultiple.pm

=head1 BUGS

Please report any bugs or feature requests to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AI-Pathfinding-OptimizeMultiple>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc AI::Pathfinding::OptimizeMultiple

You can also look for information at:

=over 4

t/optimize-multiple-full-test.t  view on Meta::CPAN


use PDL (qw/ pdl /);

use AI::Pathfinding::OptimizeMultiple ();

# TEST:$c=0;
sub test_based_on_data
{
    local $Test::Builder::Level = $Test::Builder::Level + 1;

    my ( $scans_aref, $quotas_aref, $want_results, $stats_factors, $blurb ) =
        @_;

    my $results_aref = [];

    my $selected_scans = [
        map {
            my $id = $_->{name};

            AI::Pathfinding::OptimizeMultiple::Scan->new(
                id       => $id,
                cmd_line => "-l $id",
            )
        } @{$scans_aref},

t/optimize-multiple-full-test.t  view on Meta::CPAN

    my @have = (
        map {
            +{
                name  => $scans_aref->[ $_->scan_idx ]->{name},
                iters => $_->iters,
            }
        } @{ $obj->chosen_scans() }
    );

    # TEST:$c++;
    return eq_or_diff( \@have, $want_results, "$blurb - (eq_or_diff)", );
}

# TEST:$test_based_on_data=$c;

{
    # TEST*$test_based_on_data
    test_based_on_data(
        [
            {
                name => "first",



( run in 1.311 second using v1.01-cache-2.11-cpan-49f99fa48dc )