Optimize last route segment
This commit is contained in:
parent
6de816f6a4
commit
37544b09aa
@ -64,7 +64,10 @@ pub(crate) fn generate_svg(
|
|||||||
) -> String {
|
) -> String {
|
||||||
let mut document = Document::new()
|
let mut document = Document::new()
|
||||||
// view box at (x,y), (w,h)
|
// view box at (x,y), (w,h)
|
||||||
.set("viewBox", (0.0, route2_start.y(), 2100.0, -route2_start.y()+1000.0))
|
.set(
|
||||||
|
"viewBox",
|
||||||
|
(0.0, route2_start.y(), 2100.0, -route2_start.y() + 1000.0),
|
||||||
|
)
|
||||||
.set("xmlns:xlink", "http://www.w3.org/1999/xlink");
|
.set("xmlns:xlink", "http://www.w3.org/1999/xlink");
|
||||||
|
|
||||||
for circle in points.iter().map(|(p, color)| {
|
for circle in points.iter().map(|(p, color)| {
|
||||||
|
@ -57,7 +57,7 @@ fn read_stdin() -> InputData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn custom_input() -> InputData {
|
fn _custom_input() -> InputData {
|
||||||
let mut polys = vec![];
|
let mut polys = vec![];
|
||||||
polys.push(Polygon::new(
|
polys.push(Polygon::new(
|
||||||
vec![
|
vec![
|
||||||
|
80
src/main.rs
80
src/main.rs
@ -4,6 +4,7 @@ use chrono::{Duration, NaiveTime};
|
|||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::BinaryHeap;
|
use std::collections::BinaryHeap;
|
||||||
|
use std::f64;
|
||||||
|
|
||||||
mod display;
|
mod display;
|
||||||
mod input;
|
mod input;
|
||||||
@ -113,43 +114,41 @@ fn main() {
|
|||||||
let bus = last.bus;
|
let bus = last.bus;
|
||||||
let range = to_bus(bus, last.pos);
|
let range = to_bus(bus, last.pos);
|
||||||
if range.len() == 2 {
|
if range.len() == 2 {
|
||||||
let range = Line::new(range[0], range[1]);
|
let next = Point::new(
|
||||||
for next_y in float_range(range.start.y, range.end.y) {
|
0.0,
|
||||||
let mut next = range.start;
|
last.pos.y() + 30.0f64.to_radians().tan() * last.pos.x(),
|
||||||
next.y = next_y;
|
);
|
||||||
let next = Point::from(next);
|
let line = Line::new(last.pos, next);
|
||||||
let line = Line::new(last.pos, next);
|
if none_intersect(&polys, &line) {
|
||||||
if none_intersect(&polys, &line) {
|
let delay = line.end.y
|
||||||
let delay =
|
- bus.y() - line.end_point().euclidean_distance(&line.start_point())
|
||||||
line.end.y
|
* 2.0;
|
||||||
- bus.y() - line.end_point().euclidean_distance(&line.start_point()) * 2.0;
|
if delay > best_delay {
|
||||||
if delay > best_delay {
|
// neue beste Wartezeit
|
||||||
// neue beste Wartezeit
|
let mut route = s.clone();
|
||||||
let mut route = s.clone();
|
route.insert(
|
||||||
route.insert(
|
0,
|
||||||
0,
|
RunState {
|
||||||
RunState {
|
pos: next,
|
||||||
pos: next,
|
bus: next,
|
||||||
bus: next,
|
delay,
|
||||||
delay,
|
},
|
||||||
},
|
);
|
||||||
);
|
eprintln!(
|
||||||
eprintln!(
|
"Verbesserung: {:?} ({:?} Zustände verbleiben)",
|
||||||
"Verbesserung: {:?} ({:?} Zustände verbleiben)",
|
delay_to_time(delay),
|
||||||
delay_to_time(delay),
|
states.len()
|
||||||
states.len()
|
);
|
||||||
);
|
best = route;
|
||||||
best = route;
|
best.reverse();
|
||||||
best.reverse();
|
best_delay = delay;
|
||||||
best_delay = delay;
|
display::save_svg(
|
||||||
display::save_svg(
|
&format!("{}{}.svg", save_prefix, save_counter),
|
||||||
&format!("{}{}.svg", save_prefix, save_counter),
|
house,
|
||||||
house,
|
&polys,
|
||||||
&polys,
|
&best,
|
||||||
&best,
|
);
|
||||||
);
|
save_counter += 1;
|
||||||
save_counter += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
states.extend(all);
|
states.extend(all);
|
||||||
@ -164,13 +163,6 @@ fn main() {
|
|||||||
display::dump_route(house, &polys, &route);
|
display::dump_route(house, &polys, &route);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [a; b]
|
|
||||||
fn float_range(a: f64, b: f64) -> impl Iterator<Item = f64> {
|
|
||||||
const STEPS: usize = 1337;
|
|
||||||
let d = b - a;
|
|
||||||
(0..=STEPS).map(move |s| a + ((s as f64) * d) / STEPS as f64)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn none_intersect(polys: &[Polygon], line: &Line) -> bool {
|
fn none_intersect(polys: &[Polygon], line: &Line) -> bool {
|
||||||
let mut middle = line.start;
|
let mut middle = line.start;
|
||||||
middle.x += line.dx() / 2.0;
|
middle.x += line.dx() / 2.0;
|
||||||
|
Loading…
Reference in New Issue
Block a user