Chorus

 view release on metacpan or  search on metacpan

lib/Chorus/Expert.pm  view on Meta::CPAN

  my $ok = $xprt->process($something); # $something available as $agent->BOARD->INPUT

The main loop iterates over all registered agents in order, calling C<loop()>
on each one, until C<BOARD->{SOLVED}> or C<BOARD->{FAILED}> is set.  It respects
C<_REPLAY> and C<_REPLAY_ALL> signals from the agents.

An agent tagged with C<_LOCK_UNTIL_STABLE> is skipped when any earlier agent in
the current iteration has already succeeded (C<_SUCCES> is true).  This allows
priority-based sequencing without explicit coupling.

If C<_MAX_ITER> full iterations complete without termination, a warning is emitted
and C<process()> returns C<undef>.

Returns C<1> if C<SOLVED>, C<undef> if C<FAILED> or if C<_MAX_ITER> is exceeded.

=head2 _LOCK_UNTIL_STABLE

An optional flag set directly on an agent frame:

  $agent->{_LOCK_UNTIL_STABLE} = 'Y';

lib/Chorus/Expert.pm  view on Meta::CPAN


sub process {
  my ($this, $input) = @_;
  my $board   = $this->{_board};
  my $agents  = $this->{_agents};
  $board->set('INPUT', $input);
  my $max_iter = $this->{_MAX_ITER} // DEFAULT_MAX_ITER;
  my $iter = 0;
  do {
       if (++$iter > $max_iter) {
           warn "Chorus::Expert - process() reached max iterations ($max_iter) without SOLVED or FAILED\n";
           return;
       }
       my @processed = ();
       for my $agent (@$agents) {

          if ($agent->_LOCK_UNTIL_STABLE ) {
             print STDERR "Chorus::Expert - Agent $agent->{_IDENT} is tagged with LOCK_UNTIL_STABLE\n" if $this->{_DEBUG};
             last if grep { $_->_SUCCES } @processed;
             print STDERR "Chorus::Expert - None of agents [" . join (',', map { $_->{_IDENT} || 'NO_NAME' } @processed) . "] have succeeded\n" if $this->{_DEBUG};
          }

lib/Chorus/Expert.pm  view on Meta::CPAN


=head1 BUGS

B<C<new()> ignores its arguments.>  Parameters passed to C<Chorus::Expert->new()>
(including C<_MAX_ITER>) are silently discarded.  Always set C<_MAX_ITER> by
direct assignment immediately after construction:

  my $xprt = Chorus::Expert->new();
  $xprt->{_MAX_ITER} = 50_000;   # mandatory for long pipelines

The default is 10,000 iterations.  For a pipeline of N frames × M total rules,
a safe heuristic is C<N × M × safety_margin> (typically ×10).

Please report other bugs via the CPAN request tracker:
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Chorus>

=head1 SUPPORT

  perldoc Chorus::Expert

=over 4



( run in 1.267 second using v1.01-cache-2.11-cpan-4ab04211f4c )