Save info about best solutions
This commit is contained in:
parent
1f7d7d9a3a
commit
27734995dd
@ -1,6 +1,6 @@
|
|||||||
use svg::node::element::path::Data;
|
use svg::node::element::path::Data;
|
||||||
use svg::node::element::Path;
|
use svg::node::element::Path;
|
||||||
use svg::node::element::{AnimateMotion, Circle, MotionPath};
|
use svg::node::element::Circle;
|
||||||
use svg::Document;
|
use svg::Document;
|
||||||
use svg::Node;
|
use svg::Node;
|
||||||
|
|
||||||
@ -8,6 +8,31 @@ use std::fs;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
fn idx_to_char(idx: usize) -> char {
|
||||||
|
match idx {
|
||||||
|
0 => 'A',
|
||||||
|
1 => 'B',
|
||||||
|
2 => 'C',
|
||||||
|
_ => unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn save_info(filename: &str, world: &World, tris: &[Triangle], original_tris: &[Triangle]) {
|
||||||
|
let mut text = format!("Gesamtabstand: {:.0}\n", world.width);
|
||||||
|
for (idx, (_, tri)) in world.tris.iter().enumerate() {
|
||||||
|
let unrotated_tri = tris[idx];
|
||||||
|
let original_idx = original_tris.iter().position(|x| x.0 == unrotated_tri.0 && x.1 == unrotated_tri.1 && x.2 == unrotated_tri.2).unwrap();
|
||||||
|
text += &format!("D{}:", original_idx);
|
||||||
|
let mut coordinates = vec![tri.0, tri.1, tri.2];
|
||||||
|
coordinates.sort_by_key(|x| (x.x * 100.0) as u32);
|
||||||
|
for (idx, c) in coordinates.into_iter().enumerate() {
|
||||||
|
text += &format!(" D{}{}[{:.0} {:.0}]", original_idx, idx_to_char(idx), c.x, c.y);
|
||||||
|
}
|
||||||
|
text += "\n";
|
||||||
|
}
|
||||||
|
fs::write(filename, text).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn save_tri(filename: &str, tri: Triangle) {
|
pub(crate) fn save_tri(filename: &str, tri: Triangle) {
|
||||||
fs::write(filename, generate_svg(&[tri])).unwrap();
|
fs::write(filename, generate_svg(&[tri])).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,7 @@ fn main() {
|
|||||||
tri.2.y -= tri.0.y;
|
tri.2.y -= tri.0.y;
|
||||||
tri.0.y = 0.0;
|
tri.0.y = 0.0;
|
||||||
}
|
}
|
||||||
|
let original_tris = tris.clone();
|
||||||
let mut best = f32::MAX;
|
let mut best = f32::MAX;
|
||||||
let mut i = 0u64;
|
let mut i = 0u64;
|
||||||
let save_prefix = format!("rand_sel_{}_", random::<u64>());
|
let save_prefix = format!("rand_sel_{}_", random::<u64>());
|
||||||
@ -166,6 +167,7 @@ fn main() {
|
|||||||
//eprint!("\r");
|
//eprint!("\r");
|
||||||
println!("[{}] BEST {:.3} ", i, best);
|
println!("[{}] BEST {:.3} ", i, best);
|
||||||
display::save_world(&format!("{}{}.svg", save_prefix, i), &new_best);
|
display::save_world(&format!("{}{}.svg", save_prefix, i), &new_best);
|
||||||
|
display::save_info(&format!("{}{}.txt", save_prefix, i), &new_best, &tris, &original_tris);
|
||||||
} else {
|
} else {
|
||||||
//eprint!("\r");
|
//eprint!("\r");
|
||||||
println!("[{}] best {:.3} / prev. {:.3} ", i, new_best.width, best);
|
println!("[{}] best {:.3} / prev. {:.3} ", i, new_best.width, best);
|
||||||
|
Loading…
Reference in New Issue
Block a user