swarm_engine_core/exploration/selection/
fifo.rs1use std::fmt::Debug;
6
7use super::SelectionLogic;
8use crate::exploration::map::{ExplorationMap, GraphMap, MapNodeId, MapState};
9use crate::exploration::mutation::ActionExtractor;
10use crate::learn::LearnedProvider;
11use crate::online_stats::SwarmStats;
12
13#[derive(Debug, Clone, Default)]
18pub struct Fifo;
19
20impl Fifo {
21 pub fn new() -> Self {
22 Self
23 }
24}
25
26impl<N, E, S> SelectionLogic<N, E, S> for Fifo
27where
28 N: Debug + Clone + ActionExtractor,
29 E: Debug + Clone,
30 S: MapState,
31{
32 fn next(
33 &self,
34 map: &GraphMap<N, E, S>,
35 _stats: &SwarmStats,
36 _provider: &dyn LearnedProvider,
37 ) -> Option<MapNodeId> {
38 map.frontiers().first().copied()
39 }
40
41 fn select(
42 &self,
43 map: &GraphMap<N, E, S>,
44 count: usize,
45 _stats: &SwarmStats,
46 _provider: &dyn LearnedProvider,
47 ) -> Vec<MapNodeId> {
48 map.frontiers().into_iter().take(count).collect()
49 }
50
51 fn score(
52 &self,
53 _action: &str,
54 _target: Option<&str>,
55 _stats: &SwarmStats,
56 _provider: &dyn LearnedProvider,
57 ) -> f64 {
58 0.0 }
60
61 fn name(&self) -> &str {
62 "FIFO"
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69 use crate::exploration::map::MapNodeState;
70 use crate::exploration::mutation::ActionNodeData;
71 use crate::learn::NullProvider;
72
73 #[test]
74 fn test_fifo_selection() {
75 let fifo = Fifo::new();
76 let mut map: GraphMap<ActionNodeData, String, MapNodeState> = GraphMap::new();
77 let stats = SwarmStats::new();
78 let provider = NullProvider;
79
80 let root = map.create_root(ActionNodeData::new("root"), MapNodeState::Open);
82
83 let selected = fifo.select(&map, 1, &stats, &provider);
85 assert_eq!(selected.len(), 1);
86 assert_eq!(selected[0], root);
87 }
88
89 #[test]
90 fn test_fifo_score_always_zero() {
91 use crate::exploration::map::MapNodeState;
92 use crate::exploration::mutation::ActionNodeData;
93
94 let fifo = Fifo::new();
95 let stats = SwarmStats::new();
96 let provider = NullProvider;
97
98 let score = <Fifo as SelectionLogic<ActionNodeData, String, MapNodeState>>::score(
100 &fifo, "any", None, &stats, &provider,
101 );
102 assert_eq!(score, 0.0);
103 }
104}