2014-05-05 19:35:43 -04:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-10-03 04:03:44 -04:00
|
|
|
#ifndef RESTRICTION_MAP_H_
|
|
|
|
#define RESTRICTION_MAP_H_
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2014-05-08 17:22:49 -04:00
|
|
|
#include <memory>
|
|
|
|
|
2014-05-05 19:35:43 -04:00
|
|
|
#include "DynamicGraph.h"
|
|
|
|
#include "Restriction.h"
|
|
|
|
#include "NodeBasedGraph.h"
|
2014-05-19 07:02:41 -04:00
|
|
|
#include "../Util/StdHashExtensions.h"
|
|
|
|
#include "../typedefs.h"
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2014-05-19 07:02:41 -04:00
|
|
|
#include <unordered_map>
|
2014-05-19 06:53:27 -04:00
|
|
|
#include <unordered_set>
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2014-06-25 10:03:11 -04:00
|
|
|
struct RestrictionSource
|
2014-06-25 08:00:50 -04:00
|
|
|
{
|
2014-06-25 10:03:11 -04:00
|
|
|
NodeID start_node;
|
|
|
|
NodeID via_node;
|
2014-06-25 08:00:50 -04:00
|
|
|
|
2014-06-26 07:50:15 -04:00
|
|
|
RestrictionSource(NodeID start, NodeID via) : start_node(start), via_node(via)
|
|
|
|
{
|
|
|
|
}
|
2014-06-25 08:00:50 -04:00
|
|
|
|
2014-06-26 07:50:15 -04:00
|
|
|
friend inline bool operator==(const RestrictionSource &lhs, const RestrictionSource &rhs)
|
2014-06-25 08:00:50 -04:00
|
|
|
{
|
2014-06-25 10:03:11 -04:00
|
|
|
return (lhs.start_node == rhs.start_node && lhs.via_node == rhs.via_node);
|
2014-06-25 08:00:50 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-25 10:03:11 -04:00
|
|
|
struct RestrictionTarget
|
2014-06-25 08:00:50 -04:00
|
|
|
{
|
2014-06-25 10:03:11 -04:00
|
|
|
NodeID target_node;
|
2014-06-25 08:00:50 -04:00
|
|
|
bool is_only;
|
|
|
|
|
2014-06-26 07:50:15 -04:00
|
|
|
explicit RestrictionTarget(NodeID target, bool only) : target_node(target), is_only(only)
|
|
|
|
{
|
|
|
|
}
|
2014-06-25 08:00:50 -04:00
|
|
|
|
2014-06-26 07:50:15 -04:00
|
|
|
friend inline bool operator==(const RestrictionTarget &lhs, const RestrictionTarget &rhs)
|
2014-06-25 08:00:50 -04:00
|
|
|
{
|
2014-06-25 10:03:11 -04:00
|
|
|
return (lhs.target_node == rhs.target_node && lhs.is_only == rhs.is_only);
|
2014-06-25 08:00:50 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
2014-06-26 07:50:15 -04:00
|
|
|
template <> struct hash<RestrictionSource>
|
|
|
|
{
|
|
|
|
size_t operator()(const RestrictionSource &r_source) const
|
2014-06-25 08:00:50 -04:00
|
|
|
{
|
2014-06-26 07:50:15 -04:00
|
|
|
return hash_val(r_source.start_node, r_source.via_node);
|
|
|
|
}
|
|
|
|
};
|
2014-06-25 08:00:50 -04:00
|
|
|
|
2014-06-26 07:50:15 -04:00
|
|
|
template <> struct hash<RestrictionTarget>
|
|
|
|
{
|
|
|
|
size_t operator()(const RestrictionTarget &r_target) const
|
2014-06-25 08:00:50 -04:00
|
|
|
{
|
2014-06-26 07:50:15 -04:00
|
|
|
return hash_val(r_target.target_node, r_target.is_only);
|
|
|
|
}
|
|
|
|
};
|
2014-06-25 08:00:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Efficent look up if an edge is the start + via node of a TurnRestriction
|
|
|
|
EdgeBasedEdgeFactory decides by it if edges are inserted or geometry is compressed
|
|
|
|
*/
|
2014-05-05 19:35:43 -04:00
|
|
|
class RestrictionMap
|
|
|
|
{
|
2014-05-08 17:29:24 -04:00
|
|
|
public:
|
|
|
|
RestrictionMap(const std::shared_ptr<NodeBasedDynamicGraph> &graph,
|
|
|
|
const std::vector<TurnRestriction> &input_restrictions_list);
|
2014-05-05 19:35:43 -04:00
|
|
|
|
|
|
|
void FixupArrivingTurnRestriction(const NodeID u, const NodeID v, const NodeID w);
|
|
|
|
void FixupStartingTurnRestriction(const NodeID u, const NodeID v, const NodeID w);
|
|
|
|
NodeID CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const;
|
|
|
|
bool CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const;
|
2014-06-10 11:26:05 -04:00
|
|
|
bool IsViaNode(const NodeID node) const;
|
2014-07-24 05:25:43 -04:00
|
|
|
std::size_t size()
|
2014-06-26 07:50:15 -04:00
|
|
|
{
|
|
|
|
return m_count;
|
|
|
|
}
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2014-05-08 17:29:24 -04:00
|
|
|
private:
|
2014-06-10 11:26:05 -04:00
|
|
|
bool IsSourceNode(const NodeID node) const;
|
2014-08-19 07:01:38 -04:00
|
|
|
using EmanatingRestrictionsVector = std::vector<RestrictionTarget>;
|
|
|
|
using EdgeData = NodeBasedDynamicGraph::EdgeData;
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2014-07-24 05:25:43 -04:00
|
|
|
std::size_t m_count;
|
2014-05-08 17:29:24 -04:00
|
|
|
std::shared_ptr<NodeBasedDynamicGraph> m_graph;
|
2014-05-05 19:35:43 -04:00
|
|
|
//! index -> list of (target, isOnly)
|
2014-05-08 17:29:24 -04:00
|
|
|
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
|
2014-05-05 19:35:43 -04:00
|
|
|
//! maps (start, via) -> bucket index
|
2014-05-19 07:02:41 -04:00
|
|
|
std::unordered_map<RestrictionSource, unsigned> m_restriction_map;
|
2014-05-22 05:41:32 -04:00
|
|
|
std::unordered_set<NodeID> m_restriction_start_nodes;
|
2014-05-19 06:53:27 -04:00
|
|
|
std::unordered_set<NodeID> m_no_turn_via_node_set;
|
2014-05-05 19:35:43 -04:00
|
|
|
};
|
|
|
|
|
2014-10-03 04:03:44 -04:00
|
|
|
#endif //RESTRICTION_MAP_H_
|