Skip to content

Commit

Permalink
allow handling of multiple restrictions sharing the same from/via
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Kobitzsch committed Jul 18, 2017
1 parent 702e2aa commit ba54874
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 106 deletions.
16 changes: 16 additions & 0 deletions features/car/restrictions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,22 @@ Feature: Car - Turn restrictions
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
a - b - c - - - - - - - - - - - - - - - - - - - f
| | \ /
i - d - e - - - - - - - - - - - - - - - - -
Expand Down
3 changes: 0 additions & 3 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ class EdgeBasedGraphFactory
util::ConcurrentIDMap<util::guidance::BearingClass, BearingClassID> bearing_class_hash;
std::vector<BearingClassID> bearing_class_by_node_based_node;
util::ConcurrentIDMap<util::guidance::EntryClass, EntryClassID> entry_class_hash;

// a mapping from a restriction way to the duplicate node
std::vector<NodeID> edge_based_node_by_via_way;
};
} // namespace extractor
} // namespace osrm
Expand Down
31 changes: 31 additions & 0 deletions include/extractor/restriction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct Bits
bool is_only;
// when adding more bits, consider using bitfields just as in
// bool unused : 7;

bool operator==(const Bits &other) const { return is_only == other.is_only; }
};

} // namespace restriction
Expand Down Expand Up @@ -141,6 +143,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 +172,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 Down Expand Up @@ -239,6 +252,24 @@ struct TurnRestriction
}
}

bool operator==(const TurnRestriction &other) const
{
if (!(flags == other.flags))
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 Down
22 changes: 18 additions & 4 deletions include/extractor/way_restriction_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,32 @@ class WayRestrictionMap
bool IsStart(const NodeID from, const NodeID to) const;
bool IsEnd(const NodeID from, const NodeID to) const;

std::vector<ViaWay> ViaWays() const;

std::size_t Size() const;

// number of duplicated nodes
std::size_t NumberOfDuplicatedNodes() const;

// find the ID of the duplicated node (zero based) for a given restriction id
std::size_t DuplicatedNodeID(const std::size_t restriction_id) const;

// returns a representative for the duplicated way, consisting of the representative ID (first
// ID of the nodes restrictions) and the from/to vertices of the via-way
std::vector<ViaWay> DuplicatedNodeRepresentatives() const;

std::vector<std::size_t> GetIDs(const NodeID from, const NodeID to) const;

TurnRestriction const &GetRestriction(std::size_t) const;

private:
// acces to the turn restrictions based on the via way they use
// access all restrictions that have the same starting way and via way. Any duplicated node
// represents the same in-way + via-way combination. This vector contains data about all
// restrictions and their assigned duplicated nodes. It indicates the minimum restriciton ID
// that is represented by the next node. The ID of a node is defined as the position of the
// lower bound of the restrictions ID within this array
std::vector<std::size_t> duplicated_node_groups;

boost::unordered_multimap<std::pair<NodeID, NodeID>, std::size_t> restriction_starts;
boost::unordered_multimap<std::pair<NodeID, NodeID>, std::size_t> restriction_ends;

boost::unordered_multimap<std::pair<NodeID, NodeID>, std::size_t> via_ways;

std::vector<TurnRestriction> restriction_data;
Expand Down
Loading

0 comments on commit ba54874

Please sign in to comment.