Skip to content

Commit

Permalink
road_class -> road_priority_class
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Kobitzsch committed Jul 14, 2016
1 parent dd302cf commit b4dc10e
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 110 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 5.4.0
- Profiles
- includes library guidance.lua that offers preliminary configuration on guidance.

# 5.3.0 RC3
Changes from 5.3.0-rc.2
- Guidance
Expand Down
2 changes: 1 addition & 1 deletion docs/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Using the power of the scripting language you wouldn't typically see something a

## Guidance

The guidance parameters in profiles are currently a work in progress. They can and will change without any major version change.
The guidance parameters in profiles are currently a work in progress. They can and will change.
Please be aware of this when using guidance configuration possibilities.

### Road Classification
Expand Down
36 changes: 18 additions & 18 deletions features/guidance/anticipate-lanes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,20 @@ Feature: Turn Lane Guidance
| | | i | | |

And the ways
| nodes | turn:lanes:forward | highway | junction | # |
| nodes | turn:lanes:forward | highway | junction | # |
| ab | slight_right\|slight_right\|slight_right | primary | | |
| bc | slight_left\|slight_right\|slight_right | primary | roundabout | top |
| cd | | primary | roundabout | top |
| de | | primary | roundabout | top |
| eb | | primary | roundabout | top |
| df | | primary | | |
| cg | slight_right\|slight_right | primary | | |
| gh | slight_left\|slight_right | primary | roundabout | bot |
| hi | | primary | roundabout | bot |
| ij | slight_left\|slight_right | primary | roundabout | bot |
| jg | | primary | roundabout | bot |
| hk | | primary | | |
| jl | | primary | | |
| cd | | primary | roundabout | top |
| de | | primary | roundabout | top |
| eb | | primary | roundabout | top |
| df | | primary | | |
| cg | slight_right\|slight_right | primary | | |
| gh | slight_left\|slight_right | primary | roundabout | bot |
| hi | | primary | roundabout | bot |
| ij | slight_left\|slight_right | primary | roundabout | bot |
| jg | | primary | roundabout | bot |
| hk | | primary | | |
| jl | | primary | | |

When I route I should get
| # | waypoints | route | turns | lanes |
Expand All @@ -301,13 +301,13 @@ Feature: Turn Lane Guidance
| | | c | | |

And the ways
| nodes | turn:lanes:forward | highway | junction |
| ab | | primary | |
| bc | | primary | roundabout |
| nodes | turn:lanes:forward | highway | junction |
| ab | | primary | |
| bc | | primary | roundabout |
| cd | slight_left\|slight_left\|slight_right | primary | roundabout |
| de | | primary | roundabout |
| eb | | primary | roundabout |
| df | | primary | |
| de | | primary | roundabout |
| eb | | primary | roundabout |
| df | | primary | |

When I route I should get
| waypoints | route | turns | lanes |
Expand Down
69 changes: 45 additions & 24 deletions include/extractor/guidance/road_classification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace extractor
namespace guidance
{

namespace RoadClass
namespace RoadPriorityClass
{
typedef std::uint8_t Enum;
typedef std::uint32_t Enum;
// Top priority Road
const constexpr Enum MOTORWAY = 0;
// Second highest priority
Expand All @@ -35,7 +35,7 @@ const constexpr Enum LINK_ROAD = 14;
const constexpr Enum BIKE_PATH = 16;
// Walk Accessible
const constexpr Enum FOOT_PATH = 18;
// Link types are usually not considered in forks, unless amongst each other.
// Link types are usually not considered in forks, unless amongst each other.
// a road simply offered for connectivity. Will be ignored in forks/other decisions. Always
// considered non-obvious to continue on
const constexpr Enum CONNECTIVITY = 31;
Expand All @@ -53,52 +53,73 @@ class RoadClassification
// the road priority is used as an indicator for forks. If the roads are of similar priority
// (difference <=1), we can see the road as a fork. Else one of the road classes is seen as
// obvious choice
RoadClass::Enum road_class : 5;
RoadPriorityClass::Enum road_priority_class : 5;

public:
// default construction
RoadClassification() : motorway_class(0), link_class(0), may_be_ignored(1), road_class(RoadClass::CONNECTIVITY) {}
RoadClassification()
: motorway_class(0), link_class(0), may_be_ignored(1),
road_priority_class(RoadPriorityClass::CONNECTIVITY)
{
}

RoadClassification(bool motorway_class, bool link_class, bool may_be_ignored, RoadClass::Enum road_class)
RoadClassification(bool motorway_class,
bool link_class,
bool may_be_ignored,
RoadPriorityClass::Enum road_priority_class)
: motorway_class(motorway_class), link_class(link_class), may_be_ignored(may_be_ignored),
road_class(road_class)
road_priority_class(road_priority_class)
{
}

inline bool isMotorwayClass() const { return (0 != motorway_class) && (0 == link_class); }
inline void setMotorwayFlag(const bool new_value) { motorway_class = new_value; }
bool IsMotorwayClass() const { return (0 != motorway_class) && (0 == link_class); }
void SetMotorwayFlag(const bool new_value) { motorway_class = new_value; }

inline bool isRampClass() const { return (0 != motorway_class) && (0 != link_class); }
bool IsRampClass() const { return (0 != motorway_class) && (0 != link_class); }

inline bool isLinkClass() const { return (0 != link_class); }
inline void setLinkClass(const bool new_value) { link_class = new_value; }
bool IsLinkClass() const { return (0 != link_class); }
void SetLinkClass(const bool new_value) { link_class = new_value; }

inline bool isLowPriorityRoadClass() const { return (0 != may_be_ignored); }
inline void setLowPriorityFlag(const bool new_value) { may_be_ignored = new_value; }
bool IsLowPriorityRoadClass() const { return (0 != may_be_ignored); }
void SetLowPriorityFlag(const bool new_value) { may_be_ignored = new_value; }

inline std::uint32_t getPriority() const { return static_cast<std::uint32_t>(road_class); }
std::uint32_t GetPriority() const
{
return static_cast<std::uint32_t>(road_priority_class);
}

inline RoadClass::Enum getClass() const { return road_class; }
inline void setClass(const RoadClass::Enum new_value) { road_class = new_value; }
RoadPriorityClass::Enum GetClass() const { return road_priority_class; }
void SetClass(const RoadPriorityClass::Enum new_value)
{
road_priority_class = new_value;
}

inline bool operator==(const RoadClassification &other) const
bool operator==(const RoadClassification &other) const
{
return motorway_class == other.motorway_class && link_class == other.link_class &&
may_be_ignored == other.may_be_ignored && road_class == other.road_class;
may_be_ignored == other.may_be_ignored &&
road_priority_class == other.road_priority_class;
}

inline std::string toString() const
bool operator!=(const RoadClassification &other ) const
{
return !(*this == other);
}

std::string ToString() const
{
return std::string() + (motorway_class ? "motorway" : "normal") +
(link_class ? "_link" : "") + (may_be_ignored ? " ignorable " : " important ") +
std::to_string(road_class);
std::to_string(road_priority_class);
}
};
} __attribute ((packed));;

static_assert(sizeof(RoadClassification) == 1,"Road Classification should fit a byte. Increasing this has a severe impact on memory.");

inline bool canBeSeenAsFork(const RoadClassification first, const RoadClassification second)
{
return std::abs(static_cast<int>(first.getPriority()) -
static_cast<int>(second.getPriority())) <= 1;
return std::abs(static_cast<int>(first.GetPriority()) -
static_cast<int>(second.GetPriority())) <= 1;
}
} // namespace guidance
} // namespace extractor
Expand Down
14 changes: 10 additions & 4 deletions include/util/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ inline void print(const std::vector<engine::guidance::RouteStep> &steps)
}
}

inline void print( const extractor::guidance::Intersection & intersection )
{
std::cout << " Intersection:\n";
for (const auto &road : intersection)
std::cout << "\t" << toString(road) << "\n";
std::cout << std::flush;
}


inline void print(const extractor::guidance::lanes::LaneDataVector &turn_lane_data)
{
std::cout << " Tags:\n";
Expand All @@ -76,10 +85,7 @@ printTurnAssignmentData(const NodeID at,
std::cout << std::setprecision(12) << toFloating(coordinate.lat) << " "
<< toFloating(coordinate.lon) << "\n";

std::cout << " Intersection:\n";
for (const auto &road : intersection)
std::cout << "\t" << toString(road) << "\n";

print(intersection);
// flushes as well
print(turn_lane_data);
}
Expand Down
45 changes: 35 additions & 10 deletions profiles/lib/guidance.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
local Guidance = {}

-- Guidance: Default Mapping from roads to types/priorities
highway_classes = { ["motorway"] = road_class.motorway, ["motorway_link"] = road_class.link_road, ["trunk"] = road_class.trunk, ["trunk_link"] = road_class.link_road,
["primary"] = road_class.primary, ["primary_link"] = road_class.link_road, ["secondary"] = road_class.secondary, ["secondary_link"] = road_class.link_road,
["tertiary"] = road_class.tertiary, ["tertiary_link"] = road_class.link_road, ["unclassified"] = road_class.side_residential, ["residential"] = road_class.side_residential,
["service"] = road_class.connectivity, ["living_street"] = road_class.main_residential, ["track"] = road_class.bike_path, ["path"] = road_class.bike_path,
["footway"] = road_class.foot_path, ["pedestrian"] = road_class.foot_path, ["steps"] = road_class.foot_path}
default_highway_class = road_class.connectivity;
highway_classes = { ["motorway"] = road_priority_class.motorway,
["motorway_link"] = road_priority_class.link_road,
["trunk"] = road_priority_class.trunk,
["trunk_link"] = road_priority_class.link_road,
["primary"] = road_priority_class.primary,
["primary_link"] = road_priority_class.link_road,
["secondary"] = road_priority_class.secondary,
["secondary_link"] = road_priority_class.link_road,
["tertiary"] = road_priority_class.tertiary,
["tertiary_link"] = road_priority_class.link_road,
["unclassified"] = road_priority_class.side_residential,
["residential"] = road_priority_class.side_residential,
["service"] = road_priority_class.connectivity,
["living_street"] = road_priority_class.main_residential,
["track"] = road_priority_class.bike_path,
["path"] = road_priority_class.bike_path,
["footway"] = road_priority_class.foot_path,
["pedestrian"] = road_priority_class.foot_path,
["steps"] = road_priority_class.foot_path}

default_highway_class = road_priority_class.connectivity;

motorway_types = { ["motorway"] = true, ["motorway_link"] = true, ["trunk"] = true, ["trunk_link"] = true }

-- these road types are set with a car in mind. For bicycle/walk we probably need different ones
road_types = { ["motorway"] = true, ["motorway_link"] = true, ["trunk"] = true, ["trunk_link"] = true, ["primary"] = true, ["primary_link"] = true,
["secondary"] = true, ["secondary_link"] = true, ["tertiary"] = true, ["tertiary_link"] = true, ["unclassified"] = true, ["residential"] = true,
road_types = { ["motorway"] = true,
["motorway_link"] = true,
["trunk"] = true,
["trunk_link"] = true,
["primary"] = true,
["primary_link"] = true,
["secondary"] = true,
["secondary_link"] = true,
["tertiary"] = true,
["tertiary_link"] = true,
["unclassified"] = true,
["residential"] = true,
["living_street"] = true }

link_types = { ["motorway_link"] = true, ["trunk_link"] = true, ["primary_link"] = true, ["secondary_link"] = true, ["tertiary_link"] = true }
Expand All @@ -25,9 +50,9 @@ function Guidance.set_classification (highway, result)
result.road_classification.link_class = true;
end
if highway_classes[highway] ~= nil then
result.road_classification.road_class = highway_classes[highway]
result.road_classification.road_priority_class = highway_classes[highway]
else
result.road_classification.road_class = default_highway_class
result.road_classification.road_priority_class = default_highway_class
end
if road_types[highway] then
result.road_classification.may_be_ignored = false;
Expand Down
2 changes: 0 additions & 2 deletions src/extractor/extractor_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti

// FIXME this need to be moved into the profiles
const guidance::RoadClassification road_classification = parsed_way.road_classification;
std::cout << "Classification: " << road_classification.toString() << std::endl;

const auto laneStringToDescription = [](std::string lane_string) -> TurnLaneDescription {
if (lane_string.empty())
return {};
Expand Down
8 changes: 4 additions & 4 deletions src/extractor/guidance/intersection_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ TurnType::Enum IntersectionHandler::findBasicTurnType(const EdgeID via_edge,
const auto &in_data = node_based_graph.GetEdgeData(via_edge);
const auto &out_data = node_based_graph.GetEdgeData(road.turn.eid);

bool on_ramp = in_data.road_classification.isRampClass();
bool on_ramp = in_data.road_classification.IsRampClass();

bool onto_ramp = out_data.road_classification.isRampClass();
bool onto_ramp = out_data.road_classification.IsRampClass();

if (!on_ramp && onto_ramp)
return TurnType::OnRamp;
Expand Down Expand Up @@ -133,9 +133,9 @@ void IntersectionHandler::assignFork(const EdgeID via_edge,
{
const auto &in_data = node_based_graph.GetEdgeData(via_edge);
const bool low_priority_left =
node_based_graph.GetEdgeData(left.turn.eid).road_classification.isLowPriorityRoadClass();
node_based_graph.GetEdgeData(left.turn.eid).road_classification.IsLowPriorityRoadClass();
const bool low_priority_right =
node_based_graph.GetEdgeData(right.turn.eid).road_classification.isLowPriorityRoadClass();
node_based_graph.GetEdgeData(right.turn.eid).road_classification.IsLowPriorityRoadClass();
if ((angularDeviation(left.turn.angle, STRAIGHT_ANGLE) < MAXIMAL_ALLOWED_NO_TURN_DEVIATION &&
angularDeviation(right.turn.angle, STRAIGHT_ANGLE) > FUZZY_ANGLE_DIFFERENCE))
{
Expand Down
6 changes: 3 additions & 3 deletions src/extractor/guidance/motorway_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace

inline bool isMotorwayClass(EdgeID eid, const util::NodeBasedDynamicGraph &node_based_graph)
{
return node_based_graph.GetEdgeData(eid).road_classification.isMotorwayClass();
return node_based_graph.GetEdgeData(eid).road_classification.IsMotorwayClass();
}
inline RoadClassification roadClass(const ConnectedRoad &road,
const util::NodeBasedDynamicGraph &graph)
Expand All @@ -35,7 +35,7 @@ inline RoadClassification roadClass(const ConnectedRoad &road,

inline bool isRampClass(EdgeID eid, const util::NodeBasedDynamicGraph &node_based_graph)
{
return node_based_graph.GetEdgeData(eid).road_classification.isRampClass();
return node_based_graph.GetEdgeData(eid).road_classification.IsRampClass();
}

} // namespace
Expand Down Expand Up @@ -495,7 +495,7 @@ Intersection MotorwayHandler::fallback(Intersection intersection) const

util::SimpleLogger().Write(logDEBUG)
<< "road: " << toString(road) << " Name: " << out_data.name_id
<< " Road Class: " << out_data.road_classification.toString();
<< " Road Class: " << out_data.road_classification.ToString();

if (!road.entry_allowed)
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/extractor/guidance/turn_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Intersection TurnAnalysis::assignTurnTypes(const NodeID from_nid,

// Turn On Ramps Into Off Ramps, if we come from a motorway-like road
if (node_based_graph.GetEdgeData(via_eid)
.road_classification.isMotorwayClass())
.road_classification.IsMotorwayClass())
{
std::for_each(intersection.begin(), intersection.end(), [](ConnectedRoad &road) {
if (road.turn.instruction.type == TurnType::OnRamp)
Expand Down
Loading

0 comments on commit b4dc10e

Please sign in to comment.