Compare commits
2 Commits
master
...
hack-for-e
Author | SHA1 | Date | |
---|---|---|---|
|
9fe127cab7 | ||
|
ffac5baa99 |
@ -8,6 +8,8 @@ edition = "2018"
|
|||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
lto = "fat"
|
||||||
|
incremental = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
geo = { git = "https://github.com/FliegendeWurst/geo" }
|
geo = { git = "https://github.com/FliegendeWurst/geo" }
|
||||||
|
60
src/main.rs
60
src/main.rs
@ -39,41 +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 {
|
fn random_world(rng: &mut SmallRng, tris: &mut Vec<Triangle>, angles: &mut [f32], flips: &mut Vec<bool>) -> World {
|
||||||
//tris.shuffle(rng);
|
//tris.shuffle(rng);
|
||||||
*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]];
|
*tris = vec![tris[9], tris[12], tris[6], tris[1], tris[4], tris[0], tris[15], tris[5], tris[13], tris[7], 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];
|
*flips = vec![false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, true, true, false, false, true, false, false, false];
|
||||||
angles[0] = 0.9 * PI;
|
angles[0] = 1.45 * PI;
|
||||||
angles[1] = 1.4 * PI;
|
angles[1] = 1.37 * PI;
|
||||||
angles[2] = 1.3 * PI;
|
angles[2] = 1.5 * PI;
|
||||||
angles[3] = 1.4 * PI;
|
angles[3] = 0.6 * PI;
|
||||||
angles[4] = 0.5 * PI;
|
angles[4] = 0.1 * PI;
|
||||||
angles[5] = PI;
|
angles[5] = 1.0 * PI;
|
||||||
angles[6] = 0.0;
|
angles[6] = 1.5 * PI;
|
||||||
angles[7] = PI;
|
angles[7] = 1.1 * PI;
|
||||||
angles[8] = 0.8 * PI;
|
angles[8] = PI;
|
||||||
angles[9] = 0.1 * PI;
|
angles[9] = 0.8 * PI;
|
||||||
angles[10] = 0.05 * PI;
|
angles[10] = 0.05 * PI;
|
||||||
angles[11] = 0.0;
|
angles[11] = 0.0;
|
||||||
angles[12] = 1.7 * PI;
|
angles[12] = 1.7 * PI;
|
||||||
angles[13] = 0.5 * PI;
|
angles[13] = 0.5 * PI;
|
||||||
angles[14] = 0.0;
|
angles[14] = 0.0;
|
||||||
angles[15] = PI;
|
angles[15] = 2.0 * PI;
|
||||||
angles[16] = 1.5 * PI;
|
angles[16] = 1.5 * PI;
|
||||||
angles[17] = 1.1 * PI;
|
angles[17] = 1.1 * PI;
|
||||||
angles[18] = PI;
|
angles[18] = 0.6 * PI;
|
||||||
angles[19] = PI;
|
angles[19] = 0.7 * PI;
|
||||||
angles[20] = 0.0;
|
angles[20] = -0.4 * PI;
|
||||||
angles[21] = 2.0 * PI;
|
angles[21] = 0.5 * PI;
|
||||||
angles[22] = PI;
|
angles[22] = 0.6 * PI;
|
||||||
let mut world = World { tris: Vec::with_capacity(tris.len()), width: 0.0 };
|
let mut world = World { tris: Vec::with_capacity(tris.len()), width: 0.0 };
|
||||||
for (idx, tri) in tris.iter().enumerate() {
|
for (idx, tri) in tris.iter().enumerate() {
|
||||||
let mut tri = *tri;
|
let mut tri = *tri;
|
||||||
flips[idx] = rng.gen();
|
//flips[idx] = rng.gen();
|
||||||
if flips[idx] {
|
if flips[idx] {
|
||||||
tri.0.x *= -1.0;
|
tri.0.x *= -1.0;
|
||||||
tri.1.x *= -1.0;
|
tri.1.x *= -1.0;
|
||||||
tri.2.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]);
|
tri = rotate(tri, angles[idx]);
|
||||||
let minx = min(min(tri.0.x, tri.1.x), tri.2.x);
|
let minx = min(min(tri.0.x, tri.1.x), tri.2.x);
|
||||||
tri.0.x -= minx;
|
tri.0.x -= minx;
|
||||||
@ -207,7 +207,8 @@ fn one_main(tris: &mut Vec<Triangle>) -> World {
|
|||||||
let mut best_width = f32::MAX;
|
let mut best_width = f32::MAX;
|
||||||
let mut best_all = f32::MAX;
|
let mut best_all = f32::MAX;
|
||||||
let _random = random_world(&mut rng, tris, &mut angles, &mut flips);
|
let _random = random_world(&mut rng, tris, &mut angles, &mut flips);
|
||||||
optimize(69999, &mut best_all, &mut best_width, &tris, &mut angles, &mut flips, &mut rng, "rand_", 0)
|
//display::save_world("/tmp/rand.svg", &_random);
|
||||||
|
optimize(0, &mut best_all, &mut best_width, &tris, &mut angles, &mut flips, &mut rng, "rand_", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@ -274,6 +275,23 @@ fn optimize(iters: usize, best_all: &mut f32, best_width: &mut f32, tris: &[Tria
|
|||||||
angles[idx] -= angle;
|
angles[idx] -= angle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for i in 1000..2499 {
|
||||||
|
let angle = rng.gen_range(-PI, PI);
|
||||||
|
angles[idx] += angle;
|
||||||
|
let new = construct_world(tris, &angles, &best_flips);
|
||||||
|
if new.width < *best_width {
|
||||||
|
*best_all = new.width;
|
||||||
|
eprint!("\r[{}O{}I{}EE{}] at {:.3}", save_counter, iteration, idx, i, new.width);
|
||||||
|
//display::save_world(&format!("{}{}_{}_{}.svg", save_prefix, save_counter, iteration, i), &new);
|
||||||
|
//iters = 99999;
|
||||||
|
best = new;
|
||||||
|
*best_width = best.width;
|
||||||
|
found_better = true;
|
||||||
|
*best_angles = angles.clone();
|
||||||
|
} else {
|
||||||
|
angles[idx] -= angle;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
iteration += 1;
|
iteration += 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user