mirror of
https://github.com/aziis98/asd-2024.git
synced 2026-10-06 22:55:18 +00:00
fix: added allow dead_code
This commit is contained in:
@@ -1,99 +1,99 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
hash::{BuildHasherDefault, Hash},
|
||||
iter::Sum,
|
||||
ops::AddAssign,
|
||||
};
|
||||
// use std::{
|
||||
// collections::HashMap,
|
||||
// hash::{BuildHasherDefault, Hash},
|
||||
// iter::Sum,
|
||||
// ops::AddAssign,
|
||||
// };
|
||||
|
||||
// use nalgebra::{Point, SVector};
|
||||
// use petgraph::stable_graph::NodeIndex;
|
||||
|
||||
// type HashFn = BuildHasherDefault<rustc_hash::FxHasher>;
|
||||
|
||||
use fdg::Field;
|
||||
use nalgebra::Point;
|
||||
// use fdg::Field;
|
||||
// use nalgebra::Point;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StressMajorizationConfiguration<F: Field> {
|
||||
pub dt: F,
|
||||
}
|
||||
// #[derive(Debug, Clone)]
|
||||
// pub struct StressMajorizationConfiguration<F: Field> {
|
||||
// pub dt: F,
|
||||
// }
|
||||
|
||||
use petgraph::{
|
||||
algo::{dijkstra, Measure},
|
||||
graph::NodeIndex,
|
||||
stable_graph::StableGraph,
|
||||
};
|
||||
use StressMajorizationConfiguration as Config;
|
||||
// use petgraph::{
|
||||
// algo::{dijkstra, Measure},
|
||||
// graph::NodeIndex,
|
||||
// stable_graph::StableGraph,
|
||||
// };
|
||||
// use StressMajorizationConfiguration as Config;
|
||||
|
||||
impl<F: Field> Default for Config<F> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
dt: F::from(0.035).unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl<F: Field> Default for Config<F> {
|
||||
// fn default() -> Self {
|
||||
// Self {
|
||||
// dt: F::from(0.035).unwrap(),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/// A basic implementation
|
||||
#[derive(Debug)]
|
||||
pub struct StressMajorization<F: Field, const D: usize> {
|
||||
pub conf: Config<F>,
|
||||
pub shortest_path_matrix: HashMap<NodeIndex, HashMap<NodeIndex, F>>,
|
||||
}
|
||||
// /// A basic implementation
|
||||
// #[derive(Debug)]
|
||||
// pub struct StressMajorization<F: Field, const D: usize> {
|
||||
// pub conf: Config<F>,
|
||||
// pub shortest_path_matrix: HashMap<NodeIndex, HashMap<NodeIndex, F>>,
|
||||
// }
|
||||
|
||||
impl<F: Field + Measure + Sum, const D: usize> StressMajorization<F, D> {
|
||||
pub fn new(conf: Config<F>) -> Self {
|
||||
Self {
|
||||
conf,
|
||||
shortest_path_matrix: HashMap::new(),
|
||||
}
|
||||
}
|
||||
// impl<F: Field + Measure + Sum, const D: usize> StressMajorization<F, D> {
|
||||
// pub fn new(conf: Config<F>) -> Self {
|
||||
// Self {
|
||||
// conf,
|
||||
// shortest_path_matrix: HashMap::new(),
|
||||
// }
|
||||
// }
|
||||
|
||||
fn apply<N: Clone, E: Clone>(&mut self, graph: &mut StableGraph<(N, Point<F, D>), E>) {
|
||||
// if self.shortest_path_matrix.is_empty() {
|
||||
// self.shortest_path_matrix = graph
|
||||
// .node_indices()
|
||||
// .map(|idx| {
|
||||
// (idx, )
|
||||
// })
|
||||
// .collect();
|
||||
// }
|
||||
// fn apply<N: Clone, E: Clone>(&mut self, graph: &mut StableGraph<(N, Point<F, D>), E>) {
|
||||
// // if self.shortest_path_matrix.is_empty() {
|
||||
// // self.shortest_path_matrix = graph
|
||||
// // .node_indices()
|
||||
// // .map(|idx| {
|
||||
// // (idx, )
|
||||
// // })
|
||||
// // .collect();
|
||||
// // }
|
||||
|
||||
// let borrowed_graph: &StableGraph<(N, Point<F, D>), E> = graph;
|
||||
// // let borrowed_graph: &StableGraph<(N, Point<F, D>), E> = graph;
|
||||
|
||||
self.shortest_path_matrix.extend(
|
||||
graph
|
||||
.node_indices()
|
||||
.map(|idx| (idx, dijkstra(graph as &_, idx, None, |_| F::one()))),
|
||||
)
|
||||
}
|
||||
// self.shortest_path_matrix.extend(
|
||||
// graph
|
||||
// .node_indices()
|
||||
// .map(|idx| (idx, dijkstra(graph as &_, idx, None, |_| F::one()))),
|
||||
// )
|
||||
// }
|
||||
|
||||
fn calc_stress<N: Clone, E: Clone>(
|
||||
&mut self,
|
||||
graph: &mut StableGraph<(N, Point<F, D>), E>,
|
||||
) -> F {
|
||||
// graph
|
||||
// .node_indices()
|
||||
// .flat_map(|v| {
|
||||
// graph.node_indices().skip(v.index() + 1).map(move |w| {
|
||||
// let dist = nalgebra::distance(
|
||||
// &graph.node_weight(v).unwrap().1,
|
||||
// &graph.node_weight(w).unwrap().1,
|
||||
// );
|
||||
// fn calc_stress<N: Clone, E: Clone>(
|
||||
// &mut self,
|
||||
// graph: &mut StableGraph<(N, Point<F, D>), E>,
|
||||
// ) -> F {
|
||||
// // graph
|
||||
// // .node_indices()
|
||||
// // .flat_map(|v| {
|
||||
// // graph.node_indices().skip(v.index() + 1).map(move |w| {
|
||||
// // let dist = nalgebra::distance(
|
||||
// // &graph.node_weight(v).unwrap().1,
|
||||
// // &graph.node_weight(w).unwrap().1,
|
||||
// // );
|
||||
|
||||
// if dist != F::zero() {
|
||||
// let dij = self.shortest_path_matrix[&v][&w];
|
||||
// // if dist != F::zero() {
|
||||
// // let dij = self.shortest_path_matrix[&v][&w];
|
||||
|
||||
// let sp_diff = self.shortest_path_matrix[&v][&w] - dist;
|
||||
// dij.simd_sqrt().abs() * sp_diff * sp_diff
|
||||
// } else {
|
||||
// F::zero()
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// .sum()
|
||||
F::default()
|
||||
}
|
||||
}
|
||||
// // let sp_diff = self.shortest_path_matrix[&v][&w] - dist;
|
||||
// // dij.simd_sqrt().abs() * sp_diff * sp_diff
|
||||
// // } else {
|
||||
// // F::zero()
|
||||
// // }
|
||||
// // })
|
||||
// // })
|
||||
// // .sum()
|
||||
// F::default()
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl<const D: usize, N, E> Force<f32, D, N, E> for StressMajorization<D> {
|
||||
// fn apply(&mut self, graph: &mut ForceGraph<f32, D, N, E>) {
|
||||
|
||||
Reference in New Issue
Block a user