From 47c3052fbededb8006bcf86a073c4228013d110d Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Sun, 28 Apr 2019 15:23:06 +0200 Subject: [PATCH] Add another random optimization --- src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.rs b/src/main.rs index be021cb..16f80ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -228,6 +228,26 @@ fn optimize(iters: usize, best_all: &mut f32, best_width: &mut f32, tris: &[Tria angles = start_angles.clone(); flips = start_flips.clone(); } + angles = best_angles.clone(); + for idx in 0..tris.len() { + for _ in 0..999 { + let angle = rng.gen_range(-0.1, 0.1); + angles[idx] += angle; + let new = construct_world(tris, &angles, &best_flips); + if new.width < *best_width { + *best_all = new.width; + //eprint!("\r[{}O{}o{}] at {:.3}", save_counter, iteration, i, new.width); + //display::save_world(&format!("{}{}_{}_{}.svg", save_prefix, save_counter, iteration, i), &new); + //iters = 99999; + best = new; + *best_width = best.width; + found_better = true; + *best_angles = angles.clone(); + } else { + angles[idx] -= angle; + } + } + } iteration += 1; } best