|
|
@ -1,99 +1,99 @@
|
|
|
|
use std::{
|
|
|
|
// use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
// collections::HashMap,
|
|
|
|
hash::{BuildHasherDefault, Hash},
|
|
|
|
// hash::{BuildHasherDefault, Hash},
|
|
|
|
iter::Sum,
|
|
|
|
// iter::Sum,
|
|
|
|
ops::AddAssign,
|
|
|
|
// ops::AddAssign,
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
// use nalgebra::{Point, SVector};
|
|
|
|
// use nalgebra::{Point, SVector};
|
|
|
|
// use petgraph::stable_graph::NodeIndex;
|
|
|
|
// use petgraph::stable_graph::NodeIndex;
|
|
|
|
|
|
|
|
|
|
|
|
// type HashFn = BuildHasherDefault<rustc_hash::FxHasher>;
|
|
|
|
// type HashFn = BuildHasherDefault<rustc_hash::FxHasher>;
|
|
|
|
|
|
|
|
|
|
|
|
use fdg::Field;
|
|
|
|
// use fdg::Field;
|
|
|
|
use nalgebra::Point;
|
|
|
|
// use nalgebra::Point;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
// #[derive(Debug, Clone)]
|
|
|
|
pub struct StressMajorizationConfiguration<F: Field> {
|
|
|
|
// pub struct StressMajorizationConfiguration<F: Field> {
|
|
|
|
pub dt: F,
|
|
|
|
// pub dt: F,
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
use petgraph::{
|
|
|
|
// use petgraph::{
|
|
|
|
algo::{dijkstra, Measure},
|
|
|
|
// algo::{dijkstra, Measure},
|
|
|
|
graph::NodeIndex,
|
|
|
|
// graph::NodeIndex,
|
|
|
|
stable_graph::StableGraph,
|
|
|
|
// stable_graph::StableGraph,
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
use StressMajorizationConfiguration as Config;
|
|
|
|
// use StressMajorizationConfiguration as Config;
|
|
|
|
|
|
|
|
|
|
|
|
impl<F: Field> Default for Config<F> {
|
|
|
|
// impl<F: Field> Default for Config<F> {
|
|
|
|
fn default() -> Self {
|
|
|
|
// fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
// Self {
|
|
|
|
dt: F::from(0.035).unwrap(),
|
|
|
|
// 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>>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// let borrowed_graph: &StableGraph<(N, Point<F, D>), E> = graph;
|
|
|
|
// /// 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(),
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
|
|
self.shortest_path_matrix.extend(
|
|
|
|
// // let borrowed_graph: &StableGraph<(N, Point<F, D>), E> = graph;
|
|
|
|
graph
|
|
|
|
|
|
|
|
.node_indices()
|
|
|
|
|
|
|
|
.map(|idx| (idx, dijkstra(graph as &_, idx, None, |_| F::one()))),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn calc_stress<N: Clone, E: Clone>(
|
|
|
|
// self.shortest_path_matrix.extend(
|
|
|
|
&mut self,
|
|
|
|
|
|
|
|
graph: &mut StableGraph<(N, Point<F, D>), E>,
|
|
|
|
|
|
|
|
) -> F {
|
|
|
|
|
|
|
|
// graph
|
|
|
|
// graph
|
|
|
|
// .node_indices()
|
|
|
|
// .node_indices()
|
|
|
|
// .flat_map(|v| {
|
|
|
|
// .map(|idx| (idx, dijkstra(graph as &_, idx, None, |_| F::one()))),
|
|
|
|
// 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>,
|
|
|
|
// if dist != F::zero() {
|
|
|
|
// ) -> F {
|
|
|
|
// let dij = self.shortest_path_matrix[&v][&w];
|
|
|
|
// // graph
|
|
|
|
|
|
|
|
// // .node_indices()
|
|
|
|
// let sp_diff = self.shortest_path_matrix[&v][&w] - dist;
|
|
|
|
// // .flat_map(|v| {
|
|
|
|
// dij.simd_sqrt().abs() * sp_diff * sp_diff
|
|
|
|
// // graph.node_indices().skip(v.index() + 1).map(move |w| {
|
|
|
|
// } else {
|
|
|
|
// // let dist = nalgebra::distance(
|
|
|
|
// F::zero()
|
|
|
|
// // &graph.node_weight(v).unwrap().1,
|
|
|
|
|
|
|
|
// // &graph.node_weight(w).unwrap().1,
|
|
|
|
|
|
|
|
// // );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 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()
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// .sum()
|
|
|
|
|
|
|
|
F::default()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// impl<const D: usize, N, E> Force<f32, D, N, E> for StressMajorization<D> {
|
|
|
|
// 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>) {
|
|
|
|
// fn apply(&mut self, graph: &mut ForceGraph<f32, D, N, E>) {
|
|
|
|