diff --git a/engine/src/main.rs b/engine/src/main.rs index 818755c4..2f0a58a8 100644 --- a/engine/src/main.rs +++ b/engine/src/main.rs @@ -1,5 +1,6 @@ use std::env; use std::path::Path; +use std::sync::Arc; extern crate bmw_routing_engine; @@ -32,9 +33,9 @@ fn main() { let to = read_into_vector(path.join("test/target").to_str().unwrap()).expect("could not read target"); let ground_truth = read_into_vector(path.join("test/travel_time_length").to_str().unwrap()).expect("could not read travel_time_length"); - let graph = Graph::new(first_out, head, travel_time); + let graph = Arc::new(Graph::new(first_out, head, travel_time)); let mut simple_server = DijkServer::new(graph.clone()); - let mut bi_dir_server = BiDijkServer::::new(graph.clone()); + let mut bi_dir_server = BiDijkServer::new(graph.clone()); let async_server = AsyncDijkServer::new(graph.clone()); let mut async_bi_dir_server = AsyncBiDijkServer::new(graph.clone()); @@ -47,7 +48,7 @@ fn main() { inverted_order[node as usize] = i as u32; } let mut ch_server = CHServer::new((Graph::new(ch_first_out, ch_head, ch_weight).ch_split(&inverted_order), None)); - let mut ch_server_with_own_ch = CHServer::new(contraction_hierarchy::contract(graph, ch_order)); + let mut ch_server_with_own_ch = CHServer::new(contraction_hierarchy::contract(&graph, ch_order)); for ((&from, &to), &ground_truth) in from.iter().zip(to.iter()).zip(ground_truth.iter()).take(100) { let ground_truth = match ground_truth { diff --git a/engine/src/shortest_path/contraction_hierarchy/mod.rs b/engine/src/shortest_path/contraction_hierarchy/mod.rs index 6ddc5b01..dbe51732 100644 --- a/engine/src/shortest_path/contraction_hierarchy/mod.rs +++ b/engine/src/shortest_path/contraction_hierarchy/mod.rs @@ -58,7 +58,7 @@ struct ContractionGraph { } impl ContractionGraph { - fn new(graph: FirstOutGraph, node_order: Vec) -> ContractionGraph { + fn new(graph: &FirstOutGraph, node_order: Vec) -> ContractionGraph { let n = graph.num_nodes(); let mut node_ranks = vec![0; n]; for (i, &node) in node_order.iter().enumerate() { @@ -164,8 +164,8 @@ impl<'a> PartialContractionGraph<'a> { fn shortcut_required(&self, from: NodeId, to: NodeId, shortcut_weight: Weight) -> bool { let mut server = ::shortest_path::query::bidirectional_dijkstra::Server { - forward_dijkstra: SteppedDijkstra::new(ForwardWrapper { graph: &self }), - backward_dijkstra: SteppedDijkstra::new(BackwardWrapper { graph: &self }), + forward_dijkstra: SteppedDijkstra::new(Box::new(ForwardWrapper { graph: &self })), + backward_dijkstra: SteppedDijkstra::new(Box::new(BackwardWrapper { graph: &self })), tentative_distance: INFINITY, maximum_distance: shortcut_weight, meeting_node: 0 @@ -179,7 +179,7 @@ impl<'a> PartialContractionGraph<'a> { } } -pub fn contract(graph: FirstOutGraph, node_order: Vec) -> ((FirstOutGraph, FirstOutGraph), Option<(Vec, Vec)>) { +pub fn contract(graph: &FirstOutGraph, node_order: Vec) -> ((FirstOutGraph, FirstOutGraph), Option<(Vec, Vec)>) { let mut graph = ContractionGraph::new(graph, node_order); graph.contract(); graph.as_first_out_graphs() diff --git a/engine/src/shortest_path/query/async/bidirectional_dijkstra.rs b/engine/src/shortest_path/query/async/bidirectional_dijkstra.rs index 31be2240..cca82460 100644 --- a/engine/src/shortest_path/query/async/bidirectional_dijkstra.rs +++ b/engine/src/shortest_path/query/async/bidirectional_dijkstra.rs @@ -4,6 +4,7 @@ use std::ptr; use std::sync::{Arc, Barrier}; use std::sync::atomic::compiler_fence; use std::sync::atomic::Ordering::SeqCst; +use std::ops::Deref; use shortest_path::timestamped_vector::TimestampedVector; @@ -28,7 +29,7 @@ pub struct Server { } impl Server { - pub fn new(graph: Graph) -> Server { + pub fn new>(graph: C) -> Server { let (forward_query_sender, forward_query_receiver) = channel(); let (forward_progress_sender, forward_progress_receiver) = channel(); let (backward_query_sender, backward_query_receiver) = channel(); @@ -79,7 +80,7 @@ impl Server { }); thread::spawn(move || { - let mut dijkstra = SteppedDijkstra::new(reversed); + let mut dijkstra = SteppedDijkstra::new(Box::new(reversed)); unsafe { *backward_distances_pointer.pointer = dijkstra.distances_pointer() }; compiler_fence(SeqCst); diff --git a/engine/src/shortest_path/query/async/dijkstra.rs b/engine/src/shortest_path/query/async/dijkstra.rs index 5864d171..66e4f81d 100644 --- a/engine/src/shortest_path/query/async/dijkstra.rs +++ b/engine/src/shortest_path/query/async/dijkstra.rs @@ -1,5 +1,7 @@ use super::*; +use std::ops::Deref; + #[derive(Debug)] pub struct Server { query_sender: Sender, @@ -7,7 +9,7 @@ pub struct Server { } impl Server { - pub fn new(graph: Graph) -> Server { + pub fn new>(graph: C) -> Server { let (query_sender, query_receiver) = channel(); let (progress_sender, progress_receiver) = channel(); diff --git a/engine/src/shortest_path/query/bidirectional_dijkstra.rs b/engine/src/shortest_path/query/bidirectional_dijkstra.rs index 8e3e5525..0317b4c0 100644 --- a/engine/src/shortest_path/query/bidirectional_dijkstra.rs +++ b/engine/src/shortest_path/query/bidirectional_dijkstra.rs @@ -1,28 +1,32 @@ use std::collections::LinkedList; +use std::ops::Deref; + use super::*; #[derive(Debug)] -pub struct Server { - pub forward_dijkstra: SteppedDijkstra, - pub backward_dijkstra: SteppedDijkstra, +pub struct Server> { + pub forward_dijkstra: SteppedDijkstra, + pub backward_dijkstra: SteppedDijkstra>, pub tentative_distance: Weight, pub maximum_distance: Weight, pub meeting_node: NodeId } -impl Server { - pub fn new(graph: Graph) -> Server { +impl> Server { + pub fn new(graph: C) -> Server { let reversed = graph.reverse(); Server { forward_dijkstra: SteppedDijkstra::new(graph), - backward_dijkstra: SteppedDijkstra::new(reversed), + backward_dijkstra: SteppedDijkstra::new(Box::new(reversed)), tentative_distance: INFINITY, maximum_distance: INFINITY, meeting_node: 0 } } +} +impl> Server { pub fn distance(&mut self, from: NodeId, to: NodeId) -> Option { // initialize self.tentative_distance = INFINITY; diff --git a/engine/src/shortest_path/query/contraction_hierarchy.rs b/engine/src/shortest_path/query/contraction_hierarchy.rs index 3f84d100..f1bff498 100644 --- a/engine/src/shortest_path/query/contraction_hierarchy.rs +++ b/engine/src/shortest_path/query/contraction_hierarchy.rs @@ -3,8 +3,8 @@ use super::*; #[derive(Debug)] pub struct Server { - forward_dijkstra: SteppedDijkstra, - backward_dijkstra: SteppedDijkstra, + forward_dijkstra: SteppedDijkstra>, + backward_dijkstra: SteppedDijkstra>, tentative_distance: Weight, meeting_node: NodeId, shortcut_middle_nodes: Option<(Vec, Vec)> @@ -13,8 +13,8 @@ pub struct Server { impl Server { pub fn new(((up, down), shortcut_middle_nodes): ((Graph, Graph), Option<(Vec, Vec)>)) -> Server { Server { - forward_dijkstra: SteppedDijkstra::new(up), - backward_dijkstra: SteppedDijkstra::new(down), + forward_dijkstra: SteppedDijkstra::new(Box::new(up)), + backward_dijkstra: SteppedDijkstra::new(Box::new(down)), tentative_distance: INFINITY, meeting_node: 0, shortcut_middle_nodes diff --git a/engine/src/shortest_path/query/dijkstra.rs b/engine/src/shortest_path/query/dijkstra.rs index b24caa39..fa327d39 100644 --- a/engine/src/shortest_path/query/dijkstra.rs +++ b/engine/src/shortest_path/query/dijkstra.rs @@ -1,14 +1,15 @@ use super::*; +use std::ops::Deref; use std::collections::LinkedList; #[derive(Debug)] -pub struct Server { - dijkstra: SteppedDijkstra, +pub struct Server> { + dijkstra: SteppedDijkstra, } -impl Server { - pub fn new(graph: Graph) -> Server { +impl> Server { + pub fn new(graph: C) -> Server { Server { dijkstra: SteppedDijkstra::new(graph) } diff --git a/engine/src/shortest_path/stepped_dijkstra.rs b/engine/src/shortest_path/stepped_dijkstra.rs index 8e567c21..dacd3108 100644 --- a/engine/src/shortest_path/stepped_dijkstra.rs +++ b/engine/src/shortest_path/stepped_dijkstra.rs @@ -1,4 +1,5 @@ use super::*; +use std::ops::Deref; use index_heap::{IndexdMinHeap, Indexing}; use super::timestamped_vector::TimestampedVector; @@ -21,8 +22,8 @@ impl Indexing for State { } #[derive(Debug)] -pub struct SteppedDijkstra { - graph: Graph, +pub struct SteppedDijkstra> { + graph: C, distances: TimestampedVector, predecessors: Vec, closest_node_priority_queue: IndexdMinHeap, @@ -32,8 +33,8 @@ pub struct SteppedDijkstra { result: Option> } -impl SteppedDijkstra { - pub fn new(graph: Graph) -> SteppedDijkstra { +impl> SteppedDijkstra { + pub fn new(graph: C) -> SteppedDijkstra { let n = graph.num_nodes(); SteppedDijkstra { diff --git a/search_space_visualization/src/main.rs b/search_space_visualization/src/main.rs index 21663e6f..ca21fdbc 100644 --- a/search_space_visualization/src/main.rs +++ b/search_space_visualization/src/main.rs @@ -10,6 +10,7 @@ use std::env; use std::path::Path; use std::cmp::max; use std::cmp::Ordering; +use std::rc::Rc; use bmw_routing_engine::*; use graph::first_out_graph::FirstOutGraph as Graph; @@ -82,8 +83,8 @@ fn main() { let head = read_into_vector(path.join("head").to_str().unwrap()).expect("could not read head"); let travel_time = read_into_vector(path.join("travel_time").to_str().unwrap()).expect("could not read travel_time"); - let graph = Graph::new(first_out, head, travel_time); - let mut query_server = DijkServer::::new(graph.clone()); + let graph = Rc::new(Graph::new(first_out, head, travel_time)); + let mut query_server = DijkServer::new(graph.clone()); let find_closest = |(p_lat, p_lon): (f32, f32)| -> NodeId { lat.iter().zip(lon.iter()).enumerate().min_by_key(|&(_, (lat, lon))| { diff --git a/server/src/main.rs b/server/src/main.rs index 3044c705..05a11d17 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -45,7 +45,7 @@ impl Ord for NonNan { #[derive(Debug)] struct RoutingWrapper { - server: shortest_path::query::bidirectional_dijkstra::Server, + server: shortest_path::query::bidirectional_dijkstra::Server>, lat: Vec, lng: Vec } @@ -118,7 +118,7 @@ fn main() { let lng = read_into_vector(path.join("longitude").to_str().unwrap()).expect("could not read first_out"); let wrapper = RoutingWrapper { - server: shortest_path::query::bidirectional_dijkstra::Server::::new(graph), lat, lng + server: shortest_path::query::bidirectional_dijkstra::Server::new(Box::new(graph)), lat, lng }; let config = rocket::config::Config::build(rocket::config::Environment::Staging)