|
|
@ -5,7 +5,7 @@ use itertools::iproduct; |
|
|
|
use std::collections::VecDeque; |
|
|
|
use std::collections::vec_deque::Iter; |
|
|
|
|
|
|
|
pub fn try_combine(city: &City, left_layouts: &Vec<&Vec<House>>, right_layouts: &Vec<&Vec<House>>) { |
|
|
|
pub fn try_combine(city: &City, left_layouts: &Vec<Vec<House>>, right_layouts: &Vec<Vec<House>>, print_transposed: bool) { |
|
|
|
// Sorted in reverse so we can remove from the end
|
|
|
|
let mut left_houses_sorted: Vec<Vec<House>> = left_layouts.iter() |
|
|
|
.map(|l| l.iter().sorted_by(|h1, h2| h2.x.cmp(&h1.x)).map(|x| *x).collect()) |
|
|
@ -33,7 +33,12 @@ pub fn try_combine(city: &City, left_layouts: &Vec<&Vec<House>>, right_layouts: |
|
|
|
let mut best_price = None; |
|
|
|
// x is the last left coordinate, x+1 is right
|
|
|
|
for x in 0..SIZE { |
|
|
|
if print_transposed { |
|
|
|
eprintln!("Starting y {}", x); |
|
|
|
} else { |
|
|
|
eprintln!("Starting x {}", x); |
|
|
|
} |
|
|
|
|
|
|
|
// Update the lines
|
|
|
|
for (left_line, left_houses) in lefts.iter_mut().zip(left_houses_sorted.iter_mut()) { |
|
|
|
while let Some(house) = left_houses.last() { |
|
|
@ -69,6 +74,15 @@ pub fn try_combine(city: &City, left_layouts: &Vec<&Vec<House>>, right_layouts: |
|
|
|
if is_compatible(city, &left, &right) { |
|
|
|
if best_price.is_none() || price < best_price.unwrap() { |
|
|
|
best_price = Some(price); |
|
|
|
if print_transposed { |
|
|
|
eprintln!("{} - new best score, cut on y {}, left {} - right {}, printing", price, x, left_i, right_i); |
|
|
|
println!("{} - new best score, cut on y {}, left {} - right {}", price, x, left_i, right_i); |
|
|
|
let new_houses: Vec<_> = left.houses().chain(right.houses()).collect(); |
|
|
|
println!("{}", new_houses.len()); |
|
|
|
for house in new_houses { |
|
|
|
println!("{} {}", house.x, house.y); |
|
|
|
} |
|
|
|
} else { |
|
|
|
eprintln!("{} - new best score, cut on x {}, left {} - right {}, printing", price, x, left_i, right_i); |
|
|
|
println!("{} - new best score, cut on x {}, left {} - right {}", price, x, left_i, right_i); |
|
|
|
let new_houses: Vec<_> = left.houses().chain(right.houses()).collect(); |
|
|
@ -77,6 +91,7 @@ pub fn try_combine(city: &City, left_layouts: &Vec<&Vec<House>>, right_layouts: |
|
|
|
println!("{} {}", house.y, house.x); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
compatibles += 1; |
|
|
|
|
|
|
|
// All other pairs would be more expensive
|
|
|
@ -86,7 +101,7 @@ pub fn try_combine(city: &City, left_layouts: &Vec<&Vec<House>>, right_layouts: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
eprintln!("{}/{} compatible", compatibles, compatibles + incompatibles); |
|
|
|
eprintln!("{} incompatibles checked before {} compatible", incompatibles, compatibles); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|