57 lines
1.3 KiB
Rust
57 lines
1.3 KiB
Rust
use crate::common::TreeNode;
|
|
use crate::route::{Router, SearchState};
|
|
use fnv::FnvHashMap;
|
|
|
|
trait SearchAlgoImpl<State = (), Weight: Ord = ()> {
|
|
fn get_weight(&mut self, systems: &TreeNode, router: &Router) -> Option<Weight>;
|
|
|
|
fn get_neighbors(
|
|
&mut self,
|
|
system: &TreeNode,
|
|
router: &Router,
|
|
range: f32,
|
|
) -> Vec<(Weight, TreeNode)> {
|
|
let mut ret = vec![];
|
|
for nb in router.neighbours(system, range) {
|
|
if let Some(w) = self.get_weight(nb, router) {
|
|
ret.push((w, *nb));
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
struct SearchAlgo<'a> {
|
|
algo: Box<dyn SearchAlgoImpl>,
|
|
prev: FnvHashMap<u32, u32>,
|
|
state: Option<SearchState>,
|
|
router: &'a Router,
|
|
}
|
|
|
|
struct BFS(usize);
|
|
|
|
impl SearchAlgoImpl for BFS {
|
|
fn get_weight(&mut self, _system: &TreeNode, _router: &Router) -> Option<()> {
|
|
return Some(());
|
|
}
|
|
}
|
|
|
|
impl<'a> SearchAlgo<'a> {
|
|
fn new(router: &'a Router, algo: Box<dyn SearchAlgoImpl>) -> Self {
|
|
Self {
|
|
algo,
|
|
prev: FnvHashMap::default(),
|
|
state: None,
|
|
router,
|
|
}
|
|
}
|
|
|
|
fn test(&mut self) {
|
|
// self.algo.get_neighbors
|
|
}
|
|
}
|
|
|
|
/*
|
|
a = 1 - acos(dot(u/Length(u),v/Length(v)))/PI
|
|
*/
|