Add duration to edges and use it in table plugin

This commit is contained in:
Michael Krasnyk
2017-01-19 22:52:09 +01:00
committed by Patrick Niklaus
parent c059d15cb9
commit 25baf51a2c
24 changed files with 312 additions and 126 deletions
+1 -1
View File
@@ -113,7 +113,7 @@ class TableAPI final : public BaseAPI
row_end_iterator,
json_row.values.begin(),
[](const EdgeWeight duration) {
if (duration == INVALID_EDGE_WEIGHT)
if (duration == MAXIMAL_EDGE_DURATION)
{
return util::json::Value(util::json::Null());
}
+12 -6
View File
@@ -369,8 +369,10 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
// Find the node-based-edge that this belongs to, and directly
// calculate the forward_weight, forward_offset, reverse_weight, reverse_offset
EdgeWeight forward_offset = 0, forward_weight = 0, forward_duration = 0;
EdgeWeight reverse_offset = 0, reverse_weight = 0, reverse_duration = 0;
EdgeWeight forward_weight_offset = 0, forward_weight = 0;
EdgeWeight reverse_weight_offset = 0, reverse_weight = 0;
EdgeWeight forward_duration_offset = 0, forward_duration = 0;
EdgeWeight reverse_duration_offset = 0, reverse_duration = 0;
const std::vector<EdgeWeight> forward_weight_vector =
datafacade.GetUncompressedForwardWeights(data.packed_geometry_id);
@@ -383,7 +385,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
for (std::size_t i = 0; i < data.fwd_segment_position; i++)
{
forward_offset += forward_weight_vector[i];
forward_weight_offset += forward_weight_vector[i];
forward_duration_offset += forward_duration_vector[i];
}
forward_weight = forward_weight_vector[data.fwd_segment_position];
forward_duration = forward_duration_vector[data.fwd_segment_position];
@@ -393,7 +396,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
for (std::size_t i = 0; i < reverse_weight_vector.size() - data.fwd_segment_position - 1;
i++)
{
reverse_offset += reverse_weight_vector[i];
reverse_weight_offset += reverse_weight_vector[i];
reverse_duration_offset += reverse_duration_vector[i];
}
reverse_weight =
reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1];
@@ -415,10 +419,12 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto transformed = PhantomNodeWithDistance{PhantomNode{data,
forward_weight,
reverse_weight,
forward_weight_offset,
reverse_weight_offset,
forward_duration,
reverse_duration,
forward_offset,
reverse_offset,
forward_duration_offset,
reverse_duration_offset,
point_on_segment,
input_coordinate},
current_perpendicular_distance};
+2 -2
View File
@@ -63,8 +63,8 @@ struct Hint
friend std::ostream &operator<<(std::ostream &, const Hint &);
};
static_assert(sizeof(Hint) == 64 + 4, "Hint is bigger than expected");
constexpr std::size_t ENCODED_HINT_SIZE = 92;
static_assert(sizeof(Hint) == 72 + 4, "Hint is bigger than expected");
constexpr std::size_t ENCODED_HINT_SIZE = 104;
static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint),
"ENCODED_HINT_SIZE does not match size of Hint");
}
+47 -23
View File
@@ -51,10 +51,12 @@ struct PhantomNode
unsigned name_id,
EdgeWeight forward_weight,
EdgeWeight reverse_weight,
EdgeWeight forward_weight_offset,
EdgeWeight reverse_weight_offset,
EdgeWeight forward_duration,
EdgeWeight reverse_duration,
EdgeWeight forward_offset,
EdgeWeight reverse_offset,
EdgeWeight forward_duration_offset,
EdgeWeight reverse_duration_offset,
unsigned packed_geometry_id_,
bool is_tiny_component,
unsigned component_id,
@@ -65,12 +67,13 @@ struct PhantomNode
extractor::TravelMode backward_travel_mode)
: forward_segment_id(forward_segment_id), reverse_segment_id(reverse_segment_id),
name_id(name_id), forward_weight(forward_weight), reverse_weight(reverse_weight),
forward_duration(forward_duration), reverse_duration(reverse_duration),
forward_offset(forward_offset), reverse_offset(reverse_offset),
packed_geometry_id(packed_geometry_id_), component{component_id, is_tiny_component},
location(std::move(location)), input_location(std::move(input_location)),
fwd_segment_position(fwd_segment_position), forward_travel_mode(forward_travel_mode),
backward_travel_mode(backward_travel_mode)
forward_weight_offset(forward_weight_offset),
reverse_weight_offset(reverse_weight_offset), forward_duration(forward_duration),
reverse_duration(reverse_duration), forward_duration_offset(forward_duration_offset),
reverse_duration_offset(reverse_duration_offset), packed_geometry_id(packed_geometry_id_),
component{component_id, is_tiny_component}, location(std::move(location)),
input_location(std::move(input_location)), fwd_segment_position(fwd_segment_position),
forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode)
{
}
@@ -78,8 +81,9 @@ struct PhantomNode
: forward_segment_id{SPECIAL_SEGMENTID, false},
reverse_segment_id{SPECIAL_SEGMENTID, false},
name_id(std::numeric_limits<unsigned>::max()), forward_weight(INVALID_EDGE_WEIGHT),
reverse_weight(INVALID_EDGE_WEIGHT), forward_duration(INVALID_EDGE_WEIGHT),
reverse_duration(INVALID_EDGE_WEIGHT), forward_offset(0), reverse_offset(0),
reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0),
forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION),
forward_duration_offset(0), reverse_duration_offset(0),
packed_geometry_id(SPECIAL_GEOMETRYID), component{INVALID_COMPONENTID, false},
fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE),
backward_travel_mode(TRAVEL_MODE_INACCESSIBLE)
@@ -89,13 +93,25 @@ struct PhantomNode
EdgeWeight GetForwardWeightPlusOffset() const
{
BOOST_ASSERT(forward_segment_id.enabled);
return forward_offset + forward_weight;
return forward_weight_offset + forward_weight;
}
EdgeWeight GetReverseWeightPlusOffset() const
{
BOOST_ASSERT(reverse_segment_id.enabled);
return reverse_offset + reverse_weight;
return reverse_weight_offset + reverse_weight;
}
EdgeWeight GetForwardDuration() const
{
BOOST_ASSERT(forward_segment_id.enabled);
return forward_duration + forward_duration_offset;
}
EdgeWeight GetReverseDuration() const
{
BOOST_ASSERT(reverse_segment_id.enabled);
return reverse_duration + reverse_duration_offset;
}
bool IsBidirected() const { return forward_segment_id.enabled && reverse_segment_id.enabled; }
@@ -106,8 +122,8 @@ struct PhantomNode
(reverse_segment_id.id < number_of_nodes)) &&
((forward_weight != INVALID_EDGE_WEIGHT) ||
(reverse_weight != INVALID_EDGE_WEIGHT)) &&
((forward_duration != INVALID_EDGE_WEIGHT) ||
(reverse_duration != INVALID_EDGE_WEIGHT)) &&
((forward_duration != MAXIMAL_EDGE_DURATION) ||
(reverse_duration != MAXIMAL_EDGE_DURATION)) &&
(component.id != INVALID_COMPONENTID) && (name_id != INVALID_NAMEID);
}
@@ -124,17 +140,21 @@ struct PhantomNode
explicit PhantomNode(const OtherT &other,
EdgeWeight forward_weight,
EdgeWeight reverse_weight,
EdgeWeight forward_weight_offset,
EdgeWeight reverse_weight_offset,
EdgeWeight forward_duration,
EdgeWeight reverse_duration,
EdgeWeight forward_offset,
EdgeWeight reverse_offset,
EdgeWeight forward_duration_offset,
EdgeWeight reverse_duration_offset,
const util::Coordinate location,
const util::Coordinate input_location)
: forward_segment_id{other.forward_segment_id},
reverse_segment_id{other.reverse_segment_id}, name_id{other.name_id},
forward_weight{forward_weight}, reverse_weight{reverse_weight},
forward_duration{forward_duration}, reverse_duration{reverse_duration},
forward_offset{forward_offset}, reverse_offset{reverse_offset},
forward_weight_offset{forward_weight_offset},
reverse_weight_offset{reverse_weight_offset}, forward_duration{forward_duration},
reverse_duration{reverse_duration}, forward_duration_offset{forward_duration_offset},
reverse_duration_offset{reverse_duration_offset},
packed_geometry_id{other.packed_geometry_id},
component{other.component.id, other.component.is_tiny}, location{location},
input_location{input_location}, fwd_segment_position{other.fwd_segment_position},
@@ -148,10 +168,12 @@ struct PhantomNode
unsigned name_id;
EdgeWeight forward_weight;
EdgeWeight reverse_weight;
EdgeWeight forward_weight_offset; // TODO: try to remove -> requires path unpacking changes
EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes
EdgeWeight forward_duration;
EdgeWeight reverse_duration;
EdgeWeight forward_offset;
EdgeWeight reverse_offset;
EdgeWeight forward_duration_offset; // TODO: try to remove -> requires path unpacking changes
EdgeWeight reverse_duration_offset; // TODO: try to remove -> requires path unpacking changes
unsigned packed_geometry_id;
struct ComponentType
{
@@ -169,7 +191,7 @@ struct PhantomNode
extractor::TravelMode backward_travel_mode;
};
static_assert(sizeof(PhantomNode) == 64, "PhantomNode has more padding then expected");
static_assert(sizeof(PhantomNode) == 72, "PhantomNode has more padding then expected");
using PhantomNodePair = std::pair<PhantomNode, PhantomNode>;
@@ -199,10 +221,12 @@ inline std::ostream &operator<<(std::ostream &out, const PhantomNode &pn)
<< "name: " << pn.name_id << ", "
<< "fwd-w: " << pn.forward_weight << ", "
<< "rev-w: " << pn.reverse_weight << ", "
<< "fwd-o: " << pn.forward_weight_offset << ", "
<< "rev-o: " << pn.reverse_weight_offset << ", "
<< "fwd-d: " << pn.forward_duration << ", "
<< "rev-d: " << pn.reverse_duration << ", "
<< "fwd-o: " << pn.forward_offset << ", "
<< "rev-o: " << pn.reverse_offset << ", "
<< "fwd-do: " << pn.forward_duration_offset << ", "
<< "rev-do: " << pn.reverse_duration_offset << ", "
<< "geom: " << pn.packed_geometry_id << ", "
<< "comp: " << pn.component.is_tiny << " / " << pn.component.id << ", "
<< "pos: " << pn.fwd_segment_position << ", "
@@ -138,7 +138,7 @@ class AlternativeRouting final : private BasicRoutingInterface
else
{
// check whether there is a loop present at the node
const auto loop_weight = super::GetLoopWeight(facade, node);
const auto loop_weight = super::GetLoopWeight<false>(facade, node);
const EdgeWeight new_weight_with_loop = new_weight + loop_weight;
if (loop_weight != INVALID_EDGE_WEIGHT &&
new_weight_with_loop <= *upper_bound_to_shortest_path_weight)
@@ -23,15 +23,16 @@ namespace routing_algorithms
class ManyToManyRouting final : public BasicRoutingInterface
{
using super = BasicRoutingInterface;
using QueryHeap = SearchEngineData::QueryHeap;
using QueryHeap = SearchEngineData::ManyToManyQueryHeap;
SearchEngineData &engine_working_data;
struct NodeBucket
{
unsigned target_id; // essentially a row in the weight matrix
EdgeWeight weight;
NodeBucket(const unsigned target_id, const EdgeWeight weight)
: target_id(target_id), weight(weight)
EdgeWeight duration;
NodeBucket(const unsigned target_id, const EdgeWeight weight, const EdgeWeight duration)
: target_id(target_id), weight(weight), duration(duration)
{
}
};
@@ -56,7 +57,8 @@ class ManyToManyRouting final : public BasicRoutingInterface
const unsigned number_of_targets,
QueryHeap &query_heap,
const SearchSpaceWithBuckets &search_space_with_buckets,
std::vector<EdgeWeight> &result_table) const;
std::vector<EdgeWeight> &weights_table,
std::vector<EdgeWeight> &durations_table) const;
void BackwardRoutingStep(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
const unsigned column_idx,
@@ -67,6 +69,7 @@ class ManyToManyRouting final : public BasicRoutingInterface
inline void RelaxOutgoingEdges(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
const NodeID node,
const EdgeWeight weight,
const EdgeWeight duration,
QueryHeap &query_heap) const
{
for (auto edge : facade->GetAdjacentEdgeRange(node))
@@ -77,20 +80,22 @@ class ManyToManyRouting final : public BasicRoutingInterface
{
const NodeID to = facade->GetTarget(edge);
const EdgeWeight edge_weight = data.weight;
const EdgeWeight edge_duration = data.duration;
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
const EdgeWeight to_weight = weight + edge_weight;
const EdgeWeight to_duration = duration + edge_duration;
// New Node discovered -> Add to Heap + Node Info Storage
if (!query_heap.WasInserted(to))
{
query_heap.Insert(to, to_weight, node);
query_heap.Insert(to, to_weight, {node, to_duration});
}
// Found a shorter Path -> Update weight
else if (to_weight < query_heap.GetKey(to))
{
// new parent
query_heap.GetData(to).parent = node;
query_heap.GetData(to) = {node, to_duration};
query_heap.DecreaseKey(to, to_weight);
}
}
@@ -16,6 +16,7 @@
#include <cstdint>
#include <algorithm>
#include <functional>
#include <iterator>
#include <memory>
#include <numeric>
@@ -77,8 +78,26 @@ class BasicRoutingInterface
const bool force_loop_forward,
const bool force_loop_reverse) const;
template <bool UseDuration>
EdgeWeight GetLoopWeight(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
NodeID node) const;
NodeID node) const
{
EdgeWeight loop_weight = UseDuration ? MAXIMAL_EDGE_DURATION : INVALID_EDGE_WEIGHT;
for (auto edge : facade->GetAdjacentEdgeRange(node))
{
const auto &data = facade->GetEdgeData(edge);
if (data.forward)
{
const NodeID to = facade->GetTarget(edge);
if (to == node)
{
const auto value = UseDuration ? data.duration : data.weight;
loop_weight = std::min(loop_weight, value);
}
}
}
return loop_weight;
}
template <typename RandomIter>
void UnpackPath(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
+17
View File
@@ -17,24 +17,41 @@ struct HeapData
/* explicit */ HeapData(NodeID p) : parent(p) {}
};
struct ManyToManyHeapData : HeapData
{
EdgeWeight duration;
ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {}
};
struct SearchEngineData
{
using QueryHeap = util::
BinaryHeap<NodeID, NodeID, EdgeWeight, HeapData, util::UnorderedMapStorage<NodeID, int>>;
using SearchEngineHeapPtr = boost::thread_specific_ptr<QueryHeap>;
using ManyToManyQueryHeap = util::BinaryHeap<NodeID,
NodeID,
EdgeWeight,
ManyToManyHeapData,
util::UnorderedMapStorage<NodeID, int>>;
using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>;
static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1;
static SearchEngineHeapPtr forward_heap_2;
static SearchEngineHeapPtr reverse_heap_2;
static SearchEngineHeapPtr forward_heap_3;
static SearchEngineHeapPtr reverse_heap_3;
static ManyToManyHeapPtr many_to_many_heap;
void InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes);
void InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes);
void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes);
void InitializeOrClearManyToManyThreadLocalStorage(const unsigned number_of_nodes);
};
}
}