Skip to content

Commit

Permalink
Add data structure to allow identification of via-way turns during cr…
Browse files Browse the repository at this point in the history
…eation of edge-based-graph

initial version of handling via-way turn restrictions (this is dirty)

 - requires update of data structures
 - requires clean-up
 - requires optimisation
  • Loading branch information
Moritz Kobitzsch committed Jul 31, 2017
1 parent b1809d1 commit 8d0202d
Show file tree
Hide file tree
Showing 17 changed files with 837 additions and 357 deletions.
82 changes: 52 additions & 30 deletions features/car/restrictions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ Feature: Car - Turn restrictions
| from | to | route |
| a | h | abc,cde,efc,cgh,cgh |

@restriction
@restriction-way
Scenario: Car - prohibit turn
Given the node map
"""
Expand All @@ -563,9 +563,11 @@ Feature: Car - Turn restrictions
| restriction | ab | be | de | no_right_turn |

When I route I should get
| from | to | route |
| a | d | ab,be,de,de |
| a | f | ab,be,ef,ef |
| from | to | route | turns | locations |
| a | d | ab,be,ef,ef,de,de | depart,turn right,turn left,continue uturn,new name straight,arrive | a,b,e,f,e,d |
| a | f | ab,be,ef,ef | depart,turn right,turn left,arrive | a,b,e,f |
| c | d | bc,be,de,de | depart,turn left,turn right,arrive | c,b,e,d |
| c | f | bc,be,ef,ef | depart,turn left,turn left,arrive | c,b,e,f |

@restriction @overlap
Scenario: Car - prohibit turn
Expand Down Expand Up @@ -597,11 +599,11 @@ Feature: Car - Turn restrictions
| restriction | bc | be | ef | no_left_turn |

When I route I should get
| from | to | route |
| a | d | ab,be,de,de |
| a | f | ab,be,ef,ef |
| c | d | bc,be,de,de |
| c | f | bc,be,ef,ef |
| from | to | route |
| a | d | ab,be,ef,ef,de,de |
| a | f | ab,be,ef,ef |
| c | d | bc,be,de,de |
| c | f | bc,be,de,de,ef,ef |

@restriction-way @overlap
Scenario: Two times same way
Expand All @@ -618,9 +620,25 @@ Feature: Car - Turn restrictions
| |
| |
| |
a - b - c - f
| | \ |
i - d - e
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
a - b - c - - - - - - - - - - - - - - - - - - - f
| | \ /
i - d - e - - - - - - - - - - - - - - - - -
"""

And the ways
Expand All @@ -641,7 +659,7 @@ Feature: Car - Turn restrictions

When I route I should get
| from | to | route |
| a | i | ab,bc,cd,fedib,fedib |
| a | i | ab,bc,cf,fedib,fedib |


@restriction-way @overlap
Expand Down Expand Up @@ -682,8 +700,8 @@ Feature: Car - Turn restrictions

When I route I should get
| from | to | route |
| a | j | left,third,right,right |
| f | e | right,first,left,left |
| a | j | left,first,right,right |
| f | e | right,third,left,left |

@restriction
Scenario: Car - allow only turn
Expand Down Expand Up @@ -711,9 +729,11 @@ Feature: Car - Turn restrictions
| restriction | ab | be | ef | only_left_on |

When I route I should get
| from | to | route |
| a | d | ab,be,de,de |

| from | to | route | turns | locations |
| a | d | ab,be,ef,ef,de,de | depart,turn right,turn left,continue uturn,new name straight,arrive | a,b,e,f,e,d |
| a | f | ab,be,ef,ef | depart,turn right,turn left,arrive | a,b,e,f |
| c | d | bc,be,de,de | depart,turn left,turn right,arrive | c,b,e,d |
| c | f | bc,be,ef,ef | depart,turn left,turn left,arrive | c,b,e,f |

@restriction
Scenario: Car - allow only turn
Expand Down Expand Up @@ -810,14 +830,15 @@ Feature: Car - Turn restrictions
| restriction | gf | fb,bc | cd | only_u_turn |

When I route I should get
| from | to | route |
| a | d | abcd,abcd |
| a | e | abcd,ce,ce |
| a | f | abcd,hfb,hfb |
| g | e | gf,hfb,abcd,ce,ce |
| g | d | gf,hfb,abcd,abcd |
| h | e | hfb,abcd,ce,ce |
| h | d | hfb,abcd,abcd |
| from | to | route | turns | locations |
| a | d | abcd,ce,ce,abcd,abcd | depart,turn left,continue uturn,turn left,arrive | a,c,e,c,d |
| a | e | abcd,ce,ce | depart,turn left,arrive | a,c,e |
| a | f | abcd,hfb,hfb | depart,turn right,arrive | a,b,f |
| g | e | gf,hfb,abcd,ce,ce | depart,turn right,turn right,turn left,arrive | g,f,b,c,e |
| g | d | gf,hfb,abcd,abcd | depart,turn right,turn right,arrive | g,f,b,d |
| h | e | hfb,abcd,ce,ce | depart,end of road right,turn left,arrive | h,b,c,e |
| h | d | hfb,abcd,abcd | depart,end of road right,arrive | h,b,d |


@restriction
Scenario: Car - prohibit turn, traffic lights
Expand Down Expand Up @@ -855,7 +876,8 @@ Feature: Car - Turn restrictions


When I route I should get
| from | to | route |
| h | j | ab,be,de,de |
| h | f | ab,be,ef,ef |

| from | to | route | turns | locations |
| a | d | ab,be,ef,ef,de,de | depart,turn right,turn left,continue uturn,new name straight,arrive | a,b,e,f,e,d |
| a | f | ab,be,ef,ef | depart,turn right,turn left,arrive | a,b,e,f |
| c | d | bc,be,de,de | depart,turn left,turn right,arrive | c,b,e,d |
| c | f | bc,be,ef,ef | depart,turn left,turn left,arrive | c,b,e,f |
21 changes: 14 additions & 7 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "extractor/profile_properties.hpp"
#include "extractor/query_node.hpp"
#include "extractor/restriction_map.hpp"
#include "extractor/way_restriction_map.hpp"

#include "util/concurrent_id_map.hpp"
#include "util/deallocating_vector.hpp"
Expand Down Expand Up @@ -78,7 +79,6 @@ class EdgeBasedGraphFactory
CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<util::Coordinate> &coordinates,
const extractor::PackedOSMIDs &osm_node_ids,
ProfileProperties profile_properties,
Expand All @@ -91,7 +91,9 @@ class EdgeBasedGraphFactory
const std::string &turn_weight_penalties_filename,
const std::string &turn_duration_penalties_filename,
const std::string &turn_penalties_index_filename,
const std::string &cnbg_ebg_mapping_path);
const std::string &cnbg_ebg_mapping_path,
const RestrictionMap &restriction_map,
const WayRestrictionMap &way_restriction_map);

// The following get access functions destroy the content in the factory
void GetEdgeBasedEdges(util::DeallocatingVector<EdgeBasedEdge> &edges);
Expand All @@ -106,7 +108,7 @@ class EdgeBasedGraphFactory
std::vector<util::guidance::BearingClass> GetBearingClasses() const;
std::vector<util::guidance::EntryClass> GetEntryClasses() const;

unsigned GetHighestEdgeID();
std::uint64_t GetNumberOfEdgeBasedNodes() const;

// Basic analysis of a turn (u --(e1)-- v --(e2)-- w)
// with known angle.
Expand Down Expand Up @@ -134,12 +136,15 @@ class EdgeBasedGraphFactory
std::vector<EdgeBasedNodeSegment> m_edge_based_node_segments;
EdgeBasedNodeDataContainer m_edge_based_node_container;
util::DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
EdgeID m_max_edge_id;

// the number of edge-based nodes is mostly made up out of the edges in the node-based graph.
// Any edge in the node-based graph represents a node in the edge-based graph. In addition, we
// add a set of artificial edge-based nodes into the mix to model via-way turn restrictions.
std::uint64_t m_number_of_edge_based_nodes;

const std::vector<util::Coordinate> &m_coordinates;
const extractor::PackedOSMIDs &m_osm_node_ids;
std::shared_ptr<util::NodeBasedDynamicGraph> m_node_based_graph;
std::shared_ptr<RestrictionMap const> m_restriction_map;

const std::unordered_set<NodeID> &m_barrier_nodes;
const std::unordered_set<NodeID> &m_traffic_lights;
Expand All @@ -152,14 +157,16 @@ class EdgeBasedGraphFactory

unsigned RenumberEdges();

std::vector<NBGToEBG> GenerateEdgeExpandedNodes();
std::vector<NBGToEBG> GenerateEdgeExpandedNodes(const WayRestrictionMap &way_restriction_map);

void GenerateEdgeExpandedEdges(ScriptingEnvironment &scripting_environment,
const std::string &original_edge_data_filename,
const std::string &turn_lane_data_filename,
const std::string &turn_weight_penalties_filename,
const std::string &turn_duration_penalties_filename,
const std::string &turn_penalties_index_filename);
const std::string &turn_penalties_index_filename,
const RestrictionMap &restriction_map,
const WayRestrictionMap &way_restriction_map);

NBGToEBG InsertEdgeBasedNode(const NodeID u, const NodeID v);

Expand Down
10 changes: 10 additions & 0 deletions include/extractor/node_data_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ template <storage::Ownership Ownership> class EdgeBasedNodeDataContainerImpl
util::inplacePermutation(classes.begin(), classes.end(), permutation);
}

// all containers have the exact same size
std::size_t Size() const
{
BOOST_ASSERT(geometry_ids.size() == name_ids.size());
BOOST_ASSERT(geometry_ids.size() == component_ids.size());
BOOST_ASSERT(geometry_ids.size() == travel_modes.size());
BOOST_ASSERT(geometry_ids.size() == classes.size());
return geometry_ids.size();
}

private:
Vector<GeometryID> geometry_ids;
Vector<NameID> name_ids;
Expand Down
72 changes: 42 additions & 30 deletions include/extractor/restriction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace extractor
// ab via b to bd
struct InputNodeRestriction
{
OSMEdgeID_weak from;
OSMNodeID_weak via;
OSMEdgeID_weak to;
OSMWayID from;
OSMNodeID via;
OSMWayID to;
};

// A restriction that uses a single via-way in between
Expand All @@ -39,9 +39,9 @@ struct InputNodeRestriction
// ab via be to ef -- no u turn
struct InputWayRestriction
{
OSMEdgeID_weak from;
OSMEdgeID_weak via;
OSMEdgeID_weak to;
OSMWayID from;
OSMWayID via;
OSMWayID to;
};

// Outside view of the variant, these are equal to the `which()` results
Expand All @@ -52,35 +52,20 @@ enum RestrictionType
NUM_RESTRICTION_TYPES = 2
};

namespace restriction_details
{

// currently these bits only hold an `is_only` value.
struct Bits
{ // mostly unused, initialised to false by default
Bits() : is_only(false) {}

bool is_only;
// when adding more bits, consider using bitfields just as in
// bool unused : 7;
};

} // namespace restriction

struct InputTurnRestriction
{
// keep in the same order as the turn restrictions below
boost::variant<InputNodeRestriction, InputWayRestriction> node_or_way;
restriction_details::Bits flags;
bool is_only;

OSMEdgeID_weak From() const
OSMWayID From() const
{
return node_or_way.which() == RestrictionType::NODE_RESTRICTION
? boost::get<InputNodeRestriction>(node_or_way).from
: boost::get<InputWayRestriction>(node_or_way).from;
}

OSMEdgeID_weak To() const
OSMWayID To() const
{
return node_or_way.which() == RestrictionType::NODE_RESTRICTION
? boost::get<InputNodeRestriction>(node_or_way).to
Expand Down Expand Up @@ -141,6 +126,11 @@ struct NodeRestriction
return "From " + std::to_string(from) + " via " + std::to_string(via) + " to " +
std::to_string(to);
}

bool operator==(const NodeRestriction &other) const
{
return std::tie(from, via, to) == std::tie(other.from, other.via, other.to);
}
};

// A way restriction in the context of OSRM requires translation into NodeIDs. This is due to the
Expand All @@ -165,6 +155,12 @@ struct WayRestriction
// case a way restrction is not fully collapsed
NodeRestriction in_restriction;
NodeRestriction out_restriction;

bool operator==(const WayRestriction &other) const
{
return std::tie(in_restriction, out_restriction) ==
std::tie(other.in_restriction, other.out_restriction);
}
};

// Wrapper for turn restrictions that gives more information on its type / handles the switch
Expand All @@ -173,20 +169,18 @@ struct TurnRestriction
{
// keep in the same order as the turn restrictions above
boost::variant<NodeRestriction, WayRestriction> node_or_way;
restriction_details::Bits flags;
bool is_only;

// construction for NodeRestrictions
explicit TurnRestriction(NodeRestriction node_restriction, bool is_only = false)
: node_or_way(node_restriction)
: node_or_way(node_restriction), is_only(is_only)
{
flags.is_only = is_only;
}

// construction for WayRestrictions
explicit TurnRestriction(WayRestriction way_restriction, bool is_only = false)
: node_or_way(way_restriction)
: node_or_way(way_restriction), is_only(is_only)
{
flags.is_only = is_only;
}

explicit TurnRestriction()
Expand Down Expand Up @@ -239,6 +233,24 @@ struct TurnRestriction
}
}

bool operator==(const TurnRestriction &other) const
{
if (is_only != other.is_only)
return false;

if (Type() != other.Type())
return false;

if (Type() == RestrictionType::WAY_RESTRICTION)
{
return AsWayRestriction() == other.AsWayRestriction();
}
else
{
return AsNodeRestriction() == other.AsNodeRestriction();
}
}

std::string ToString() const
{
std::string representation;
Expand All @@ -253,7 +265,7 @@ struct TurnRestriction
auto const &node = AsNodeRestriction();
representation = node.ToString();
}
representation += " is_only: " + std::to_string(flags.is_only);
representation += " is_only: " + std::to_string(is_only);
return representation;
}
};
Expand Down
Loading

0 comments on commit 8d0202d

Please sign in to comment.