Skip to content

Commit

Permalink
destonly needs to be a separate EdgeLabel property because transition…
Browse files Browse the repository at this point in the history
…_cost relies on it
  • Loading branch information
nilsnolde committed Mar 19, 2024
1 parent 997a40f commit d990027
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 91 deletions.
27 changes: 14 additions & 13 deletions src/thor/bidirectional_astar.cc
Expand Up @@ -318,15 +318,14 @@ inline bool BidirectionalAStar::ExpandInner(baldr::GraphReader& graphreader,
// It will be used by hierarchy limits
dist = astarheuristic_reverse_.GetDistance(t2->get_node_ll(meta.edge->endnode()));
}
bool is_destonly = meta.edge->destonly() || (costing_->is_hgv() && meta.edge->destonly_hgv());
edgelabels_forward_.emplace_back(pred_idx, meta.edge_id, opp_edge_id, meta.edge, newcost,
sortcost, dist, mode_, transition_cost, not_thru_pruning,
pred.closure_pruning() || !(costing_->IsClosed(meta.edge, tile)),
pred.destonly_pruning() ||
!(meta.edge->destonly() ||
(costing_->is_hgv() && meta.edge->destonly_hgv())),
pred.destonly_pruning() || !is_destonly,
static_cast<bool>(flow_sources & kDefaultFlowMask),
costing_->TurnType(pred.opp_local_idx(), nodeinfo, meta.edge),
restriction_idx, 0);
restriction_idx, 0, is_destonly);
adjacencylist_forward_.add(idx);
} else {
idx = edgelabels_reverse_.size();
Expand All @@ -335,6 +334,7 @@ inline bool BidirectionalAStar::ExpandInner(baldr::GraphReader& graphreader,
// It will be used by hierarchy limits
dist = astarheuristic_forward_.GetDistance(t2->get_node_ll(meta.edge->endnode()));
}
bool is_destonly = opp_edge->destonly() || (costing_->is_hgv() && opp_edge->destonly_hgv());
edgelabels_reverse_.emplace_back(pred_idx, meta.edge_id, opp_edge_id, meta.edge, newcost,
sortcost, dist, mode_, transition_cost, not_thru_pruning,
pred.closure_pruning() || !(costing_->IsClosed(opp_edge, t2)),
Expand All @@ -344,7 +344,7 @@ inline bool BidirectionalAStar::ExpandInner(baldr::GraphReader& graphreader,
static_cast<bool>(flow_sources & kDefaultFlowMask),
costing_->TurnType(meta.edge->localedgeidx(), nodeinfo, opp_edge,
opp_pred_edge),
restriction_idx, 0);
restriction_idx, 0, is_destonly);
adjacencylist_reverse_.add(idx);
}

Expand Down Expand Up @@ -1007,13 +1007,13 @@ void BidirectionalAStar::SetOrigin(GraphReader& graphreader,
// It will be used by hierarchy limits
dist = astarheuristic_reverse_.GetDistance(nodeinfo->latlng(endtile->header()->base_ll()));
}
bool is_destonly =
directededge->destonly() || (costing_->is_hgv() && directededge->destonly_hgv());
edgelabels_forward_.emplace_back(kInvalidLabel, edgeid, directededge, cost, sortcost, dist, mode_,
baldr::kInvalidRestriction,
!(costing_->IsClosed(directededge, tile)),
!(directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv())),
!(costing_->IsClosed(directededge, tile)), !is_destonly,
static_cast<bool>(flow_sources & kDefaultFlowMask),
sif::InternalTurn::kNoTurn);
sif::InternalTurn::kNoTurn, is_destonly);
adjacencylist_forward_.add(idx);

// setting this edge as reached
Expand Down Expand Up @@ -1108,12 +1108,13 @@ void BidirectionalAStar::SetDestination(GraphReader& graphreader,
// It will be used by hierarchy limits
dist = astarheuristic_forward_.GetDistance(tile->get_node_ll(opp_dir_edge->endnode()));
}
bool is_destonly =
directededge->destonly() || (costing_->is_hgv() && directededge->destonly_hgv());
edgelabels_reverse_.emplace_back(kInvalidLabel, opp_edge_id, edgeid, opp_dir_edge, cost, sortcost,
dist, mode_, c, false, !(costing_->IsClosed(directededge, tile)),
!(directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv())),
static_cast<bool>(flow_sources & kDefaultFlowMask),
sif::InternalTurn::kNoTurn, baldr::kInvalidRestriction);
!is_destonly, static_cast<bool>(flow_sources & kDefaultFlowMask),
sif::InternalTurn::kNoTurn, baldr::kInvalidRestriction,
is_destonly);
adjacencylist_reverse_.add(idx);

// setting this edge as reached, sending the opposing because this is the reverse tree
Expand Down
14 changes: 6 additions & 8 deletions src/thor/costmatrix.cc
Expand Up @@ -518,26 +518,24 @@ bool CostMatrix::ExpandInner(baldr::GraphReader& graphreader,
uint32_t idx = edgelabels.size();
*meta.edge_status = {EdgeSet::kTemporary, idx};
if (FORWARD) {
bool is_destonly = meta.edge->destonly() || (costing_->is_hgv() && meta.edge->destonly_hgv());
edgelabels.emplace_back(pred_idx, meta.edge_id, opp_edge_id, meta.edge, newcost, mode_, tc,
pred_dist, not_thru_pruning,
pred.closure_pruning() || !(costing_->IsClosed(meta.edge, tile)),
pred.destonly_pruning() ||
!(meta.edge->destonly() ||
(costing_->is_hgv() && meta.edge->destonly_hgv())),
pred.destonly_pruning() || !is_destonly,
static_cast<bool>(flow_sources & kDefaultFlowMask),
costing_->TurnType(pred.opp_local_idx(), nodeinfo, meta.edge),
restriction_idx, 0);
restriction_idx, 0, is_destonly);
} else {
bool is_destonly = opp_edge->destonly() || (costing_->is_hgv() && opp_edge->destonly_hgv());
edgelabels.emplace_back(pred_idx, meta.edge_id, opp_edge_id, meta.edge, newcost, mode_, tc,
pred_dist, not_thru_pruning,
pred.closure_pruning() || !(costing_->IsClosed(opp_edge, t2)),
pred.destonly_pruning() ||
!(opp_edge->destonly() ||
(costing_->is_hgv() && opp_edge->destonly_hgv())),
pred.destonly_pruning() || !is_destonly,
static_cast<bool>(flow_sources & kDefaultFlowMask),
costing_->TurnType(meta.edge->localedgeidx(), nodeinfo, opp_edge,
opp_pred_edge),
restriction_idx, 0);
restriction_idx, 0, is_destonly);
}
adj.add(idx);
// mark the edge as settled for the connection check
Expand Down
26 changes: 13 additions & 13 deletions src/thor/dijkstras.cc
Expand Up @@ -250,27 +250,26 @@ void Dijkstras::ExpandInner(baldr::GraphReader& graphreader,
uint32_t idx = bdedgelabels_.size();
*es = {EdgeSet::kTemporary, idx};
if (FORWARD) {
bool is_destonly =
directededge->destonly() || (costing_->is_hgv() && directededge->destonly_hgv());
bdedgelabels_.emplace_back(pred_idx, edgeid, oppedgeid, directededge, newcost, mode_,
transition_cost, path_dist, not_thru_pruning,
pred.closure_pruning() || !costing_->IsClosed(directededge, tile),
pred.destonly_pruning() ||
!(directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv())),
pred.destonly_pruning() || !is_destonly,
static_cast<bool>(flow_sources & kDefaultFlowMask),
costing_->TurnType(pred.opp_local_idx(), nodeinfo, directededge),
restriction_idx, pred.path_id());
restriction_idx, pred.path_id(), is_destonly);

} else {
bool is_destonly = opp_edge->destonly() || (costing_->is_hgv() && opp_edge->destonly_hgv());
bdedgelabels_.emplace_back(pred_idx, edgeid, oppedgeid, directededge, newcost, mode_,
transition_cost, path_dist, not_thru_pruning,
pred.closure_pruning() || !costing_->IsClosed(opp_edge, tile),
pred.destonly_pruning() ||
!(opp_edge->destonly() ||
(costing_->is_hgv() && opp_edge->destonly_hgv())),
pred.closure_pruning() || !costing_->IsClosed(opp_edge, t2),
pred.destonly_pruning() || !is_destonly,
static_cast<bool>(flow_sources & kDefaultFlowMask),
costing_->TurnType(directededge->localedgeidx(), nodeinfo, opp_edge,
opp_pred_edge),
restriction_idx, pred.path_id());
restriction_idx, pred.path_id(), is_destonly);
}
adjacencylist_.add(idx);
}
Expand Down Expand Up @@ -908,6 +907,8 @@ void Dijkstras::SetDestinationLocations(
// edge (edgeid) is set.
uint32_t idx = bdedgelabels_.size();
int restriction_idx = kInvalidRestriction;
bool is_destonly =
directededge->destonly() || (costing_->is_hgv() && directededge->destonly_hgv());
// TODO: When running expansion in reverse, handle the case where the
// destination lies on a closure but the expansion started from an open
// edge. Currently, we begin with closure prunning turned on and hence
Expand All @@ -917,10 +918,9 @@ void Dijkstras::SetDestinationLocations(
// consecutive edges)
bdedgelabels_.emplace_back(kInvalidLabel, opp_edge_id, edgeid, opp_dir_edge, cost, mode_,
Cost{}, path_dist, false, !(costing_->IsClosed(directededge, tile)),
!(directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv())),
static_cast<bool>(flow_sources & kDefaultFlowMask),
InternalTurn::kNoTurn, restriction_idx, multipath_ ? path_id : 0);
!is_destonly, static_cast<bool>(flow_sources & kDefaultFlowMask),
InternalTurn::kNoTurn, restriction_idx, multipath_ ? path_id : 0,
is_destonly);
adjacencylist_.add(idx);
edgestatus_.Set(opp_edge_id, EdgeSet::kTemporary, idx, opp_tile, multipath_ ? path_id : 0);
}
Expand Down
28 changes: 14 additions & 14 deletions src/thor/timedistancematrix.cc
Expand Up @@ -154,23 +154,25 @@ void TimeDistanceMatrix::Expand(GraphReader& graphreader,
bool not_thru_pruning = pred.not_thru_pruning() || !directededge->not_thru();

if (FORWARD) {
bool is_destonly =
directededge->destonly() || (costing_->is_hgv() && directededge->destonly_hgv());
edgelabels_.emplace_back(pred_idx, edgeid, directededge, newcost, newcost.cost, mode_,
path_distance, restriction_idx, not_thru_pruning,
(pred.closure_pruning() || !(costing_->IsClosed(directededge, tile))),
directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv()),
pred.destonly_pruning() || !is_destonly,
0 != (flow_sources & kDefaultFlowMask),
costing_->TurnType(pred.opp_local_idx(), nodeinfo, directededge), 0);
costing_->TurnType(pred.opp_local_idx(), nodeinfo, directededge), 0,
is_destonly);
} else {
bool is_destonly = opp_edge->destonly() || (costing_->is_hgv() && opp_edge->destonly_hgv());
edgelabels_.emplace_back(pred_idx, edgeid, directededge, newcost, newcost.cost, mode_,
path_distance, restriction_idx, not_thru_pruning,
(pred.closure_pruning() || !(costing_->IsClosed(opp_edge, t2))),
opp_edge->destonly() ||
(costing_->is_hgv() && opp_edge->destonly_hgv()),
pred.destonly_pruning() || !is_destonly,
0 != (flow_sources & kDefaultFlowMask),
costing_->TurnType(directededge->localedgeidx(), nodeinfo, opp_edge,
opp_pred_edge),
0);
0, is_destonly);
}

*es = {EdgeSet::kTemporary, idx};
Expand Down Expand Up @@ -372,22 +374,20 @@ void TimeDistanceMatrix::SetOrigin(GraphReader& graphreader,
// Add EdgeLabel to the adjacency list (but do not set its status).
// Set the predecessor edge index to invalid to indicate the origin
// of the path. Set the origin flag
bool is_destonly =
directededge->destonly() || (costing_->is_hgv() && directededge->destonly_hgv());
if (FORWARD) {
edgelabels_.emplace_back(kInvalidLabel, edgeid, directededge, cost, cost.cost, mode_, dist,
baldr::kInvalidRestriction, false,
!costing_->IsClosed(directededge, tile),
!(directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv())),
!costing_->IsClosed(directededge, tile), !is_destonly,
static_cast<bool>(flow_sources & kDefaultFlowMask),
InternalTurn::kNoTurn, 0);
InternalTurn::kNoTurn, 0, is_destonly);
} else {
edgelabels_.emplace_back(kInvalidLabel, opp_edge_id, opp_dir_edge, cost, cost.cost, mode_, dist,
baldr::kInvalidRestriction, false,
!costing_->IsClosed(directededge, tile),
!(directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv())),
!costing_->IsClosed(directededge, tile), !is_destonly,
static_cast<bool>(flow_sources & kDefaultFlowMask),
InternalTurn::kNoTurn, 0);
InternalTurn::kNoTurn, 0, is_destonly);
}
edgelabels_.back().set_origin();
adjacencylist_.add(edgelabels_.size() - 1);
Expand Down
29 changes: 12 additions & 17 deletions src/thor/unidirectional_astar.cc
Expand Up @@ -271,26 +271,24 @@ inline bool UnidirectionalAStar<expansion_direction, FORWARD>::ExpandInner(
bool not_thru_pruning = pred.not_thru_pruning() || !meta.edge->not_thru();

if (FORWARD) {
bool is_destonly = meta.edge->destonly() || (costing_->is_hgv() && meta.edge->destonly_hgv());
edgelabels_.emplace_back(pred_idx, meta.edge_id, opp_edge_id, meta.edge, cost, sortcost, dist,
mode_, transition_cost, not_thru_pruning,
(pred.closure_pruning() || !(costing_->IsClosed(meta.edge, tile))),
pred.destonly_pruning() ||
!(meta.edge->destonly() ||
(costing_->is_hgv() && meta.edge->destonly_hgv())),
pred.destonly_pruning() || !is_destonly,
0 != (flow_sources & kDefaultFlowMask),
costing_->TurnType(pred.opp_local_idx(), nodeinfo, meta.edge),
restriction_idx, 0);
restriction_idx, 0, is_destonly);
} else {
bool is_destonly = opp_edge->destonly() || (costing_->is_hgv() && opp_edge->destonly_hgv());
edgelabels_.emplace_back(pred_idx, meta.edge_id, opp_edge_id, meta.edge, cost, sortcost, dist,
mode_, transition_cost, not_thru_pruning,
(pred.closure_pruning() || !(costing_->IsClosed(opp_edge, endtile))),
pred.destonly_pruning() ||
!(opp_edge->destonly() ||
(costing_->is_hgv() && opp_edge->destonly_hgv())),
pred.destonly_pruning() || !is_destonly,
0 != (flow_sources & kDefaultFlowMask),
costing_->TurnType(meta.edge->localedgeidx(), nodeinfo, opp_edge,
opp_pred_edge),
restriction_idx, 0);
restriction_idx, 0, is_destonly);
}

auto& edge_label = edgelabels_.back();
Expand Down Expand Up @@ -754,22 +752,19 @@ void UnidirectionalAStar<expansion_direction, FORWARD>::SetOrigin(

// Add EdgeLabel to the adjacency list
uint32_t idx = edgelabels_.size();

bool is_destonly =
directededge->destonly() || (costing_->is_hgv() && directededge->destonly_hgv());
if (FORWARD) {
edgelabels_.emplace_back(kInvalidLabel, edgeid, GraphId(), directededge, cost, sortcost, dist,
mode_, Cost{}, false, !(costing_->IsClosed(directededge, tile)),
!(directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv())),
0 != (flow_sources & kDefaultFlowMask), sif::InternalTurn::kNoTurn,
kInvalidRestriction, 0);
!is_destonly, 0 != (flow_sources & kDefaultFlowMask),
sif::InternalTurn::kNoTurn, kInvalidRestriction, 0, is_destonly);
} else {
edgelabels_.emplace_back(kInvalidLabel, opp_edge_id, edgeid, opp_dir_edge, cost, sortcost,
dist, mode_, Cost{}, false,
!(costing_->IsClosed(directededge, tile)),
!(directededge->destonly() ||
(costing_->is_hgv() && directededge->destonly_hgv())),
!(costing_->IsClosed(directededge, tile)), !is_destonly,
0 != (flow_sources & kDefaultFlowMask), sif::InternalTurn::kNoTurn,
kInvalidRestriction, 0);
kInvalidRestriction, 0, is_destonly);
}

auto& edge_label = edgelabels_.back();
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Expand Up @@ -184,7 +184,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/utrecht_tiles/traffic.ta
--with-traffic --overwrite
COMMENT "Building Utrecht Tiles..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS valhalla_build_tiles valhalla_add_predicted_traffic build_timezones ${VALHALLA_SOURCE_DIR}/test/data/utrecht_netherlands.osm.pbf ${CMAKE_BINARY_DIR}/valhalla_build_extract)
DEPENDS build_timezones ${VALHALLA_SOURCE_DIR}/test/data/utrecht_netherlands.osm.pbf ${CMAKE_BINARY_DIR}/valhalla_build_extract)
add_custom_target(utrecht_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/utrecht_tiles/traffic.tar)
set_target_properties(utrecht_tiles PROPERTIES FOLDER "Tests")

Expand Down

0 comments on commit d990027

Please sign in to comment.