refactored data loading code
This commit is contained in:
parent
6f6df97af8
commit
1067c6a514
8 changed files with 74 additions and 128 deletions
42
src/utils.rs
42
src/utils.rs
|
|
@ -1,9 +1,49 @@
|
|||
use crate::alt::LandmarkSet;
|
||||
use crate::gridgraph::GridGraph;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::process::exit;
|
||||
|
||||
pub const EARTH_RADIUS: f64 = 6_371_000.0; // meters
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
|
||||
pub struct RoutingQuery{
|
||||
pub struct RoutingQuery {
|
||||
pub source: usize,
|
||||
pub destination: usize,
|
||||
}
|
||||
|
||||
pub fn load_graph(path: &str) -> Box<GridGraph> {
|
||||
println!("Loading file from {}", path);
|
||||
let file = match File::open(path) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
println!("Error while opening the file {}: {}", path, e);
|
||||
exit(1)
|
||||
}
|
||||
};
|
||||
|
||||
let graph = match GridGraph::from_fmi_file(file) {
|
||||
Ok(g) => g,
|
||||
Err(e) => {
|
||||
println!("Error while reading the graph: {:?}", e);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
println!("Loaded graph file");
|
||||
|
||||
graph
|
||||
}
|
||||
|
||||
pub fn load_landmarks(path: &str) -> LandmarkSet {
|
||||
let landmarks = match File::open(path) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
println!("Error while opening landmark file {}: {:?}", path, e);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
bincode::deserialize_from(BufReader::new(landmarks)).unwrap()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue