Avoid -> Exclude

This commit is contained in:
Patrick Niklaus
2017-08-16 20:21:19 +00:00
committed by Patrick Niklaus
parent 45140ca9f7
commit d09f5c0e3a
27 changed files with 145 additions and 142 deletions
+2 -2
View File
@@ -56,7 +56,7 @@ template <typename AlgorithmT> struct HasManyToManySearch final : std::false_typ
template <typename AlgorithmT> struct HasGetTileTurns final : std::false_type
{
};
template <typename AlgorithmT> struct HasAvoidFlags final : std::false_type
template <typename AlgorithmT> struct HasExcludeFlags final : std::false_type
{
};
@@ -114,7 +114,7 @@ template <> struct HasManyToManySearch<mld::Algorithm> final : std::true_type
template <> struct HasGetTileTurns<mld::Algorithm> final : std::true_type
{
};
template <> struct HasAvoidFlags<mld::Algorithm> final : std::true_type
template <> struct HasExcludeFlags<mld::Algorithm> final : std::true_type
{
};
}
+3 -3
View File
@@ -68,7 +68,7 @@ struct BaseParameters
std::vector<boost::optional<double>> radiuses;
std::vector<boost::optional<Bearing>> bearings;
std::vector<boost::optional<Approach>> approaches;
std::vector<std::string> avoid;
std::vector<std::string> exclude;
// Adds hints to response which can be included in subsequent requests, see `hints` above.
bool generate_hints = true;
@@ -79,9 +79,9 @@ struct BaseParameters
std::vector<boost::optional<Bearing>> bearings_ = {},
std::vector<boost::optional<Approach>> approaches_ = {},
bool generate_hints_ = true,
std::vector<std::string> avoid = {})
std::vector<std::string> exclude = {})
: coordinates(coordinates_), hints(hints_), radiuses(radiuses_), bearings(bearings_),
approaches(approaches_), avoid(std::move(avoid)), generate_hints(generate_hints_)
approaches(approaches_), exclude(std::move(exclude)), generate_hints(generate_hints_)
{
}
@@ -212,7 +212,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
using SharedGeospatialQuery = GeospatialQuery<SharedRTree, BaseDataFacade>;
using RTreeNode = SharedRTree::TreeNode;
extractor::ClassData avoid_mask;
extractor::ClassData exclude_mask;
std::string m_timestamp;
extractor::ProfileProperties *m_profile_properties;
extractor::Datasources *m_datasources;
@@ -249,12 +249,12 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
void InitializeProfilePropertiesPointer(storage::DataLayout &data_layout,
char *memory_block,
const std::size_t avoid_index)
const std::size_t exclude_index)
{
m_profile_properties = data_layout.GetBlockPtr<extractor::ProfileProperties>(
memory_block, storage::DataLayout::PROPERTIES);
avoid_mask = m_profile_properties->avoidable_classes[avoid_index];
exclude_mask = m_profile_properties->excludable_classes[exclude_index];
}
void InitializeTimestampPointer(storage::DataLayout &data_layout, char *memory_block)
@@ -546,7 +546,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
void InitializeInternalPointers(storage::DataLayout &data_layout,
char *memory_block,
const std::size_t avoid_index)
const std::size_t exclude_index)
{
InitializeChecksumPointer(data_layout, memory_block);
InitializeNodeInformationPointers(data_layout, memory_block);
@@ -557,7 +557,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
InitializeTimestampPointer(data_layout, memory_block);
InitializeNamePointers(data_layout, memory_block);
InitializeTurnLaneDescriptionsPointers(data_layout, memory_block);
InitializeProfilePropertiesPointer(data_layout, memory_block, avoid_index);
InitializeProfilePropertiesPointer(data_layout, memory_block, exclude_index);
InitializeRTreePointers(data_layout, memory_block);
InitializeIntersectionClassPointers(data_layout, memory_block);
}
@@ -566,10 +566,10 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
// allows switching between process_memory/shared_memory datafacade, based on the type of
// allocator
ContiguousInternalMemoryDataFacadeBase(std::shared_ptr<ContiguousBlockAllocator> allocator_,
const std::size_t avoid_index)
const std::size_t exclude_index)
: allocator(std::move(allocator_))
{
InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), avoid_index);
InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), exclude_index);
}
// node and edge information access
@@ -810,9 +810,9 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
return edge_based_node_data.GetClassData(id);
}
bool AvoidNode(const NodeID id) const override final
bool ExcludeNode(const NodeID id) const override final
{
return (edge_based_node_data.GetClassData(id) & avoid_mask) > 0;
return (edge_based_node_data.GetClassData(id) & exclude_mask) > 0;
}
std::vector<std::string> GetClasses(const extractor::ClassData class_data) const override final
@@ -940,8 +940,8 @@ class ContiguousInternalMemoryDataFacade<CH>
{
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator,
const std::size_t avoid_index)
: ContiguousInternalMemoryDataFacadeBase(allocator, avoid_index),
const std::size_t exclude_index)
: ContiguousInternalMemoryDataFacadeBase(allocator, exclude_index),
ContiguousInternalMemoryAlgorithmDataFacade<CH>(allocator)
{
@@ -955,8 +955,8 @@ class ContiguousInternalMemoryDataFacade<CoreCH> final
{
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator,
const std::size_t avoid_index)
: ContiguousInternalMemoryDataFacade<CH>(allocator, avoid_index),
const std::size_t exclude_index)
: ContiguousInternalMemoryDataFacade<CH>(allocator, exclude_index),
ContiguousInternalMemoryAlgorithmDataFacade<CoreCH>(allocator)
{
@@ -977,15 +977,15 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
void InitializeInternalPointers(storage::DataLayout &data_layout,
char *memory_block,
const std::size_t avoid_index)
const std::size_t exclude_index)
{
InitializeMLDDataPointers(data_layout, memory_block, avoid_index);
InitializeMLDDataPointers(data_layout, memory_block, exclude_index);
InitializeGraphPointer(data_layout, memory_block);
}
void InitializeMLDDataPointers(storage::DataLayout &data_layout,
char *memory_block,
const std::size_t avoid_index)
const std::size_t exclude_index)
{
if (data_layout.GetBlockSize(storage::DataLayout::MLD_PARTITION) > 0)
{
@@ -1013,9 +1013,9 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
}
const auto weights_block_id = static_cast<storage::DataLayout::BlockID>(
storage::DataLayout::MLD_CELL_WEIGHTS_0 + avoid_index);
storage::DataLayout::MLD_CELL_WEIGHTS_0 + exclude_index);
const auto durations_block_id = static_cast<storage::DataLayout::BlockID>(
storage::DataLayout::MLD_CELL_DURATIONS_0 + avoid_index);
storage::DataLayout::MLD_CELL_DURATIONS_0 + exclude_index);
if (data_layout.GetBlockSize(weights_block_id) > 0)
{
@@ -1098,10 +1098,10 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
public:
ContiguousInternalMemoryAlgorithmDataFacade(
std::shared_ptr<ContiguousBlockAllocator> allocator_, const std::size_t avoid_index)
std::shared_ptr<ContiguousBlockAllocator> allocator_, const std::size_t exclude_index)
: allocator(std::move(allocator_))
{
InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), avoid_index);
InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), exclude_index);
}
const partition::MultiLevelPartitionView &GetMultiLevelPartition() const override
@@ -1159,9 +1159,9 @@ class ContiguousInternalMemoryDataFacade<MLD> final
private:
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator,
const std::size_t avoid_index)
: ContiguousInternalMemoryDataFacadeBase(allocator, avoid_index),
ContiguousInternalMemoryAlgorithmDataFacade<MLD>(allocator, avoid_index)
const std::size_t exclude_index)
: ContiguousInternalMemoryDataFacadeBase(allocator, exclude_index),
ContiguousInternalMemoryAlgorithmDataFacade<MLD>(allocator, exclude_index)
{
}
@@ -94,7 +94,7 @@ class BaseDataFacade
virtual extractor::ClassData GetClassData(const NodeID id) const = 0;
virtual bool AvoidNode(const NodeID id) const = 0;
virtual bool ExcludeNode(const NodeID id) const = 0;
virtual std::vector<std::string> GetClasses(const extractor::ClassData class_data) const = 0;
+17 -16
View File
@@ -23,7 +23,7 @@ namespace engine
// This class selects the right facade for
template <template <typename A> class FacadeT, typename AlgorithmT> class DataFacadeFactory
{
static constexpr auto has_avoid_flags = routing_algorithms::HasAvoidFlags<AlgorithmT>{};
static constexpr auto has_exclude_flags = routing_algorithms::HasExcludeFlags<AlgorithmT>{};
public:
using Facade = FacadeT<AlgorithmT>;
@@ -31,17 +31,17 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator)
: DataFacadeFactory(allocator, has_avoid_flags)
: DataFacadeFactory(allocator, has_exclude_flags)
{
}
template <typename ParameterT> std::shared_ptr<const Facade> Get(const ParameterT &params) const
{
return Get(params, has_avoid_flags);
return Get(params, has_exclude_flags);
}
private:
// Algorithm with avoid flags
// Algorithm with exclude flags
template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::true_type)
{
@@ -63,7 +63,7 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
}
}
// Algorithm without avoid flags
// Algorithm without exclude flags
template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::false_type)
{
@@ -75,10 +75,10 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
return facades[0];
}
// Default for non-avoid flags: return only facade
// Default for non-exclude flags: return only facade
std::shared_ptr<const Facade> Get(const api::BaseParameters &params, std::false_type) const
{
if (!params.avoid.empty())
if (!params.exclude.empty())
{
return {};
}
@@ -86,7 +86,7 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
return facades[0];
}
// TileParameters don't drive from BaseParameters and generally don't have use for avoid flags
// TileParameters don't drive from BaseParameters and generally don't have use for exclude flags
std::shared_ptr<const Facade> Get(const api::TileParameters &, std::true_type) const
{
return facades[0];
@@ -95,11 +95,11 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
// Selection logic for finding the corresponding datafacade for the given parameters
std::shared_ptr<const Facade> Get(const api::BaseParameters &params, std::true_type) const
{
if (params.avoid.empty())
if (params.exclude.empty())
return facades[0];
extractor::ClassData mask = 0;
for (const auto &name : params.avoid)
for (const auto &name : params.exclude)
{
auto class_mask_iter = name_to_class.find(name);
if (class_mask_iter == name_to_class.end())
@@ -112,18 +112,19 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
}
}
auto avoid_iter = std::find(
properties->avoidable_classes.begin(), properties->avoidable_classes.end(), mask);
if (avoid_iter != properties->avoidable_classes.end())
auto exclude_iter = std::find(
properties->excludable_classes.begin(), properties->excludable_classes.end(), mask);
if (exclude_iter != properties->excludable_classes.end())
{
auto avoid_index = std::distance(properties->avoidable_classes.begin(), avoid_iter);
return facades[avoid_index];
auto exclude_index =
std::distance(properties->excludable_classes.begin(), exclude_iter);
return facades[exclude_index];
}
return {};
}
std::array<std::shared_ptr<const Facade>, extractor::MAX_AVOIDABLE_CLASSES> facades;
std::array<std::shared_ptr<const Facade>, extractor::MAX_EXCLUDABLE_CLASSES> facades;
std::unordered_map<std::string, extractor::ClassData> name_to_class;
const extractor::ProfileProperties *properties = nullptr;
};
+13 -13
View File
@@ -57,7 +57,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto results = rtree.Nearest(
input_coordinate,
[this, approach, &input_coordinate](const CandidateSegment &segment) {
return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)),
return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentExclude(segment)),
CheckApproach(input_coordinate, segment, approach));
},
[this, max_distance, input_coordinate](const std::size_t,
@@ -83,7 +83,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
const CandidateSegment &segment) {
auto use_direction =
boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)));
boolPairAnd(HasValidEdge(segment), CheckSegmentExclude(segment)));
use_direction =
boolPairAnd(use_direction, CheckApproach(input_coordinate, segment, approach));
return use_direction;
@@ -111,7 +111,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
const CandidateSegment &segment) {
auto use_direction =
boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)));
boolPairAnd(HasValidEdge(segment), CheckSegmentExclude(segment)));
return boolPairAnd(use_direction,
CheckApproach(input_coordinate, segment, approach));
},
@@ -139,7 +139,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
const CandidateSegment &segment) {
auto use_direction =
boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)));
boolPairAnd(HasValidEdge(segment), CheckSegmentExclude(segment)));
return boolPairAnd(use_direction,
CheckApproach(input_coordinate, segment, approach));
},
@@ -162,7 +162,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto results = rtree.Nearest(
input_coordinate,
[this, approach, &input_coordinate](const CandidateSegment &segment) {
return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)),
return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentExclude(segment)),
CheckApproach(input_coordinate, segment, approach));
},
[max_results](const std::size_t num_results, const CandidateSegment &) {
@@ -183,7 +183,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto results = rtree.Nearest(
input_coordinate,
[this, approach, &input_coordinate](const CandidateSegment &segment) {
return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)),
return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentExclude(segment)),
CheckApproach(input_coordinate, segment, approach));
},
[this, max_distance, max_results, input_coordinate](const std::size_t num_results,
@@ -212,7 +212,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment);
const auto valid_edges = HasValidEdge(segment);
const auto admissible_segments = CheckSegmentAvoid(segment);
const auto admissible_segments = CheckSegmentExclude(segment);
use_directions = boolPairAnd(use_directions, admissible_segments);
use_directions = boolPairAnd(use_directions, valid_edges);
use_directions =
@@ -259,7 +259,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto use_directions = std::make_pair(use_segment, use_segment);
const auto valid_edges = HasValidEdge(segment);
const auto admissible_segments = CheckSegmentAvoid(segment);
const auto admissible_segments = CheckSegmentExclude(segment);
use_directions = boolPairAnd(use_directions, admissible_segments);
use_directions = boolPairAnd(use_directions, valid_edges);
use_directions =
@@ -309,7 +309,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto use_segment =
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment);
const auto admissible_segments = CheckSegmentAvoid(segment);
const auto admissible_segments = CheckSegmentExclude(segment);
use_directions = boolPairAnd(use_directions, HasValidEdge(segment));
if (use_segment)
@@ -367,7 +367,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto use_segment =
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment);
const auto admissible_segments = CheckSegmentAvoid(segment);
const auto admissible_segments = CheckSegmentExclude(segment);
use_directions = boolPairAnd(use_directions, HasValidEdge(segment));
if (use_segment)
@@ -539,18 +539,18 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
max_distance;
}
std::pair<bool, bool> CheckSegmentAvoid(const CandidateSegment &segment) const
std::pair<bool, bool> CheckSegmentExclude(const CandidateSegment &segment) const
{
std::pair<bool, bool> valid = {true, true};
if (segment.data.forward_segment_id.enabled &&
datafacade.AvoidNode(segment.data.forward_segment_id.id))
datafacade.ExcludeNode(segment.data.forward_segment_id.id))
{
valid.first = false;
}
if (segment.data.reverse_segment_id.enabled &&
datafacade.AvoidNode(segment.data.reverse_segment_id.id))
datafacade.ExcludeNode(segment.data.reverse_segment_id.id))
{
valid.second = false;
}
+4 -4
View File
@@ -46,14 +46,14 @@ class BasePlugin
return true;
}
if (!algorithms.HasAvoidFlags() && !params.avoid.empty())
if (!algorithms.HasExcludeFlags() && !params.exclude.empty())
{
Error("NotImplemented", "This algorithm does not support avoid flags.", result);
Error("NotImplemented", "This algorithm does not support exclude flags.", result);
return false;
}
if (algorithms.HasAvoidFlags() && !params.avoid.empty())
if (algorithms.HasExcludeFlags() && !params.exclude.empty())
{
Error("InvalidValue", "Avoid flag combination is not supported.", result);
Error("InvalidValue", "Exclude flag combination is not supported.", result);
return false;
}
+3 -3
View File
@@ -54,7 +54,7 @@ class RoutingAlgorithmsInterface
virtual bool HasMapMatching() const = 0;
virtual bool HasManyToManySearch() const = 0;
virtual bool HasGetTileTurns() const = 0;
virtual bool HasAvoidFlags() const = 0;
virtual bool HasExcludeFlags() const = 0;
virtual bool IsValid() const = 0;
};
@@ -129,9 +129,9 @@ template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgo
return routing_algorithms::HasGetTileTurns<Algorithm>::value;
}
bool HasAvoidFlags() const final override
bool HasExcludeFlags() const final override
{
return routing_algorithms::HasAvoidFlags<Algorithm>::value;
return routing_algorithms::HasExcludeFlags<Algorithm>::value;
}
bool IsValid() const final override { return static_cast<bool>(facade); }
@@ -148,7 +148,7 @@ void routingStep(const DataFacade<Algorithm> &facade,
const auto node = forward_heap.DeleteMin();
const auto weight = forward_heap.GetKey(node);
BOOST_ASSERT(!facade.AvoidNode(node));
BOOST_ASSERT(!facade.ExcludeNode(node));
// Upper bound for the path source -> target with
// weight(source -> node) = weight weight(to -> target) ≤ reverse_weight
@@ -238,7 +238,7 @@ void routingStep(const DataFacade<Algorithm> &facade,
{
const NodeID to = facade.GetTarget(edge);
if (!facade.AvoidNode(to) &&
if (!facade.ExcludeNode(to) &&
checkParentCellRestriction(partition.GetCell(level + 1, to), args...))
{
BOOST_ASSERT_MSG(edge_data.weight > 0, "edge_weight invalid");