Various changes

This commit is contained in:
arnekeller 2019-04-01 23:22:35 +02:00
parent 4815d4f965
commit 551a0ba14c
3 changed files with 34 additions and 17 deletions

View File

@ -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}}");
}

View File

@ -73,9 +73,11 @@ fn read_svg(input: &str) -> Result<InputData, Box<Error>> {
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<InputData, Box<Error>> {
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<InputData, Box<Error>> {
// Hindernis
polys.push(Polygon::new(points.into(), vec![]));
}
}
}
}
}
Ok(InputData {
start: house.expect("kein Startpunkt definiert!"),
polys
polys,
})
}

View File

@ -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<RTree<Polygon>> = RwLock::new(RTree::new());
}