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

View File

@ -31,7 +31,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/assert.hpp>
#ifndef NDEBUG
#include <bitset>
#endif
#include <iostream>
#include <limits>
@ -44,6 +46,7 @@ FixedPointCoordinate::FixedPointCoordinate(int lat, int lon)
: lat(lat),
lon(lon)
{
#ifndef NDEBUG
if(0 != (std::abs(lat) >> 30)) {
std::bitset<32> y(lat);
SimpleLogger().Write(logDEBUG) << "broken lat: " << lat << ", bits: " << y;
@ -52,6 +55,7 @@ FixedPointCoordinate::FixedPointCoordinate(int lat, int lon)
std::bitset<32> x(lon);
SimpleLogger().Write(logDEBUG) << "broken lon: " << lon << ", bits: " << x;
}
#endif
}
void FixedPointCoordinate::Reset() {
@ -59,7 +63,8 @@ void FixedPointCoordinate::Reset() {
lon = std::numeric_limits<int>::min();
}
bool FixedPointCoordinate::isSet() const {
return (std::numeric_limits<int>::min() != lat) && (std::numeric_limits<int>::min() != lon);
return (std::numeric_limits<int>::min() != lat) &&
(std::numeric_limits<int>::min() != lon);
}
bool FixedPointCoordinate::isValid() const {
if(

View File

@ -59,11 +59,11 @@ struct PhantomNode {
int GetForwardWeightPlusOffset() const {
return forward_weight - forward_offset;
return forward_weight + forward_offset;
}
int GetReverseWeightPlusOffset() const {
return reverse_weight + reverse_offset;
return reverse_offset + reverse_weight;
}
void Reset() {
@ -123,7 +123,7 @@ struct PhantomNodes {
//TODO: Rename to: BothPhantomNodesAreInvalid
bool AtLeastOnePhantomNodeIsUINTMAX() const {
return (startPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.forward_node_id == SPECIAL_NODEID);
return (startPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.reverse_node_id == SPECIAL_NODEID);
}
bool PhantomNodesHaveEqualLocation() const {

View File

@ -758,15 +758,25 @@ public:
ratio = std::min(1., ratio);
}
result_phantom_node.forward_weight *= ratio;
if( INT_MAX != result_phantom_node.reverse_weight ) {
result_phantom_node.reverse_weight *= (1.-ratio);
SimpleLogger().Write(logDEBUG) << "result_phantom_node.forward_offset: " << result_phantom_node.forward_offset;
SimpleLogger().Write(logDEBUG) << "result_phantom_node.reverse_offset: " << result_phantom_node.reverse_offset;
SimpleLogger().Write(logDEBUG) << "result_phantom_node.forward_weight: " << result_phantom_node.forward_weight;
SimpleLogger().Write(logDEBUG) << "result_phantom_node.reverse_weight: " << result_phantom_node.reverse_weight;
if (SPECIAL_NODEID != result_phantom_node.forward_node_id)
{
result_phantom_node.forward_weight *= (1.-ratio);
}
if( SPECIAL_NODEID != result_phantom_node.reverse_node_id )
{
result_phantom_node.reverse_weight *= ratio;
}
result_phantom_node.ratio = ratio;
SimpleLogger().Write(logDEBUG) << "result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate;
SimpleLogger().Write(logDEBUG) << "fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id;
SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight << ", ratio: " << result_phantom_node.ratio;
SimpleLogger().Write(logDEBUG) << "fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset << ", ratio: " << result_phantom_node.ratio;
SimpleLogger().Write(logDEBUG) << "bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n");
SimpleLogger().Write(logDEBUG) << "name id: " << result_phantom_node.name_id;
SimpleLogger().Write(logDEBUG) << "geom id: " << result_phantom_node.packed_geometry_id;

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)

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);
}
};

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