|
@ -5,7 +5,7 @@ use itertools::iproduct; |
|
|
use std::collections::VecDeque; |
|
|
use std::collections::VecDeque; |
|
|
use std::collections::vec_deque::Iter; |
|
|
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
|
|
|
// Sorted in reverse so we can remove from the end
|
|
|
let mut left_houses_sorted: Vec<Vec<House>> = left_layouts.iter() |
|
|
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()) |
|
|
.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; |
|
|
let mut best_price = None; |
|
|
// x is the last left coordinate, x+1 is right
|
|
|
// x is the last left coordinate, x+1 is right
|
|
|
for x in 0..SIZE { |
|
|
for x in 0..SIZE { |
|
|
|
|
|
if print_transposed { |
|
|
|
|
|
eprintln!("Starting y {}", x); |
|
|
|
|
|
} else { |
|
|
eprintln!("Starting x {}", x); |
|
|
eprintln!("Starting x {}", x); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Update the lines
|
|
|
// Update the lines
|
|
|
for (left_line, left_houses) in lefts.iter_mut().zip(left_houses_sorted.iter_mut()) { |
|
|
for (left_line, left_houses) in lefts.iter_mut().zip(left_houses_sorted.iter_mut()) { |
|
|
while let Some(house) = left_houses.last() { |
|
|
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 is_compatible(city, &left, &right) { |
|
|
if best_price.is_none() || price < best_price.unwrap() { |
|
|
if best_price.is_none() || price < best_price.unwrap() { |
|
|
best_price = Some(price); |
|
|
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); |
|
|
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); |
|
|
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(); |
|
|
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); |
|
|
println!("{} {}", house.y, house.x); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
compatibles += 1; |
|
|
compatibles += 1; |
|
|
|
|
|
|
|
|
// All other pairs would be more expensive
|
|
|
// 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); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|