WIP Hack pt. 2

This commit is contained in:
Arne Keller 2019-04-28 23:46:52 +02:00
parent 9e76234fc3
commit 1fdc5f4b7a

View File

@ -39,30 +39,41 @@ impl cmp::PartialOrd for World {
fn random_world(rng: &mut SmallRng, tris: &mut Vec<Triangle>, angles: &mut [f32], flips: &mut Vec<bool>) -> World {
//tris.shuffle(rng);
*tris = vec![tris[5], tris[10], tris[3], tris[0], tris[2], tris[7], tris[9], tris[11], tris[4], tris[6], tris[1], tris[8]];
*flips = vec![false, false, false, true, true, false, false, true, true, false, false, true];
angles[0] = 0.8 * PI;
angles[1] = 2.0 * PI - (130.0/360.0) * 2.0 * PI;
angles[2] = 2.0 * PI - (300.0/360.0) * 2.0 * PI;
angles[3] = 1.2 * PI;
angles[4] = 2.0 * PI - 0.0;
angles[5] = 2.0 * PI - 1.8 * PI;
angles[6] = 2.0 * PI - 0.7 * PI;
angles[7] = 2.0 * PI - 0.0;
*tris = vec![tris[0], tris[9], tris[12], tris[6], tris[1], tris[4], tris[5], tris[13], tris[7], tris[15], tris[12], tris[2], tris[22], tris[18], tris[20], tris[17], tris[19], tris[3], tris[21], tris[16], tris[14], tris[8], tris[10]];
*flips = vec![true, false, true, true, false, false, false, true, false, true, false, true, false, true, true, false, true, false, false, true, false, false, false];
angles[0] = 0.9 * PI;
angles[1] = 1.4 * PI;
angles[2] = 1.3 * PI;
angles[3] = 1.4 * PI;
angles[4] = 0.5 * PI;
angles[5] = PI;
angles[6] = 0.0;
angles[7] = PI;
angles[8] = 0.8 * PI;
angles[9] = 2.0 * PI - (26.0/36.0) * 2.0 * PI;
angles[10] = 2.0 * PI - (1.0/3.6) * 2.0 * PI;
angles[11] = 0.77 * 2.0 * PI;
angles[9] = 0.1 * PI;
angles[10] = 0.05 * PI;
angles[11] = 0.0;
angles[12] = 1.7 * PI;
angles[13] = 0.5 * PI;
angles[14] = 0.0;
angles[15] = PI;
angles[16] = 1.5 * PI;
angles[17] = 1.1 * PI;
angles[18] = PI;
angles[19] = PI;
angles[20] = 0.0;
angles[21] = 2.0 * PI;
angles[22] = PI;
let mut world = World { tris: Vec::with_capacity(tris.len()), width: 0.0 };
for (idx, tri) in tris.iter().enumerate() {
let mut tri = *tri;
//flips[idx] = rng.gen();
flips[idx] = rng.gen();
if flips[idx] {
tri.0.x *= -1.0;
tri.1.x *= -1.0;
tri.2.x *= -1.0;
}
//angles[idx] = rng.gen_range(0.0, 2.0*PI);
angles[idx] = rng.gen_range(0.0, 2.0*PI);
tri = rotate(tri, angles[idx]);
let minx = min(min(tri.0.x, tri.1.x), tri.2.x);
tri.0.x -= minx;
@ -178,12 +189,12 @@ fn main() {
let new_best = one_main(&mut tris.clone());
if new_best.width < best {
best = new_best.width;
//eprint!("\r");
eprint!("\r");
println!("[{}] BEST {:.3} ", i, 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 {
//eprint!("\r");
eprint!("\r");
println!("[{}] best {:.3} / prev. {:.3} ", i, new_best.width, best);
}
}
@ -195,10 +206,7 @@ fn one_main(tris: &mut Vec<Triangle>) -> World {
let mut rng = SmallRng::from_entropy();
let mut best_width = f32::MAX;
let mut best_all = f32::MAX;
display::save_world("/tmp/initial4.svg", &construct_world(&*tris, &angles, &flips));
panic!();
let _random = random_world(&mut rng, tris, &mut angles, &mut flips);
display::save_world("/tmp/random.svg", &_random);
optimize(69999, &mut best_all, &mut best_width, &tris, &mut angles, &mut flips, &mut rng, "rand_", 0)
}