|
|
@ -8,7 +8,7 @@ pub enum RectangleSearchError { |
|
|
|
Unsatisfiable, |
|
|
|
} |
|
|
|
|
|
|
|
pub fn iterate_improvements(mut layout: &mut HouseLayout, mut rng: &mut StdRng, print_progress: bool) { |
|
|
|
pub fn iterate_improvements(mut layout: &mut HouseLayout, mut rng: &mut StdRng, print_progress: bool, merge_first: bool) -> bool { |
|
|
|
#[derive(Eq, PartialEq)] |
|
|
|
enum LastStep { |
|
|
|
None, |
|
|
@ -16,17 +16,25 @@ pub fn iterate_improvements(mut layout: &mut HouseLayout, mut rng: &mut StdRng, |
|
|
|
MergingPairs, |
|
|
|
} |
|
|
|
|
|
|
|
let mut improved = false; |
|
|
|
|
|
|
|
let mut first_iteration = true; |
|
|
|
let mut last_improved_step = LastStep::None; |
|
|
|
loop { |
|
|
|
if last_improved_step == LastStep::MovingIndividual { break; } |
|
|
|
if print_progress { |
|
|
|
eprintln!("Starting moving individual houses..."); |
|
|
|
} |
|
|
|
if improve_move_individual_houses(&mut layout, &mut rng) { |
|
|
|
last_improved_step = LastStep::MovingIndividual; |
|
|
|
} |
|
|
|
if print_progress { |
|
|
|
eprintln!("Finished moving individual houses..."); |
|
|
|
if merge_first && first_iteration { |
|
|
|
first_iteration = false; |
|
|
|
} else { |
|
|
|
if last_improved_step == LastStep::MovingIndividual { break; } |
|
|
|
if print_progress { |
|
|
|
eprintln!("Starting moving individual houses..."); |
|
|
|
} |
|
|
|
if improve_move_individual_houses(&mut layout, &mut rng) { |
|
|
|
last_improved_step = LastStep::MovingIndividual; |
|
|
|
improved = true; |
|
|
|
} |
|
|
|
if print_progress { |
|
|
|
eprintln!("Finished moving individual houses..."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if last_improved_step == LastStep::MergingPairs { break; } |
|
|
@ -35,18 +43,15 @@ pub fn iterate_improvements(mut layout: &mut HouseLayout, mut rng: &mut StdRng, |
|
|
|
} |
|
|
|
if improve_merge_pairwise(&mut layout, print_progress) { |
|
|
|
last_improved_step = LastStep::MergingPairs; |
|
|
|
improved = true; |
|
|
|
} |
|
|
|
if print_progress { |
|
|
|
eprintln!("Finished pairwise house merge"); |
|
|
|
} |
|
|
|
//eprintln!("Starting pairwise house move...");
|
|
|
|
//if optimization::improve_move_houses_pairwise(&mut layout) {
|
|
|
|
// dump_layout(&layout, &mut best_price, seed);
|
|
|
|
// improved = true;
|
|
|
|
//}
|
|
|
|
//eprintln!("Finished pairwise house move");
|
|
|
|
if last_improved_step == LastStep::None { break; } |
|
|
|
} |
|
|
|
|
|
|
|
improved |
|
|
|
} |
|
|
|
|
|
|
|
fn get_valid_move_rectangle_multiple(layout: &HouseLayout, houses: &Vec<House>) -> Result<Rectangle, RectangleSearchError> { |
|
|
@ -229,6 +234,8 @@ pub fn improve_merge_pairwise(layout: &mut HouseLayout, print_progress: bool) -> |
|
|
|
// We instead go through the houses repeatedly and remember which pairs we have already
|
|
|
|
// tried by hashing their values because they can and do move throughout the layout Vec
|
|
|
|
// as it's being modified.
|
|
|
|
// TODO: This may lead to some pairs still being mergeable thanks to another merge
|
|
|
|
// that happened before.
|
|
|
|
let mut checked = HashSet::new(); |
|
|
|
|
|
|
|
let mut loop_improved = false; |
|
|
@ -277,7 +284,9 @@ pub fn improve_merge_pairwise(layout: &mut HouseLayout, print_progress: bool) -> |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Err(RectangleSearchError::Useless) => eprintln!("Found useless pair of houses, not solving!"), |
|
|
|
Err(RectangleSearchError::Useless) => { |
|
|
|
//eprintln!("Found useless pair of houses, not solving!")
|
|
|
|
}, |
|
|
|
Err(RectangleSearchError::Unsatisfiable) => {} |
|
|
|
} |
|
|
|
} |
|
|
|