File Coverage

blib/lib/AI/Pathfinding/OptimizeMultiple/IterState.pm
Criterion Covered Total %
statement 61 61 100.0
branch n/a
condition n/a
subroutine 18 18 100.0
pod 7 7 100.0
total 86 86 100.0


line stmt bran cond sub pod time code
1             $AI::Pathfinding::OptimizeMultiple::IterState::VERSION = '0.0.17';
2             use strict;
3 2     2   17 use warnings;
  2         4  
  2         86  
4 2     2   12  
  2         7  
  2         50  
5             use 5.012;
6 2     2   53  
  2         9  
7             use MooX qw/late/;
8 2     2   441  
  2         11338  
  2         14  
9             use PDL ();
10 2     2   210208  
  2         302  
  2         54  
11             use vars (qw(@fields));
12 2     2   12  
  2         5  
  2         216  
13             has _main => ( is => 'rw' );
14             has _num_solved =>
15             ( isa => 'Int', is => 'ro', init_arg => 'num_solved', required => 1 );
16             has _quota => ( isa => 'Int', is => 'ro', init_arg => 'quota', required => 1 );
17             has _scan_idx =>
18             ( isa => 'Int', is => 'ro', init_arg => 'scan_idx', required => 1 );
19              
20             use Exception::Class ('AI::Pathfinding::OptimizeMultiple::Error::OutOfQuotas');
21 2     2   1492  
  2         18866  
  2         16  
22             {
23             my $self = shift;
24             my $main_obj = shift;
25 8     8 1 15  
26 8         13 $self->_main($main_obj);
27              
28 8         28 return;
29             }
30 8         18  
31             {
32             my $self = shift;
33             return $self->_main->_calc_chosen_scan( $self->_scan_idx, $self->_quota );
34             }
35 8     8 1 64  
36 8         41 {
37             my $self = shift;
38             $self->_main(undef);
39             }
40              
41 8     8 1 18 {
42 8         182 my $self = shift;
43              
44             my $scans_data = $self->_main()->_scans_data();
45              
46             my @dims = $scans_data->dims();
47 16     16 1 23  
48             return $scans_data->slice(
49 16         281 join( ",", ":", $self->_scan_idx(), ( ("(0)") x ( @dims - 2 ) ) ) );
50             }
51 16         120  
52             {
53 16         258 my $state = shift;
54              
55             # $r is the result of this scan.
56             my $r = $state->idx_slice();
57              
58             # Add the total iterations for all the states that were solved by
59 8     8 1 14 # this scan.
60             $state->_main()
61             ->_add_to_total_iters(
62 8         25 PDL::sum( ( ( $r <= $state->_quota() ) & ( $r > 0 ) ) * $r ) );
63              
64             # Find all the states that weren't solved.
65             my $indexes = PDL::which( ( $r > $state->_quota() ) | ( $r < 0 ) );
66 8         268  
67             # Add the iterations for all the states that have not been solved
68             # yet.
69             $state->_main()
70             ->_add_to_total_iters( $indexes->nelem() * $state->_quota() );
71 8         95  
72             # Keep only the states that have not been solved yet.
73             $state->_main()
74             ->_scans_data(
75 8         1640 $state->_main()->_scans_data()->dice( $indexes, "X" )->copy() );
76             }
77              
78             {
79 8         194 my $state = shift;
80             my $r = $state->idx_slice()->copy();
81              
82             # $r cannot be 0, because the ones that were 0, were already solved
83             # in $state->update_total_iters().
84             my $idx_slice = $state->idx_slice();
85             $idx_slice .=
86 4     4 1 9 ( ( $r > 0 ) * ( $r - $state->_quota() ) ) + ( ( $r < 0 ) * ($r) );
87 4         13 }
88              
89             {
90             my $state = shift;
91 4         189  
92 4         91 $state->_main()->_selected_scans()->[ $state->_scan_idx() ]->mark_as_used();
93              
94             return;
95             }
96              
97             {
98 8     8   15 my $state = shift;
99              
100 8         45 push @{ $state->_main()->chosen_scans() }, $state->get_chosen_struct();
101              
102 8         199 return;
103             }
104              
105             {
106             my $state = shift;
107 8     8   16  
108             $state->_main()->_add_to_total_boards_solved( $state->_num_solved() );
109 8         14  
  8         157  
110             return;
111 8         2485 }
112              
113             {
114             my $state = shift;
115              
116 8     8   18 $state->_main()->_trace(
117             {
118 8         40 'iters_quota' => $state->_quota(),
119             'selected_scan_idx' => $state->_scan_idx(),
120 8         15 'total_boards_solved' => $state->_main()->_total_boards_solved(),
121             }
122             );
123              
124             return;
125 8     8   13 }
126              
127 8         148 {
128             my $state = shift;
129              
130             $state->_add_chosen();
131             $state->_mark_as_used();
132             $state->_update_total_boards_solved();
133             $state->_trace_wrapper();
134              
135 8         23 return;
136             }
137              
138             1;
139              
140 8     8 1 15  
141             =pod
142 8         25  
143 8         28 =encoding UTF-8
144 8         25  
145 8         22 =head1 NAME
146              
147 8         16 AI::Pathfinding::OptimizeMultiple::IterState - iteration state object.
148              
149             =head1 VERSION
150              
151             version 0.0.17
152              
153             =head1 SUBROUTINES/METHODS
154              
155             =head2 $self->attach_to()
156              
157             Internal use.
158              
159             =head2 $self->get_chosen_struct()
160              
161             Internal use.
162              
163             =head2 $self->detach()
164              
165             Internal use.
166              
167             =head2 $self->idx_slice()
168              
169             Internal use.
170              
171             =head2 $self->update_total_iters()
172              
173             Internal use.
174              
175             =head2 $self->update_idx_slice()
176              
177             Internal use.
178              
179             =head2 $self->register_params()
180              
181             Internal use.
182              
183             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
184              
185             =head1 SUPPORT
186              
187             =head2 Websites
188              
189             The following websites have more information about this module, and may be of help to you. As always,
190             in addition to those websites please use your favorite search engine to discover more resources.
191              
192             =over 4
193              
194             =item *
195              
196             MetaCPAN
197              
198             A modern, open-source CPAN search engine, useful to view POD in HTML format.
199              
200             L<https://metacpan.org/release/AI-Pathfinding-OptimizeMultiple>
201              
202             =item *
203              
204             RT: CPAN's Bug Tracker
205              
206             The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
207              
208             L<https://rt.cpan.org/Public/Dist/Display.html?Name=AI-Pathfinding-OptimizeMultiple>
209              
210             =item *
211              
212             CPANTS
213              
214             The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
215              
216             L<http://cpants.cpanauthors.org/dist/AI-Pathfinding-OptimizeMultiple>
217              
218             =item *
219              
220             CPAN Testers
221              
222             The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
223              
224             L<http://www.cpantesters.org/distro/A/AI-Pathfinding-OptimizeMultiple>
225              
226             =item *
227              
228             CPAN Testers Matrix
229              
230             The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
231              
232             L<http://matrix.cpantesters.org/?dist=AI-Pathfinding-OptimizeMultiple>
233              
234             =item *
235              
236             CPAN Testers Dependencies
237              
238             The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
239              
240             L<http://deps.cpantesters.org/?module=AI::Pathfinding::OptimizeMultiple>
241              
242             =back
243              
244             =head2 Bugs / Feature Requests
245              
246             Please report any bugs or feature requests by email to C<bug-ai-pathfinding-optimizemultiple at rt.cpan.org>, or through
247             the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=AI-Pathfinding-OptimizeMultiple>. You will be automatically notified of any
248             progress on the request by the system.
249              
250             =head2 Source Code
251              
252             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
253             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
254             from your repository :)
255              
256             L<http://github.com/shlomif/fc-solve>
257              
258             git clone ssh://git@github.com/shlomif/fc-solve.git
259              
260             =head1 AUTHOR
261              
262             Shlomi Fish <shlomif@cpan.org>
263              
264             =head1 BUGS
265              
266             Please report any bugs or feature requests on the bugtracker website
267             L<https://github.com/shlomif/fc-solve/issues>
268              
269             When submitting a bug or request, please include a test-file or a
270             patch to an existing test-file that illustrates the bug or desired
271             feature.
272              
273             =head1 COPYRIGHT AND LICENSE
274              
275             This software is Copyright (c) 2012 by Shlomi Fish.
276              
277             This is free software, licensed under:
278              
279             The MIT (X11) License
280              
281             =cut