Skip to content

Commit

Permalink
Merge pull request #267 from NREL/rjf/bug-route-on-empty-tree
Browse files Browse the repository at this point in the history
Rjf/bug route on empty tree
  • Loading branch information
robfitzgerald authored Dec 12, 2024
2 parents feae3ad + 0e069a0 commit edbf7e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ pub fn run_a_star_edge_oriented(
.get(&e2_src)
.ok_or_else(|| {
SearchError::InternalError(format!(
"resulting tree missing vertex {} expected via backtrack",
e2_src
))
"resulting tree with {} branches missing vertex {} expected via backtrack",
tree.len(),
e2_src
))
})?
.edge_traversal
.result_state;
Expand Down
15 changes: 10 additions & 5 deletions rust/routee-compass-core/src/algorithm/search/backtrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ pub fn vertex_oriented_route(
target_id: VertexId,
solution: &HashMap<VertexId, SearchTreeBranch>,
) -> Result<Vec<EdgeTraversal>, SearchError> {
if solution.is_empty() {
return Ok(vec![]);
}

let mut result: Vec<EdgeTraversal> = vec![];
let mut visited: HashSet<EdgeId> = HashSet::new();
let mut this_vertex = target_id;
loop {
if this_vertex == source_id {
break;
}
let traversal = solution
.get(&this_vertex)
.ok_or(SearchError::InternalError(format!(
"resulting tree missing vertex {} expected via backtrack",
let traversal = solution.get(&this_vertex).ok_or_else(|| {
SearchError::InternalError(format!(
"resulting tree with {} branches missing vertex {} expected via backtrack",
solution.len(),
this_vertex
)))?;
))
})?;
let first_visit = visited.insert(traversal.edge_traversal.edge_id);
if !first_visit {
return Err(SearchError::InternalError(format!(
Expand Down

0 comments on commit edbf7e0

Please sign in to comment.