view release on metacpan or search on metacpan
lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm view on Meta::CPAN
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' );
has _simulate_to => ( isa => 'Maybe[Str]', is => 'rw' );
has _start_board => ( isa => 'Int', is => 'rw' );
has _stats_factors =>
( isa => 'HashRef', is => 'rw', default => sub { return +{}; }, );
my $_component_re = qr/[A-Za-z][A-Za-z0-9_]*/;
my $_module_re = qr/$_component_re(?:::$_component_re)*/;
sub BUILD
{
my $self = shift;
# 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;
lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm view on Meta::CPAN
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 - $!";
lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm view on Meta::CPAN
$self->_should_exit_immediately(1);
print <<"EOF";
$0 - optimize a game AI multi-tasking configuration
--help | -h - displays this help screen
--output=[filename] | -o [filename] - output to this file instead of STDOUT.
EOF
return;
}
$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);
lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm view on Meta::CPAN
eval "require $class;";
if ($@)
{
die "Could not load '$class' - <<$@>>";
}
# TODO : Restore later.
$self->_input_obj(
$class->new(
{
start_board => $self->_start_board(),
num_boards => $self->_num_boards(),
}
)
);
}
$self->_post_processor(
AI::Pathfinding::OptimizeMultiple::PostProcessor->new(
{
do_rle => $self->_should_rle_be_done(),
lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm view on Meta::CPAN
$self->_get_script_fh()
->print( $cmd_line_string,
$self->_get_script_terminator($cmd_line_string) );
}
sub _get_line_of_command
{
my $self = shift;
my $args_string = join( " ",
$self->_start_board(),
$self->_start_board() + $self->_num_boards() - 1, 1 );
return "freecell-solver-range-parallel-solve $args_string";
}
sub _line_ends_mapping
{
my $self = shift;
return $self->_map_all_but_last( sub { "$_[0] \\\n" }, shift );
}
sub _get_used_scans
lib/AI/Pathfinding/OptimizeMultiple/App/CmdLine.pm view on Meta::CPAN
$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);
}
lib/AI/Pathfinding/OptimizeMultiple/DataInputObj.pm view on Meta::CPAN
use MooX qw/late/;
use File::Path qw(mkpath);
use AI::Pathfinding::OptimizeMultiple::Scan ();
use PDL (qw( pdl ));
use PDL::IO::FastRaw (qw( readfraw writefraw ));
has start_board => ( isa => 'Int', is => 'ro', required => 1 );
has num_boards => ( isa => 'Int', is => 'ro', required => 1 );
has selected_scans => (
isa => 'ArrayRef',
is => 'ro',
required => 1,
default => sub {
my ($self) = @_;
return $self->_calc_selected_scan_list();
},
lib/AI/Pathfinding/OptimizeMultiple/DataInputObj.pm view on Meta::CPAN
my $HEADER_START_BOARD_IDX = 0;
my $HEADER_NUM_BOARDS = 1;
my $HEADER_ITERATIONS_LIMIT = 2;
sub _get_scans_data_helper
{
my $self = shift;
my $selected_scans = $self->selected_scans();
my $start_board = $self->start_board();
my $scans_data = {};
my $scans_lens_data = {};
my $data_dir = ".data-proc";
my $lens_dir = ".data-len-proc";
mkpath( [ $data_dir, $lens_dir ] );
foreach my $scan (@$selected_scans)
lib/AI/Pathfinding/OptimizeMultiple/DataInputObj.pm view on Meta::CPAN
die "Incorrect file format in scan "
. $scan->{'id'} . "!\n";
}
my $c = pdl( \@array );
writefraw( $c, $dest_path );
}
}
{
my $start_idx = $NUM_NUMBERS_IN_HEADER + ( $start_board - 1 );
my $scan_vec = readfraw($dest_path);
$scans_data->{ $scan->id() } =
$scan_vec->slice( $start_idx . ":"
. ( $start_idx + $self->num_boards() - 1 ) );
}
}
{
my $src = $scan->data_file_path();
my $dest = "$lens_dir/" . $scan->id();
if ( $self->_should_update( $src, $dest ) )
{
my $data_s = _slurp($src);
lib/AI/Pathfinding/OptimizeMultiple/DataInputObj.pm view on Meta::CPAN
),
]
);
writefraw( $c, $dest );
}
{
my $scan_vec = readfraw($dest);
$scans_lens_data->{ $scan->id() } = $scan_vec->slice(
sprintf( "%d:%d,:,*",
( $start_board - 1 ),
( ( $self->num_boards() - 1 ) + ( $start_board - 1 ) ) )
)->xchg( 1, 2 );
}
}
}
return { 'scans' => $scans_data, 'with_lens' => $scans_lens_data };
}
sub _get_scans_data_generic
{
lib/AI/Pathfinding/OptimizeMultiple/DataInputObj.pm view on Meta::CPAN
}
sub _is_scan_suitable
{
my ( $self, $scan ) = @_;
my @stat = stat( $scan->data_file_path() );
return (
scalar(@stat)
&& ( $stat[7] >=
12 + ( $self->num_boards() + $self->start_board() - 1 ) * 4 )
);
}
sub _get_scans_registry_file_path
{
return "scans.txt";
}
sub _get_all_scans_list_from_file
{
lib/AI/Pathfinding/OptimizeMultiple/DataInputObj.pm view on Meta::CPAN
my $self = shift;
my $args = shift;
my $min_board = $args->{'min'} || 1;
my $max_board = $args->{'max'} || 32_000;
my $id = $args->{'id'};
my $cmd_line = $self->_get_scan_cmd_line($args);
open my $from_cmd, "-|", @$cmd_line
or die "Could not start '@$cmd_line'";
open my $fcs_out, ">", "data/$id.fcs.moves.txt";
open my $fc_pro_out, ">", "data/$id.fcpro.moves.txt";
$fcs_out->autoflush(1);
$fc_pro_out->autoflush(1);
while ( my $line = <$from_cmd> )
{
print $line;
chomp($line);
if ( $line =~ m{\A\[\[Num FCS Moves\]\]=(.*)\z}o )
{
lib/AI/Pathfinding/OptimizeMultiple/DataInputObj.pm view on Meta::CPAN
Returns the hash ref mapping scan IDs/names to iteration+lengths PDLs.
=head2 $self->num_boards()
The number of boards.
=head2 $self->selected_scans()
An accessor for the selected scans.
=head2 $self->start_board()
The index of the board to start from.
=head2 $self->time_scan()
Times a new scan.
=head2 $self->get_scan_ids_aref()
Get an array reference of the scan IDs.
=head2 my $idx = $self->lookup_scan_idx_based_on_id($scan_id)