solverforge_solver/heuristic/selector/move_selector/
iter.rs1pub struct MoveSelectorIter<S, M, C>
2where
3 S: PlanningSolution,
4 M: Move<S>,
5 C: MoveCursor<S, M>,
6{
7 cursor: C,
8 _phantom: PhantomData<(fn() -> S, fn() -> M)>,
9}
10
11impl<S, M, C> MoveSelectorIter<S, M, C>
12where
13 S: PlanningSolution,
14 M: Move<S>,
15 C: MoveCursor<S, M>,
16{
17 fn new(cursor: C) -> Self {
18 Self {
19 cursor,
20 _phantom: PhantomData,
21 }
22 }
23}
24
25impl<S, M, C> Iterator for MoveSelectorIter<S, M, C>
26where
27 S: PlanningSolution,
28 M: Move<S>,
29 C: MoveCursor<S, M>,
30{
31 type Item = M;
32
33 fn next(&mut self) -> Option<Self::Item> {
34 let id = self.cursor.next_candidate()?;
35 Some(self.cursor.take_candidate(id))
36 }
37}
38
39pub trait MoveSelector<S: PlanningSolution, M: Move<S>>: Send + Debug {
42 type Cursor<'a>: MoveCursor<S, M> + 'a
43 where
44 Self: 'a;
45
46 fn open_cursor<'a, D: Director<S>>(&'a self, score_director: &D) -> Self::Cursor<'a>;
47
48 fn iter_moves<'a, D: Director<S>>(
49 &'a self,
50 score_director: &D,
51 ) -> MoveSelectorIter<S, M, Self::Cursor<'a>> {
52 MoveSelectorIter::new(self.open_cursor(score_director))
53 }
54
55 fn size<D: Director<S>>(&self, score_director: &D) -> usize;
56
57 fn append_moves<D: Director<S>>(&self, score_director: &D, arena: &mut MoveArena<M>) {
58 let mut cursor = self.open_cursor(score_director);
59 for id in collect_cursor_indices::<S, M, _>(&mut cursor) {
60 arena.push(cursor.take_candidate(id));
61 }
62 }
63
64 fn is_never_ending(&self) -> bool {
65 false
66 }
67}