1 package DX::SearchState;
3 use Types::Standard qw(Maybe);
4 use DX::Step::Backtrack;
5 use DX::Step::InvokeNextPredicate;
6 use DX::Step::MarkAsSolution;
9 has current_hypothesis => (is => 'ro', isa => Hypothesis, required => 1);
11 has next_step => (is => 'ro', isa => Maybe[Step]);
13 has propositions => (is => 'ro', isa => PropositionSequence, required => 1);
15 has alternatives => (is => 'ro', isa => AlternativeList, required => 1);
17 has is_solution_state => (is => 'ro', required => 1);
19 has on_exhaustion_step => (is => 'ro', required => 1);
21 has on_solution_step => (is => 'ro', required => 1);
23 sub next_proposition {
24 my ($self, $hyp) = @_;
25 $hyp ||= $self->current_hypothesis;
26 $self->propositions->members->[
27 $hyp->resolved_propositions->resolved_count
32 my ($class, $hyp, $props) = @_;
34 current_hypothesis => $hyp,
36 propositions => $props,
39 next_step => DX::Step::InvokeNextPredicate->new(
40 proposition => $props->members->[0],
42 is_solution_state => 0,
44 : ( is_solution_state => 1 )
46 on_exhaustion_step => undef,
47 on_solution_step => DX::Step::MarkAsSolution->new,
53 return undef unless my $step = $self->next_step;
54 return $step->apply_to($self);
59 my ($first_alt, @rest_alt) = @{$self->alternatives};
60 return undef unless $first_alt;
61 trace 'search.backtrack.forced' => $first_alt->[0];
63 next_step => DX::Step::Backtrack->new,