use log::{error, info};
use osmgraphing::{
configs::Config,
helpers,
io::Parser,
network::NodeIdx,
routing::{self},
};
use std::{path::PathBuf, time::Instant};
fn main() {
helpers::init_logging("INFO", vec!["dijkstra"]).expect("LogLevel 'INFO' does exist.");
info!("Executing example: A*");
let cfg = {
let cfg_file = PathBuf::from("resources/configs/simple-stuttgart.fmi.yaml");
match Config::from_yaml(&cfg_file) {
Ok(cfg) => cfg,
Err(msg) => {
error!("{}", msg);
return;
}
}
};
let cfg_routing = cfg
.routing
.expect("Config-file should contain routing-settings.");
let now = Instant::now();
let graph = match Parser::parse_and_finalize(cfg.parser) {
Ok(graph) => graph,
Err(msg) => {
error!("{}", msg);
return;
}
};
info!(
"Finished parsing in {} seconds ({} µs).",
now.elapsed().as_secs(),
now.elapsed().as_micros(),
);
info!("");
info!("{}", graph);
let mut dijkstra = routing::Dijkstra::new();
let nodes = graph.nodes();
let src = nodes.create(NodeIdx(1));
let dst = nodes.create(NodeIdx(5));
let now = Instant::now();
let option_path = dijkstra.compute_best_path(&src, &dst, &graph, &cfg_routing);
info!("");
info!(
"Ran Dijkstra-query in {} ms",
now.elapsed().as_micros() as f64 / 1_000.0,
);
if let Some(path) = option_path {
info!(
"Cost {:?} from ({}) to ({}).",
path.calc_cost(cfg_routing.metric_indices(), &graph),
src,
dst
);
} else {
info!("No path from ({}) to ({}).", src, dst);
}
}