-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pre-filter turn restrictions for validity
- Loading branch information
Moritz Kobitzsch
committed
Jul 31, 2017
1 parent
2e9a7d9
commit b1809d1
Showing
4 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
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,23 @@ | ||
#ifndef OSRM_EXTRACTOR_RESTRICTION_FILTER_HPP_ | ||
#define OSRM_EXTRACTOR_RESTRICTION_FILTER_HPP_ | ||
|
||
#include "extractor/restriction.hpp" | ||
#include "util/node_based_graph.hpp" | ||
|
||
#include <vector> | ||
|
||
namespace osrm | ||
{ | ||
namespace extractor | ||
{ | ||
|
||
// To avoid handling invalid restrictions / creating unnecessary duplicate nodes for via-ways, we do | ||
// a pre-flight check for restrictions and remove all invalid restrictions from the data. Use as | ||
// `restrictions = removeInvalidRestrictions(std::move(restrictions))` | ||
std::vector<TurnRestriction> removeInvalidRestrictions(std::vector<TurnRestriction>, | ||
const util::NodeBasedDynamicGraph &); | ||
|
||
} // namespace extractor | ||
} // namespace osrm | ||
|
||
#endif // OSRM_EXTRACTOR_RESTRICTION_FILTER_HPP_ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include "extractor/restriction_filter.hpp" | ||
#include "util/node_based_graph.hpp" | ||
#include "util/typedefs.hpp" | ||
|
||
#include <algorithm> | ||
#include <boost/assert.hpp> | ||
|
||
namespace osrm | ||
{ | ||
namespace extractor | ||
{ | ||
|
||
std::vector<TurnRestriction> | ||
removeInvalidRestrictions(std::vector<TurnRestriction> restrictions, | ||
const util::NodeBasedDynamicGraph &node_based_graph) | ||
{ | ||
// definition of what we presume to be a valid via-node restriction | ||
const auto is_valid_node = [&node_based_graph](const auto &node_restriction) { | ||
// a valid restriction needs to be connected to both its from and to locations | ||
bool found_from = false, found_to = false; | ||
for (auto eid : node_based_graph.GetAdjacentEdgeRange(node_restriction.via)) | ||
{ | ||
const auto target = node_based_graph.GetTarget(eid); | ||
if (target == node_restriction.from) | ||
found_from = true; | ||
if (target == node_restriction.to) | ||
found_to = true; | ||
} | ||
|
||
if (!found_from || !found_to) | ||
return false; | ||
|
||
return true; | ||
}; | ||
|
||
// definition of what we presume to be a valid via-way restriction | ||
const auto is_valid_way = [&node_based_graph, is_valid_node](const auto &way_restriction) { | ||
const auto eid = node_based_graph.FindEdge(way_restriction.in_restriction.via, | ||
way_restriction.out_restriction.via); | ||
|
||
// ability filter, we currently cannot handle restrictions that do not match up in geometry: | ||
// restrictions cannot be interrupted by traffic signals or other similar entities that | ||
// cause node penalties | ||
if ((way_restriction.in_restriction.via != way_restriction.out_restriction.from) || | ||
(way_restriction.out_restriction.via != way_restriction.in_restriction.to)) | ||
return false; | ||
|
||
// the edge needs to exit (we cannot handle intermediate stuff, so far) | ||
if (eid == SPECIAL_EDGEID) | ||
return false; | ||
|
||
const auto &data = node_based_graph.GetEdgeData(eid); | ||
|
||
// edge needs to be traversable for a valid restrction | ||
if (data.reversed) | ||
return false; | ||
|
||
// is the in restriction referencing the correct nodes | ||
if (!is_valid_node(way_restriction.in_restriction)) | ||
return false; | ||
|
||
// is the out restriction referencing the correct nodes | ||
if (!is_valid_node(way_restriction.out_restriction)) | ||
return false; | ||
|
||
return true; | ||
}; | ||
|
||
const auto is_invalid = [is_valid_way, is_valid_node](const auto &restriction) { | ||
if (restriction.Type() == RestrictionType::NODE_RESTRICTION) | ||
{ | ||
return !is_valid_node(restriction.AsNodeRestriction()); | ||
} | ||
else | ||
{ | ||
BOOST_ASSERT(restriction.Type() == RestrictionType::WAY_RESTRICTION); | ||
return !is_valid_way(restriction.AsWayRestriction()); | ||
} | ||
}; | ||
|
||
restrictions.erase(std::remove_if(restrictions.begin(), restrictions.end(), is_invalid), | ||
restrictions.end()); | ||
|
||
return restrictions; | ||
} | ||
|
||
} // namespace extractor | ||
} // namespace osrm |