|
|
@ -50,45 +50,47 @@ fn choose_layouts<TDB: LayoutDB>(db: &TDB, city: &City, top_layout_count: usize) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn iterate_combines<TDB: LayoutDB>(mut db: &mut TDB, top_layout_count: usize, city: &City, mut cache: &mut CompatibilityCache, print_progress: bool) { |
|
|
|
#[derive(Eq, PartialEq)] |
|
|
|
enum LastStep { |
|
|
|
None, |
|
|
|
Vertical, |
|
|
|
Horizontal, |
|
|
|
} |
|
|
|
let mut no_improvements_in_a_row = 0; |
|
|
|
if print_progress { eprintln!("Building a transposed city..."); } |
|
|
|
let transposed_city = transpose_city(&city); |
|
|
|
if print_progress { eprintln!("Finished building a transposed city"); } |
|
|
|
|
|
|
|
if print_progress { eprintln!("Building right distances..."); } |
|
|
|
let right_distances = city::build_distances_right(&city); |
|
|
|
if print_progress { eprintln!("Building right distances (transposed)..."); } |
|
|
|
let right_distances_transposed = city::build_distances_right(&city); |
|
|
|
if print_progress { eprintln!("Finished building right distances"); } |
|
|
|
|
|
|
|
let mut last_improve_step = LastStep::None; |
|
|
|
loop { |
|
|
|
if last_improve_step == LastStep::Vertical { break; } |
|
|
|
if no_improvements_in_a_row == 2 { break; } |
|
|
|
if print_progress { eprintln!("Starting to combine {} top houses DB; vertical cuts", top_layout_count); } |
|
|
|
|
|
|
|
{ |
|
|
|
let chosen_layouts = choose_layouts(db, &city, top_layout_count); |
|
|
|
if print_progress { eprintln!("Building right distances..."); } |
|
|
|
let right_distances = city::build_distances_right(&city); |
|
|
|
if print_progress { eprintln!("Finished building right distances"); } |
|
|
|
if create_new_best_combination(&city, &chosen_layouts, &chosen_layouts, db, &mut cache, &right_distances, false, print_progress) { |
|
|
|
last_improve_step = LastStep::Vertical; |
|
|
|
no_improvements_in_a_row = 0; |
|
|
|
} else { |
|
|
|
no_improvements_in_a_row += 1; |
|
|
|
} |
|
|
|
if print_progress { eprintln!("Finished vertical cuts, improvement: {}", no_improvements_in_a_row == 0); } |
|
|
|
} |
|
|
|
if print_progress { eprintln!("Finished vertical cuts, improvement: {}", last_improve_step == LastStep::Vertical); } |
|
|
|
|
|
|
|
if last_improve_step == LastStep::Horizontal { break; } |
|
|
|
if no_improvements_in_a_row == 2 { break; } |
|
|
|
|
|
|
|
{ |
|
|
|
let chosen_layouts = choose_layouts(db, &city, top_layout_count); |
|
|
|
let transposed_chosen_layouts: Vec<_> = chosen_layouts.iter().map(|x| transpose_saved_layout(x)).collect(); |
|
|
|
if print_progress { eprintln!("Building right distances (transposed)..."); } |
|
|
|
let right_distances_transposed = city::build_distances_right(&transposed_city); |
|
|
|
if print_progress { eprintln!("Finished building right distances"); } |
|
|
|
|
|
|
|
if print_progress { eprintln!("Starting to combine {} top houses DB; horizontal cuts", top_layout_count); } |
|
|
|
if create_new_best_combination(&transposed_city, &transposed_chosen_layouts, &transposed_chosen_layouts, db, &mut cache, &right_distances_transposed, true, print_progress) { |
|
|
|
last_improve_step = LastStep::Horizontal; |
|
|
|
no_improvements_in_a_row = 0; |
|
|
|
} else { |
|
|
|
no_improvements_in_a_row += 1; |
|
|
|
} |
|
|
|
if print_progress { eprintln!("Finished horizontal cuts, improvement: {}", no_improvements_in_a_row == 0); } |
|
|
|
} |
|
|
|
if print_progress { eprintln!("Finished horizontal cuts, improvement: {}", last_improve_step == LastStep::Horizontal); } |
|
|
|
|
|
|
|
if last_improve_step == LastStep::None { break; } |
|
|
|
if no_improvements_in_a_row == 2 { break; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|