cleaned up the benchmark programm
This commit is contained in:
parent
2aeb770b8f
commit
f11dda3939
1 changed files with 43 additions and 45 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use fapra_osm_2::alt::{LandmarkSet, LandmarkBestSet};
|
use fapra_osm_2::alt::{LandmarkBestSet, LandmarkSet};
|
||||||
use fapra_osm_2::astar::{estimate_haversine, estimate_latitude, AStar};
|
use fapra_osm_2::astar::{estimate_haversine, AStar};
|
||||||
use fapra_osm_2::gridgraph::{GridGraph, NodeId};
|
use fapra_osm_2::gridgraph::{GridGraph, NodeId};
|
||||||
use fapra_osm_2::utils::RoutingQuery;
|
use fapra_osm_2::utils::RoutingQuery;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
@ -20,9 +20,9 @@ struct Args {
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
targets: String,
|
targets: String,
|
||||||
|
|
||||||
/// landmark file
|
/// landmark file. ALT Benchmarks are only run, if this is given.
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
landmarks: String,
|
landmarks: Option<String>,
|
||||||
|
|
||||||
/// run dijkstra
|
/// run dijkstra
|
||||||
#[clap(long, action)]
|
#[clap(long, action)]
|
||||||
|
|
@ -32,9 +32,9 @@ struct Args {
|
||||||
#[clap(long, action)]
|
#[clap(long, action)]
|
||||||
astar: bool,
|
astar: bool,
|
||||||
|
|
||||||
/// run ALT
|
/// How many of the given landmarks to select
|
||||||
#[clap(long, action)]
|
#[clap(long, action, default_value_t = 4)]
|
||||||
alt: bool,
|
alt_best_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
@ -56,6 +56,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let astar = AStar { graph: &(*graph) };
|
||||||
|
|
||||||
let targets = match File::open(args.targets.clone()) {
|
let targets = match File::open(args.targets.clone()) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -66,22 +68,44 @@ fn main() {
|
||||||
|
|
||||||
let targets: Vec<RoutingQuery> = serde_json::from_reader(BufReader::new(targets)).unwrap();
|
let targets: Vec<RoutingQuery> = serde_json::from_reader(BufReader::new(targets)).unwrap();
|
||||||
|
|
||||||
let landmarks = match File::open(args.landmarks.clone()) {
|
if let Some(landmark_path) = args.landmarks {
|
||||||
Ok(f) => f,
|
let landmarks = match File::open(landmark_path.clone()) {
|
||||||
Err(e) => {
|
Ok(f) => f,
|
||||||
println!(
|
Err(e) => {
|
||||||
"Error while opening landmark file {}: {:?}",
|
println!(
|
||||||
args.landmarks, e
|
"Error while opening landmark file {}: {:?}",
|
||||||
);
|
landmark_path, e
|
||||||
exit(1);
|
);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let landmarks: LandmarkSet = bincode::deserialize_from(BufReader::new(landmarks)).unwrap();
|
||||||
|
|
||||||
|
println!("running ALT");
|
||||||
|
|
||||||
|
let mut best_landmarks = LandmarkBestSet::new(args.alt_best_size, &landmarks);
|
||||||
|
|
||||||
|
let start = Instant::now();
|
||||||
|
|
||||||
|
for query in targets.iter() {
|
||||||
|
// println!("working on {:?}", query);
|
||||||
|
let source = astar.graph.nodes[query.source];
|
||||||
|
let destination = astar.graph.nodes[query.destination];
|
||||||
|
|
||||||
|
best_landmarks.select_best(source.index as NodeId, destination.index as NodeId);
|
||||||
|
|
||||||
|
let _result = astar.shortest_path(&source, &destination, |src, dest| {
|
||||||
|
best_landmarks.estimate(src.index as NodeId, dest.index as NodeId)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
let landmarks: LandmarkSet = bincode::deserialize_from(BufReader::new(landmarks)).unwrap();
|
let elapsed = start.elapsed();
|
||||||
|
|
||||||
let astar = AStar { graph: &(*graph) };
|
let time_per_route = elapsed.as_secs_f64() / (targets.len() as f64);
|
||||||
|
|
||||||
println!("{:?}", args);
|
println!("It took {} seconds per route for ALT.", time_per_route);
|
||||||
|
}
|
||||||
|
|
||||||
if args.astar {
|
if args.astar {
|
||||||
println!("running A*");
|
println!("running A*");
|
||||||
|
|
@ -122,30 +146,4 @@ fn main() {
|
||||||
let time_per_route = elapsed.as_secs_f64() / (targets.len() as f64);
|
let time_per_route = elapsed.as_secs_f64() / (targets.len() as f64);
|
||||||
println!("It took {} seconds per round for Dijkstra.", time_per_route);
|
println!("It took {} seconds per round for Dijkstra.", time_per_route);
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.alt {
|
|
||||||
println!("running ALT");
|
|
||||||
|
|
||||||
let mut best_landmarks = LandmarkBestSet::new(4, &landmarks);
|
|
||||||
// Landmarks
|
|
||||||
let start = Instant::now();
|
|
||||||
|
|
||||||
for query in targets.iter() {
|
|
||||||
println!("working on {:?}", query);
|
|
||||||
let source = astar.graph.nodes[query.source];
|
|
||||||
let destination = astar.graph.nodes[query.destination];
|
|
||||||
|
|
||||||
best_landmarks.select_best(source.index as NodeId, destination.index as NodeId);
|
|
||||||
|
|
||||||
let _result = astar.shortest_path(&source, &destination, |src, dest| {
|
|
||||||
best_landmarks.estimate(src.index as NodeId, dest.index as NodeId)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let elapsed = start.elapsed();
|
|
||||||
|
|
||||||
let time_per_route = elapsed.as_secs_f64() / (targets.len() as f64);
|
|
||||||
|
|
||||||
println!("It took {} seconds per route for ALT.", time_per_route);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue