Commit | Line | Data |
8c16d3c9 |
1 | package DX::SearchProcess; |
2 | |
3 | use DX::SearchState; |
4 | use DX::Class; |
5 | |
6 | has current_search_state => ( |
7 | is => 'ro', isa => SearchState, required => 1, |
8 | handles => [ qw( |
1c02730b |
9 | current_hypothesis next_step propositions |
8c16d3c9 |
10 | ) ], |
11 | ); |
12 | |
13 | sub new_for { |
14 | my ($class, $hyp, $props) = @_; |
15 | $class->new( |
8cc971ec |
16 | current_search_state => DX::SearchState->new_for($hyp, $props), |
8c16d3c9 |
17 | ); |
18 | } |
19 | |
20 | sub with_one_step { |
21 | my ($self) = @_; |
22 | my $new_ss = $self->current_search_state->with_one_step; |
23 | return undef unless $new_ss; |
24 | return $self->but(current_search_state => $new_ss); |
25 | } |
26 | |
27 | sub find_solution { |
28 | my ($self) = @_; |
29 | my $state = $self->current_search_state; |
282b1d76 |
30 | while ($state and (not $state->is_solution_state)) { |
8c16d3c9 |
31 | $state = $state->with_one_step; |
32 | } |
33 | return undef unless $state; |
8c16d3c9 |
34 | return $self->but(current_search_state => $state); |
35 | } |
36 | |
8c16d3c9 |
37 | sub find_next_solution { |
38 | my ($self) = @_; |
ae6f4d03 |
39 | my $state = $self->current_search_state->with_one_step; |
40 | return $self->but(current_search_state => $state)->find_solution; |
8c16d3c9 |
41 | } |
42 | |
43 | 1; |