From b3cf77661836262e825a8f6411a3e1228cc35c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Sejkora?= Date: Mon, 11 Jan 2021 05:36:11 +0100 Subject: [PATCH] Do not redo steps that would not improve the solution --- src/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2dfd0c7..d857178 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,18 +36,25 @@ fn main() { MIN_WEIGHT_SCORE, MAX_WEIGHT_SCORE, DB_CHOICE_PROBABILITY); population::populate_using_db(&mut layout, &mut rng, &db, MIN_WEIGHT_SCORE, MAX_WEIGHT_SCORE, DB_CHOICE_PROBABILITY); eprintln!("Finished random init, price: {}, houses: {}", layout.price(), layout.houses().len()); + let mut last_improved_step = -1; loop { - let mut improved = false; + if last_improved_step == 1 { + break; + } eprintln!("Starting moving individual houses..."); if optimization::improve_move_individual_houses(&mut layout, &mut rng) { dump_layout(&layout, &mut best_price, seed); - improved = true; + last_improved_step = 1; } eprintln!("Finished moving individual houses..."); + + if last_improved_step == 2 { + break; + } eprintln!("Starting pairwise house merge..."); if optimization::improve_merge_pairwise(&mut layout) { dump_layout(&layout, &mut best_price, seed); - improved = true; + last_improved_step = 2; } eprintln!("Finished pairwise house merge"); //eprintln!("Starting pairwise house move..."); @@ -56,9 +63,6 @@ fn main() { // improved = true; //} //eprintln!("Finished pairwise house move"); - if !improved { - break; - } } db.add_layout(&layout.houses(), true).expect("Failed to insert into DB"); }