correct partial distances

This commit is contained in:
Dennis Luxen
2014-03-12 17:23:21 +01:00
parent ba37836e24
commit fdebec6448
6 changed files with 100 additions and 35 deletions
+10 -5
View File
@@ -119,7 +119,7 @@ public:
int upper_bound_to_shortest_path_distance = INVALID_EDGE_WEIGHT;
NodeID middle_node = SPECIAL_NODEID;
if(phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID ) {
SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.forward_node_id;
SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.forward_node_id << ", w: " << -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset();
forward_heap1.Insert(
phantom_node_pair.startPhantom.forward_node_id,
-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(),
@@ -127,7 +127,7 @@ public:
);
}
if(phantom_node_pair.startPhantom.reverse_node_id != SPECIAL_NODEID ) {
SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.reverse_node_id;
SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.reverse_node_id << ", w: " << -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset();
forward_heap1.Insert(
phantom_node_pair.startPhantom.reverse_node_id,
-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(),
@@ -136,7 +136,7 @@ public:
}
if(phantom_node_pair.targetPhantom.forward_node_id != SPECIAL_NODEID ) {
SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id;
SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id << ", w: " << phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset();
reverse_heap1.Insert(
phantom_node_pair.targetPhantom.forward_node_id,
phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(),
@@ -144,7 +144,7 @@ public:
);
}
if(phantom_node_pair.targetPhantom.reverse_node_id != SPECIAL_NODEID ) {
SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id;
SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id << ", w: " << phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset();
reverse_heap1.Insert(
phantom_node_pair.targetPhantom.reverse_node_id,
phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(),
@@ -186,6 +186,7 @@ public:
);
}
}
SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates";
sort_unique_resize( via_node_candidate_list );
SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates";
@@ -204,6 +205,10 @@ public:
packed_reverse_path
);
//TODO: leave early when no path found:
SimpleLogger().Write(logDEBUG) << "ub: " << upper_bound_to_shortest_path_distance;
boost::unordered_map<NodeID, int> approximated_forward_sharing;
boost::unordered_map<NodeID, int> approximated_reverse_sharing;
@@ -623,7 +628,7 @@ private:
const NodeID node = forward_heap.DeleteMin();
const int distance = forward_heap.GetKey(node);
const int scaled_distance = (distance-edge_expansion_offset)/(1.+VIAPATH_EPSILON);
// SimpleLogger().Write(logDEBUG) << "ub: " << *upper_bound_to_shortest_path_distance << ", distance: " << distance << ", scaled_distance: " << scaled_distance;
SimpleLogger().Write(logDEBUG) << "node: " << node << ", distance: " << distance << ", ub: " << *upper_bound_to_shortest_path_distance << ", scaled_distance: " << scaled_distance;
if(
(INVALID_EDGE_WEIGHT != *upper_bound_to_shortest_path_distance) &&
(scaled_distance > *upper_bound_to_shortest_path_distance)
+46 -7
View File
@@ -141,6 +141,7 @@ public:
const PhantomNodes & phantom_node_pair,
std::vector<PathData> & unpacked_path
) const {
SimpleLogger().Write(logDEBUG) << "packed_path.size: " << packed_path.size();
const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.startPhantom.forward_node_id);
const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.targetPhantom.forward_node_id);
@@ -262,10 +263,38 @@ public:
std::reverse(id_vector.begin(), id_vector.end() );
}
SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size();
const bool start_and_end_on_same_edge = (phantom_node_pair.startPhantom.packed_geometry_id == phantom_node_pair.targetPhantom.packed_geometry_id) && unpacked_path.empty();
SimpleLogger().Write(logDEBUG) << "unpacked_path.empty()=" << (unpacked_path.empty() ? "y" : "n");
const int start_index = ( start_and_end_on_same_edge ? phantom_node_pair.startPhantom.fwd_segment_position : 0 );
const int end_index = (target_traversed_in_reverse ? id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position : phantom_node_pair.targetPhantom.fwd_segment_position);
const bool is_local_path = (phantom_node_pair.startPhantom.packed_geometry_id == phantom_node_pair.targetPhantom.packed_geometry_id) && unpacked_path.empty();
SimpleLogger().Write(logDEBUG) << "is_local_path: " << (is_local_path ? "y" : "n");
// const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position - 1 : phantom_node_pair.startPhantom.fwd_segment_position ) : 0 );
int start_index = 0;
int end_index = phantom_node_pair.targetPhantom.fwd_segment_position;
SimpleLogger().Write(logDEBUG) << "case1";
if (target_traversed_in_reverse)
{
// start_index = id_vector.size() -1;
end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position;
// if (is_local_path)
// {
// start_index = id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position -1;
// }
}
if (is_local_path)
{
SimpleLogger().Write(logDEBUG) << "case3";
start_index = phantom_node_pair.startPhantom.fwd_segment_position - 1;
end_index = phantom_node_pair.targetPhantom.fwd_segment_position - 1;
if (target_traversed_in_reverse)
{
SimpleLogger().Write(logDEBUG) << "case4";
start_index = id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position - 1;
end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position - 1;
}
}
SimpleLogger().Write(logDEBUG) << "fetching from [" << start_index << "," << end_index << "]";
@@ -273,10 +302,10 @@ public:
// BOOST_ASSERT( start_index <= end_index );
for(
unsigned i = start_index;
i < end_index;
i != end_index;
( start_index < end_index ? ++i :--i)
) {
SimpleLogger().Write(logDEBUG) << facade->GetCoordinateOfNode(id_vector[i]);
SimpleLogger().Write(logDEBUG) << "[" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]);
unpacked_path.push_back(
PathData(
id_vector[i],
@@ -391,8 +420,18 @@ public:
}
}
int ComputeEdgeOffset(const PhantomNode & phantom) const {
return phantom.forward_weight + (phantom.isBidirected() ? phantom.reverse_weight : 0);
int ComputeEdgeOffset(const PhantomNode & phantom_node) const {
int weight_offset = 0;
if (phantom_node.forward_node_id != SPECIAL_NODEID)
{
weight_offset += phantom_node.GetForwardWeightPlusOffset();
}
if (phantom_node.reverse_node_id != SPECIAL_NODEID)
{
weight_offset += phantom_node.GetReverseWeightPlusOffset();
}
return weight_offset;
// return phantom_node.forward_weight + (phantom_node.isBidirected() ? phantom_node.reverse_weight : 0);
}
};
+22 -16
View File
@@ -63,6 +63,8 @@ public:
if( phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX() ) {
// raw_route_data.lengthOfShortestPath = INT_MAX;
// raw_route_data.lengthOfAlternativePath = INT_MAX;
SimpleLogger().Write(logDEBUG) << "returning early";
return;
}
}
@@ -108,14 +110,15 @@ public:
search_from_1st_node &&
phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID
) {
SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.startPhantom.forward_node_id << ", w: " << -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset();
forward_heap1.Insert(
phantom_node_pair.startPhantom.forward_node_id,
distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(),
-distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(),
phantom_node_pair.startPhantom.forward_node_id
);
forward_heap2.Insert(
phantom_node_pair.startPhantom.forward_node_id,
distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(),
-distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(),
phantom_node_pair.startPhantom.forward_node_id
);
}
@@ -123,20 +126,22 @@ public:
search_from_2nd_node &&
phantom_node_pair.startPhantom.reverse_node_id != SPECIAL_NODEID
) {
SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.startPhantom.reverse_node_id << ", w: " << -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset();
forward_heap1.Insert(
phantom_node_pair.startPhantom.reverse_node_id,
distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(),
-distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(),
phantom_node_pair.startPhantom.reverse_node_id
);
forward_heap2.Insert(
phantom_node_pair.startPhantom.reverse_node_id,
distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(),
-distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(),
phantom_node_pair.startPhantom.reverse_node_id
);
}
//insert new backward nodes into backward heap, unadjusted.
if( phantom_node_pair.targetPhantom.forward_node_id != SPECIAL_NODEID ) {
SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id << ", w: " << phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset();
reverse_heap1.Insert(
phantom_node_pair.targetPhantom.forward_node_id,
phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(),
@@ -145,6 +150,7 @@ public:
}
if( phantom_node_pair.targetPhantom.reverse_node_id != SPECIAL_NODEID ) {
SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id << ", w: " << phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset();
reverse_heap2.Insert(
phantom_node_pair.targetPhantom.reverse_node_id,
phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(),
@@ -363,22 +369,22 @@ public:
for(unsigned i = 0; i < packed_legs1.size(); ++i){
BOOST_ASSERT( !phantom_nodes_vector.empty() );
const bool at_beginning = (0 == i);
const bool at_end = (packed_legs1.size() == i+1);
const bool at_beginning = (packed_legs1[i] == packed_legs1.front());
const bool at_end = (packed_legs1[i] == packed_legs1.back());
BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size() );
PhantomNodes unpack_phantom_node_pair = phantom_nodes_vector[i];
if (!at_beginning)
{
unpack_phantom_node_pair.startPhantom.packed_geometry_id = SPECIAL_EDGEID;
unpack_phantom_node_pair.startPhantom.fwd_segment_position = 0;
}
// if (!at_beginning)
// {
// unpack_phantom_node_pair.startPhantom.packed_geometry_id = SPECIAL_EDGEID;
// unpack_phantom_node_pair.startPhantom.fwd_segment_position = 0;
// }
if (!at_end)
{
unpack_phantom_node_pair.targetPhantom.packed_geometry_id = SPECIAL_EDGEID;
unpack_phantom_node_pair.targetPhantom.fwd_segment_position = 0;
}
// if (!at_end)
// {
// unpack_phantom_node_pair.targetPhantom.packed_geometry_id = SPECIAL_EDGEID;
// unpack_phantom_node_pair.targetPhantom.fwd_segment_position = 0;
// }
super::UnpackPath(
// -- packed input