-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from NREL/rjf/ksp-algorithm
support for algorithms with multiple trees/routes
- Loading branch information
Showing
25 changed files
with
509 additions
and
645 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
rust/routee-compass-core/src/algorithm/search/ksp/ksp_single_via_paths.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::{ | ||
algorithm::search::{ | ||
search_algorithm::SearchAlgorithm, search_error::SearchError, | ||
search_instance::SearchInstance, search_result::SearchResult, | ||
}, | ||
model::road_network::vertex_id::VertexId, | ||
}; | ||
|
||
pub fn run_ksp( | ||
_source: VertexId, | ||
_target: Option<VertexId>, | ||
_si: &SearchInstance, | ||
_underlying: Box<SearchAlgorithm>, | ||
) -> Result<Vec<SearchResult>, SearchError> { | ||
todo!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod ksp_single_via_paths; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 61 additions & 21 deletions
82
rust/routee-compass-core/src/algorithm/search/search_algorithm.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,88 @@ | ||
use super::a_star::a_star_algorithm; | ||
use super::backtrack; | ||
use super::search_algorithm_result::SearchAlgorithmResult; | ||
use super::search_error::SearchError; | ||
use super::search_instance::SearchInstance; | ||
use super::search_result::SearchResult; | ||
use crate::algorithm::search::search_algorithm_type::SearchAlgorithmType; | ||
use crate::model::road_network::{edge_id::EdgeId, vertex_id::VertexId}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(rename_all = "snake_case", tag = "type")] | ||
pub enum SearchAlgorithm { | ||
#[serde(rename = "a*")] | ||
AStarAlgorithm, | ||
} | ||
|
||
impl TryFrom<&serde_json::Value> for SearchAlgorithm { | ||
type Error = SearchError; | ||
|
||
fn try_from(config: &serde_json::Value) -> Result<Self, Self::Error> { | ||
let alg_type: SearchAlgorithmType = config.try_into()?; | ||
match alg_type { | ||
SearchAlgorithmType::AStar => Ok(SearchAlgorithm::AStarAlgorithm), | ||
} | ||
} | ||
KspSingleVia { | ||
k: usize, | ||
underlying: Box<SearchAlgorithm>, | ||
}, | ||
} | ||
|
||
impl SearchAlgorithm { | ||
pub fn run_vertex_oriented( | ||
&self, | ||
origin: VertexId, | ||
destination: Option<VertexId>, | ||
src_id: VertexId, | ||
dst_id_opt: Option<VertexId>, | ||
search_instance: &SearchInstance, | ||
) -> Result<SearchResult, SearchError> { | ||
) -> Result<SearchAlgorithmResult, SearchError> { | ||
match self { | ||
SearchAlgorithm::AStarAlgorithm => { | ||
a_star_algorithm::run_a_star(origin, destination, search_instance) | ||
let search_result = | ||
a_star_algorithm::run_a_star(src_id, dst_id_opt, search_instance)?; | ||
let routes = match dst_id_opt { | ||
None => vec![], | ||
Some(dst_id) => { | ||
let route = | ||
backtrack::vertex_oriented_route(src_id, dst_id, &search_result.tree)?; | ||
vec![route] | ||
} | ||
}; | ||
Ok(SearchAlgorithmResult { | ||
trees: vec![search_result.tree], | ||
routes, | ||
iterations: search_result.iterations, | ||
}) | ||
} | ||
SearchAlgorithm::KspSingleVia { | ||
k: _, | ||
underlying: _, | ||
} => todo!(), | ||
} | ||
} | ||
pub fn run_edge_oriented( | ||
&self, | ||
origin: EdgeId, | ||
destination: Option<EdgeId>, | ||
src_id: EdgeId, | ||
dst_id_opt: Option<EdgeId>, | ||
search_instance: &SearchInstance, | ||
) -> Result<SearchResult, SearchError> { | ||
) -> Result<SearchAlgorithmResult, SearchError> { | ||
match self { | ||
SearchAlgorithm::AStarAlgorithm => { | ||
a_star_algorithm::run_a_star_edge_oriented(origin, destination, search_instance) | ||
let search_result = a_star_algorithm::run_a_star_edge_oriented( | ||
src_id, | ||
dst_id_opt, | ||
search_instance, | ||
)?; | ||
let routes = match dst_id_opt { | ||
None => vec![], | ||
Some(dst_id) => { | ||
let route = backtrack::edge_oriented_route( | ||
src_id, | ||
dst_id, | ||
&search_result.tree, | ||
search_instance.directed_graph.clone(), | ||
)?; | ||
vec![route] | ||
} | ||
}; | ||
Ok(SearchAlgorithmResult { | ||
trees: vec![search_result.tree], | ||
routes, | ||
iterations: search_result.iterations, | ||
}) | ||
} | ||
SearchAlgorithm::KspSingleVia { | ||
k: _, | ||
underlying: _, | ||
} => todo!(), | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
rust/routee-compass-core/src/algorithm/search/search_algorithm_result.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use super::{edge_traversal::EdgeTraversal, search_tree_branch::SearchTreeBranch}; | ||
use crate::model::road_network::vertex_id::VertexId; | ||
use std::collections::HashMap; | ||
|
||
pub struct SearchAlgorithmResult { | ||
pub trees: Vec<HashMap<VertexId, SearchTreeBranch>>, | ||
pub routes: Vec<Vec<EdgeTraversal>>, | ||
pub iterations: u64, | ||
} |
56 changes: 0 additions & 56 deletions
56
rust/routee-compass-core/src/algorithm/search/search_algorithm_type.rs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
rust/routee-compass/src/app/compass/test/speeds_test/edge_geometries.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
LINESTRING (-105.1683038 39.7379033, -104.8086039 41.1475252) | ||
LINESTRING (-105.1683038 39.7379033, -111.9095014 40.7607176) | ||
LINESTRING (-104.8086039 41.1475252, -111.9095014 40.7607176) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.