further refinement. upper bound for movement

This commit is contained in:
Niko Abeler 2022-11-19 19:55:43 +01:00
parent a2244ed58c
commit df7db9b27d
2 changed files with 24 additions and 13 deletions

View File

@ -63,11 +63,11 @@ fn read_graph(file_name: &str) -> (usize, EdgeMatrix) {
}
fn main() -> std::io::Result<()> {
const ITER: usize = 50;
const ITER: usize = 600;
const THREADS: usize = 8;
// let edges = connection_matrix(size);
let (size, edges): (usize, EdgeMatrix) = read_graph("../graph.bin");
let (size, edges): (usize, EdgeMatrix) = read_graph("../debug_graph.bin");
println!("Size: {}", size);
let mut nodes = nodes_list(size);
let mut nodes_next = nodes_list(size);

View File

@ -41,8 +41,12 @@ impl MyModel {
let node = nodes[i_node].read().unwrap();
let edges = self.edges.read().unwrap();
let mut node_x = node.x;
let mut node_y = node.y;
let node_x = node.x;
let node_y = node.y;
let mut sum_x = 0.0;
let mut sum_y = 0.0;
for o in 0..self.size {
if o == i_node {
continue;
@ -64,23 +68,30 @@ impl MyModel {
let edge = edges[i_node][o].weight;
if edge == 0.0 {
let f_rep = (self.c / (dist).powi(2)).min(self.c);
let f_rep = dist.powi(2).recip().min(self.opt_dist);
let f_rep_x = f_rep * unit_x;
let f_rep_y = f_rep * unit_y;
node_x -= f_rep_x;
node_y -= f_rep_y;
sum_x -= f_rep_x;
sum_y -= f_rep_y;
} else {
let f_spring = self.c * 0.5 * (dist - self.opt_dist) / self.ranks[i_node];
let f_spring = 0.5 * (dist - self.opt_dist);
let f_spring_x = f_spring * unit_x;
let f_spring_y = f_spring * unit_y;
node_x += f_spring_x;
node_y += f_spring_y;
sum_x += f_spring_x;
sum_y += f_spring_y;
}
}
// limit the movement
// TODO: find a good upper bound
let sum_l = (sum_x * sum_x + sum_y * sum_y).sqrt().max(1e-6).recip() * self.c;
let sum_x = sum_x * sum_l;
let sum_y = sum_y * sum_l;
Node {
x: node_x,
y: node_y,
x: node_x + sum_x,
y: node_y + sum_y,
}
}
}