1 package DX::SearchState;
3 use Types::Standard qw(Maybe);
4 use DX::Step::Backtrack;
5 use DX::Step::InvokeNextPredicate;
8 has current_hypothesis => (is => 'ro', isa => Hypothesis, required => 1);
10 has next_step => (is => 'ro', isa => Maybe[Step]);
12 has propositions => (is => 'ro', isa => PropositionSequence, required => 1);
14 has alternatives => (is => 'ro', isa => AlternativeList, required => 1);
16 has is_solution_state => (is => 'ro', required => 1);
18 has on_exhaustion_step => (is => 'ro', required => 1);
20 sub next_proposition {
21 my ($self, $hyp) = @_;
22 $hyp ||= $self->current_hypothesis;
23 $self->propositions->members->[
24 $hyp->resolved_propositions->resolved_count
29 my ($class, $hyp, $props) = @_;
31 current_hypothesis => $hyp,
33 propositions => $props,
36 next_step => DX::Step::InvokeNextPredicate->new(
37 proposition => $props->members->[0],
39 is_solution_state => 0,
41 : ( is_solution_state => 1 )
43 on_exhaustion_step => undef,
49 return undef unless my $step = $self->next_step;
50 return $step->apply_to($self);
55 my ($first_alt, @rest_alt) = @{$self->alternatives};
56 return undef unless $first_alt;
57 trace 'search.backtrack.forced' => $first_alt->[0];
59 next_step => DX::Step::Backtrack->new,