Various changes
This commit is contained in:
parent
4815d4f965
commit
551a0ba14c
@ -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}}");
|
||||
}
|
||||
|
22
src/input.rs
22
src/input.rs
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
18
src/main.rs
18
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<RTree<Polygon>> = 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
|
||||
|
Loading…
Reference in New Issue
Block a user