Use a priority queue instead of djikstra's
This commit is contained in:
parent
ce36020814
commit
5da4260e81
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
tmp*.svg
|
80
src/main.rs
80
src/main.rs
@ -69,7 +69,7 @@ fn main() {
|
||||
//route: vec![house],
|
||||
//length: 0.0.into()
|
||||
};
|
||||
/*
|
||||
|
||||
eprintln!("# Max delay possible: {:?}", start.delay);
|
||||
|
||||
let mut states = BinaryHeap::new();
|
||||
@ -149,84 +149,6 @@ fn main() {
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
display::dump_svg(&points, &lines, &polys);
|
||||
*/
|
||||
|
||||
if let Some(route) = dijkstra::<_, R64, _, _, _>(&start, |node| {
|
||||
eprintln!("{:?}", node);
|
||||
if node.pos.x() == 0.0 {
|
||||
return vec![];
|
||||
}
|
||||
assert!(node.pos.x() > 0.0);
|
||||
// get successors (next points)
|
||||
let mut all = Vec::new();
|
||||
|
||||
// try to go to any points of any polygon
|
||||
for next in &points {
|
||||
let next = Point::from(*next);
|
||||
if none_intersect(&polys, &Line::new(node.pos, next)) {
|
||||
eprintln!("{},{} would go {},{}", node.pos.x(), node.pos.y(), next.x(), next.y());
|
||||
all.push((RunState {
|
||||
pos: next,
|
||||
bus: node.bus.translate(0.0.into(), distance(node.pos, next) * R64::from(2.0)),
|
||||
delay: node.delay,
|
||||
}, 0.0.into()));
|
||||
} else {
|
||||
eprintln!("{},{} can't go {},{}", node.pos.x(), node.pos.y(), next.x(), next.y());
|
||||
}
|
||||
}
|
||||
|
||||
// try to go the bus
|
||||
for delay in float_range(100.0, 0.0).map(R64::from) {
|
||||
let bus = node.bus.translate(0.0.into(), delay);
|
||||
let range = to_bus(bus, node.pos);
|
||||
if !range.is_empty() {
|
||||
let range = Line::new(range[0], range[1]);
|
||||
for percent in float_range(0.0, 1.0).map(R64::from) {
|
||||
let mut next = range.start;
|
||||
next.x += range.dx() * percent;
|
||||
next.y += range.dy() * percent;
|
||||
let next = Point::from(next);
|
||||
if none_intersect(&polys, &Line::new(node.pos, next)) {
|
||||
let cost = distance(node.pos, next);
|
||||
//eprintln!("(delay {:02}) go from {:?} len {:.2} to {:?}", delay, node.pos, cost, next);
|
||||
all.push((RunState {
|
||||
pos: next,
|
||||
bus: next,
|
||||
delay,
|
||||
//route: { let mut route = node.route.clone(); route.push(next); route },
|
||||
//length: node.length + cost
|
||||
}, -delay));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
all
|
||||
/*
|
||||
}, |node| {
|
||||
// heuristic
|
||||
// -> current x coordinate ?
|
||||
//node.pos.x()
|
||||
0.0.into()
|
||||
*/
|
||||
}, |node| {
|
||||
// success condition
|
||||
node.pos.x() == 0.0 && node.delay > R64::from(5.0)
|
||||
}) {
|
||||
eprintln!("route found");
|
||||
let first = route.0.first().unwrap();
|
||||
let last = route.0.last().unwrap();
|
||||
let delay = last.delay;
|
||||
eprintln!("d = {}", delay);
|
||||
let points = vec![(house, "red"), (first.bus.translate(0.0.into(), delay), "yellow"), (last.bus, "orange")];
|
||||
let lines = route.0.iter().map(|x| x.pos).collect::<LineString>().lines().map(|x| {
|
||||
(x, "gray")
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
display::dump_svg(&points, &lines, &polys);
|
||||
} else {
|
||||
eprintln!("no route found!");
|
||||
}
|
||||
// */
|
||||
}
|
||||
|
||||
/// [a; b]
|
||||
|
Loading…
Reference in New Issue
Block a user