Add pruning based on @MoKob's idea in #1921

This commit is contained in:
Patrick Niklaus 2016-03-08 00:11:35 +01:00
parent e125f3a897
commit adc3bacea9
2 changed files with 24 additions and 12 deletions

View File

@ -40,6 +40,7 @@ using SubMatchingList = std::vector<SubMatching>;
constexpr static const unsigned MAX_BROKEN_STATES = 10;
constexpr static const double MAX_SPEED = 180 / 3.6; // 180km -> m/s
constexpr static const unsigned SUSPICIOUS_DISTANCE_DELTA = 100;
constexpr static const double MAX_DISTANCE_DELTA = 2000.;
// implements a hidden markov model map matching algorithm
template <class DataFacadeT>
@ -102,7 +103,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
}
else
{
return std::numeric_limits<double>::max();
return MAX_DISTANCE_DELTA;
}
}();
@ -200,6 +201,8 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
const auto haversine_distance = util::coordinate_calculation::haversineDistance(
prev_coordinate, current_coordinate);
// assumes minumum of 0.1 m/s
const int duration_uppder_bound = ((haversine_distance + max_distance_delta) * 0.25) * 10;
// compute d_t for this timestamp and the next one
for (const auto s : util::irange<std::size_t>(0u, prev_viterbi.size()))
@ -224,7 +227,6 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
forward_heap.Clear();
reverse_heap.Clear();
// get distance diff between loc1/2 and locs/s_prime
double network_distance;
if (super::facade->GetCoreSize() > 0)
{
@ -233,7 +235,8 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
network_distance = super::GetNetworkDistanceWithCore(
forward_heap, reverse_heap, forward_core_heap, reverse_core_heap,
prev_unbroken_timestamps_list[s].phantom_node,
current_timestamps_list[s_prime].phantom_node);
current_timestamps_list[s_prime].phantom_node,
duration_uppder_bound);
}
else
{
@ -243,6 +246,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
current_timestamps_list[s_prime].phantom_node);
}
// get distance diff between loc1/2 and locs/s_prime
const auto d_t = std::abs(network_distance - haversine_distance);
// very low probability transition -> prune

View File

@ -500,9 +500,11 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
std::int32_t &distance,
std::vector<NodeID> &packed_leg,
const bool force_loop_forward,
const bool force_loop_reverse) const
const bool force_loop_reverse,
const int duration_uppder_bound=INVALID_EDGE_WEIGHT) const
{
NodeID middle = SPECIAL_NODEID;
distance = duration_uppder_bound;
// get offset to account for offsets on phantom nodes on compressed edges
const auto min_edge_offset = std::min(0, forward_heap.MinKey());
@ -527,8 +529,9 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
}
// No path found for both target nodes?
if (INVALID_EDGE_WEIGHT == distance || SPECIAL_NODEID == middle)
if (duration_uppder_bound <= distance || SPECIAL_NODEID == middle)
{
distance = INVALID_EDGE_WEIGHT;
return;
}
@ -567,10 +570,11 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
int &distance,
std::vector<NodeID> &packed_leg,
const bool force_loop_forward,
const bool force_loop_reverse) const
const bool force_loop_reverse,
int duration_uppder_bound = INVALID_EDGE_WEIGHT) const
{
NodeID middle = SPECIAL_NODEID;
distance = INVALID_EDGE_WEIGHT;
distance = duration_uppder_bound;
std::vector<std::pair<NodeID, EdgeWeight>> forward_entry_points;
std::vector<std::pair<NodeID, EdgeWeight>> reverse_entry_points;
@ -678,8 +682,9 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
}
// No path found for both target nodes?
if (INVALID_EDGE_WEIGHT == distance || SPECIAL_NODEID == middle)
if (duration_uppder_bound <= distance || SPECIAL_NODEID == middle)
{
distance = INVALID_EDGE_WEIGHT;
return;
}
@ -776,7 +781,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
SearchEngineData::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom) const
const PhantomNode &target_phantom,
int duration_uppder_bound=INVALID_EDGE_WEIGHT) const
{
BOOST_ASSERT(forward_heap.Empty());
BOOST_ASSERT(reverse_heap.Empty());
@ -813,7 +819,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
int duration = INVALID_EDGE_WEIGHT;
std::vector<NodeID> packed_path;
SearchWithCore(forward_heap, reverse_heap, forward_core_heap, reverse_core_heap, duration,
packed_path, DO_NOT_FORCE_LOOPS, DO_NOT_FORCE_LOOPS);
packed_path, DO_NOT_FORCE_LOOPS, DO_NOT_FORCE_LOOPS, duration_uppder_bound);
double distance = std::numeric_limits<double>::max();
if (duration != INVALID_EDGE_WEIGHT)
@ -829,7 +835,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
double GetNetworkDistance(SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom) const
const PhantomNode &target_phantom,
int duration_uppder_bound=INVALID_EDGE_WEIGHT) const
{
BOOST_ASSERT(forward_heap.Empty());
BOOST_ASSERT(reverse_heap.Empty());
@ -865,7 +872,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
int duration = INVALID_EDGE_WEIGHT;
std::vector<NodeID> packed_path;
Search(forward_heap, reverse_heap, duration, packed_path, DO_NOT_FORCE_LOOPS, DO_NOT_FORCE_LOOPS);
Search(forward_heap, reverse_heap, duration, packed_path, DO_NOT_FORCE_LOOPS,
DO_NOT_FORCE_LOOPS, duration_uppder_bound);
if (duration == INVALID_EDGE_WEIGHT)
{