-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Grand Unified Obstacle Treatment #7130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Grand Unified Obstacle Treatment #7130
Conversation
Thanks so much for the pull request. This looks very nice, indeed. I love the simplification of the code, the documentation, and the added tests look well written at first glance. Once CI passes, I will do a deeper review. From the first impression, this patch has a high chance of getting merged. Well done. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me. Left some minor comments that should be easy to address. The only bigger question is around the use of the extern
keyword which should be avoided. Again, thanks so much for the contribution.
RoadPriorityClass::Enum priority_class; | ||
bool is_incoming; | ||
bool is_outgoing; | ||
}; | ||
|
||
extern const std::vector<ExtractionTurnLeg> NO_OTHER_ROADS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the extern keyword needed here? We should avoid it, if possible, since it implies a global variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
// | ||
// This may be a completely impassable obstacle like a barrier, a temporary obstacle | ||
// like a traffic light or a stop sign, or an obstacle that just slows you down like a | ||
// traffic calming bump. The obstacle may be present in both directions or in one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// traffic calming bump. The obstacle may be present in both directions or in one | |
// traffic calming bump. The obstacle may be present in both directions or in one |
include/extractor/obstacles.hpp
Outdated
// | ||
struct Obstacle | ||
{ | ||
// clang-format off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How bad does it look with formatting on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
// The type of an obstacle | ||
// Note: must be kept in sync with scripting_environment_lua.cpp | ||
enum class Type : uint16_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance to factor this out into the same header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try. But then it is the same story with all enums passed to sol / LUA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, then let's not overthink it. We can leave the enum as is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to pull it into the obstacles.cpp file but not into the header. In the header I had to use a constexpr, but the Microsoft compiler choked on it.
include/extractor/obstacles.hpp
Outdated
// pass SPECIAL_NODEID as 'from' to get all obstacles at 'to' | ||
// 'type' can be a bitwise-or combination of Obstacle::Type | ||
using GetType = | ||
boost::any_range<Obstacle, boost::forward_traversal_tag, Obstacle, std::ptrdiff_t>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance to implement this without boost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sol does not recognize a std::ranges::subrange as a container. It did recognize a boost::any_range though. As a compromise I used a std::vector hoping the performance hit is not too bad.
profiles/lib/obstacles.lua
Outdated
@@ -0,0 +1,53 @@ | |||
-- Assigns obstacle value to node as defined by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- Assigns obstacle value to node as defined by | |
-- Assigns obstacle value to nodes as defined by |
profiles/lib/obstacles.lua
Outdated
function Obstacles.process_node(profile, node) | ||
local highway = node:get_value_by_key("highway") | ||
if highway then | ||
local typ = obstacle_type[highway] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the variable name be type
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought type
was reserved in LUA, but it is not. Will change.
src/extractor/obstacles.cpp
Outdated
|
||
void ObstacleMap::fixupNodes(const NodeIDVector &node_ids) | ||
{ | ||
const NodeIDVector::const_iterator begin = node_ids.cbegin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps use the auto
keyword?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 well done
@@ -99,11 +99,12 @@ void handle_lua_error(const sol::protected_function_result &luares) | |||
const auto msg = luaerr.what(); | |||
if (msg != nullptr) | |||
{ | |||
std::cerr << msg << "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is why some tests are flaky. std::cerr
is not thread-safe.
* Grand Unified Obstacle Treatment * add changelog * Address comments * fix formatting * fix ci * fix ci * fix ci * simplify ObstacleMap::get
Issue
Currently OSRM:
This patch
signs, barriers, traffic calming, and turning points,
Related work
Similar to pull requests: #6426, #6153, #4828. Thanks to their authors, who gave many ideas.
Fixes issue: #7089
Implementation description
A class
ObstacleMap
singleton is injected globally into the LUA scripting environment.The
ObstacleMap
offers functions to add and query different kinds of 'obstacle' nodes.(For want of a better name since 'waypoint' was already taken.)
The LUA
process_node()
function (repeatedly) callsObstacleMap::add()
to registerdiscovered obstacles. This function is thread safe. The data is directly stored in the
final place and not moved again after.
A compatibilty layer for
process_node()
has been provided to emulate the currentbehaviour: to return
result.barrier
andresult.traffic_signal
.The LUA
process_turn()
function can callObstacleMap::any()
andObstacleMap::get()
toretrieve registered obstacles.
The length of the road has been added to the
ExtractionTurnLeg
LUA table and legs forthe start and target roads have been added to
ExtractionTurn
(a parameter ofprocess_turn()
).Tasklist