From 551a0ba14cda5cd3dd82997e338c39a548d140f5 Mon Sep 17 00:00:00 2001 From: arnekeller Date: Mon, 1 Apr 2019 23:22:35 +0200 Subject: [PATCH] Various changes --- src/display.rs | 11 +++++++++-- src/input.rs | 22 ++++++++++++---------- src/main.rs | 18 +++++++++++++----- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/display.rs b/src/display.rs index 8917e32..c2a9e26 100644 --- a/src/display.rs +++ b/src/display.rs @@ -69,8 +69,15 @@ pub(crate) fn dump_latex_code(route: &[RunState], polys: &[Polygon]) { println!("\\tkzDrawSegment(R{},R{})", idx - 1, idx); } for idx in 0..route.len() { - let color = if idx == 0 || idx == route.len() - 1 { "green" } else { "red" }; - println!("\\tkzDrawPoint[fill={},color=black,size=13](R{})", color, idx); + let color = if idx == 0 || idx == route.len() - 1 { + "green" + } else { + "red" + }; + println!( + "\\tkzDrawPoint[fill={},color=black,size=13](R{})", + color, idx + ); } println!("\\end{{tikzpicture}}"); } diff --git a/src/input.rs b/src/input.rs index 503b575..5d10802 100644 --- a/src/input.rs +++ b/src/input.rs @@ -73,9 +73,11 @@ fn read_svg(input: &str) -> Result> { let mut polys = Vec::new(); for (id, node) in svg.descendants().svg() { //eprintln!("<{:?} /> {:?}", id, node); - if id == ElementId::Path && *node.parent().unwrap().tag_name() != QName::Id(ElementId::Marker) { - let attrs = node.attributes(); - if let Some(&AttributeValue::Path(ref path)) = attrs.get_value(AttributeId::D) { + if id == ElementId::Path + && *node.parent().unwrap().tag_name() != QName::Id(ElementId::Marker) + { + let attrs = node.attributes(); + if let Some(&AttributeValue::Path(ref path)) = attrs.get_value(AttributeId::D) { let mut path = path.clone(); path.conv_to_absolute(); @@ -84,18 +86,18 @@ fn read_svg(input: &str) -> Result> { match p { PathSegment::MoveTo { x, y, .. } => { points.push(Point::new(*x, -*y)); - }, + } PathSegment::LineTo { x, y, .. } => { points.push(Point::new(*x, -*y)); - }, + } PathSegment::VerticalLineTo { y, .. } => { points.push(Point::new(points.last().unwrap().x(), -*y)); - }, + } PathSegment::HorizontalLineTo { x, .. } => { points.push(Point::new(*x, points.last().unwrap().y())); - }, + } PathSegment::ClosePath { .. } => break, - _ => unimplemented!("nicht unterstütztes SVG-Element: {:?}", p) + _ => unimplemented!("nicht unterstütztes SVG-Element: {:?}", p), } } if points.len() == 1 { @@ -105,13 +107,13 @@ fn read_svg(input: &str) -> Result> { // Hindernis polys.push(Polygon::new(points.into(), vec![])); } - } + } } } Ok(InputData { start: house.expect("kein Startpunkt definiert!"), - polys + polys, }) } diff --git a/src/main.rs b/src/main.rs index 80d877e..47eee09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use std::collections::BinaryHeap; use std::f64; use std::process::exit; use std::sync::RwLock; +use std::time::{self, Instant}; mod display; mod input; @@ -138,15 +139,16 @@ fn main() { // Zwischenlösungen speichern let save_prefix = "route_"; let mut save_counter = 0; + // Debug-Statistiken + let mut total_time = time::Duration::from_secs(0); + let mut iterations = 0; // weitersuchen, bis kein besserer Zustand mehr vorhanden ist while states.peek().map(|x| x[0].bus > best_bus) == Some(true) { + let start = Instant::now(); // besten Zustand einlesen let state = states.pop().unwrap(); let last = &state[0]; - if opt.debug { - println!("last {:?}", last); - } // neue Zustände let mut all = vec![]; @@ -222,6 +224,12 @@ fn main() { } // neu gefundene Routen speichern states.extend(all); + let end = Instant::now(); + total_time += end - start; + iterations += 1; + } + if opt.debug { + eprintln!("DEBUG: {}us/iteration", total_time.as_micros() / iterations); } // beste Lösung ausgeben eprintln!("Finale Lösung:"); @@ -264,7 +272,7 @@ fn main() { } } -lazy_static!{ +lazy_static! { static ref RTREE: RwLock> = RwLock::new(RTree::new()); } @@ -322,7 +330,7 @@ fn distance(a: Point, b: Point) -> f64 { fn best_bus_pos(opt: &Opt, total_distance: f64, lisa: Point) -> f64 { let x_l = lisa.x(); // a let y_l = lisa.y(); // b - + // y-Koordinate des Busses: d // Länge, die Lisa noch laufen muss: l // Verhältnis beider Geschwindigkeiten: x = bus / lisa