All good, but needs unpacking of start and end

This commit is contained in:
Dennis Luxen 2014-02-21 16:55:41 +01:00
parent e68c750389
commit 5bde545ce3
15 changed files with 169 additions and 70 deletions

View File

@ -306,7 +306,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(
m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION;
} }
BOOST_ASSERT( forward_data.edgeBasedNodeID != std::numeric_limits<unsigned>::max() ); BOOST_ASSERT( forward_data.edgeBasedNodeID != std::numeric_limits<unsigned>::max() );
SimpleLogger().Write() << "e1: " << e1 << "u: " << u << ", v: " << v; // SimpleLogger().Write() << "e1: " << e1 << "u: " << u << ", v: " << v;
if( forward_data.ignore_in_grid ) { if( forward_data.ignore_in_grid ) {
// SimpleLogger().Write(logDEBUG) << "skipped edge at " << m_node_info_list[u].lat << "," << // SimpleLogger().Write(logDEBUG) << "skipped edge at " << m_node_info_list[u].lat << "," <<
@ -324,7 +324,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(
if ( e2 == m_node_based_graph->EndEdges(v) ) { if ( e2 == m_node_based_graph->EndEdges(v) ) {
SimpleLogger().Write(logDEBUG) << "Did not find edge (" << v << "," << u << ")"; SimpleLogger().Write(logDEBUG) << "Did not find edge (" << v << "," << u << ")";
} }
#endif NDEBUG #endif
BOOST_ASSERT( e2 != std::numeric_limits<unsigned>::max() ); BOOST_ASSERT( e2 != std::numeric_limits<unsigned>::max() );
BOOST_ASSERT( e2 < m_node_based_graph->EndEdges(v) ); BOOST_ASSERT( e2 < m_node_based_graph->EndEdges(v) );
const EdgeData & reverse_data = m_node_based_graph->GetEdgeData(e2); const EdgeData & reverse_data = m_node_based_graph->GetEdgeData(e2);
@ -470,6 +470,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(
reverse_dist_prefix_sum[geometry_size-1-i] reverse_dist_prefix_sum[geometry_size-1-i]
) )
); );
BOOST_ASSERT( m_edge_based_node_list.back().IsCompressed() );
first_node_of_edge = last_coordinate_id; first_node_of_edge = last_coordinate_id;
} }
//TODO: Manually reconstruct last edge. //TODO: Manually reconstruct last edge.
@ -518,6 +519,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(
0 0
) )
); );
BOOST_ASSERT( !m_edge_based_node_list.back().IsCompressed() );
} }
} }
@ -742,7 +744,7 @@ void EdgeBasedGraphFactory::Run(
if( u > v ) { if( u > v ) {
continue; continue;
} }
BOOST_ASSERT( u < v ); // BOOST_ASSERT( u < v );
BOOST_ASSERT( edge_data.type != SHRT_MAX ); BOOST_ASSERT( edge_data.type != SHRT_MAX );
//Note: edges that end on barrier nodes or on a turn restriction //Note: edges that end on barrier nodes or on a turn restriction

View File

@ -26,9 +26,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <osrm/Coordinate.h> #include <osrm/Coordinate.h>
#include "../Util/SimpleLogger.h"
#include "../Util/StringUtil.h" #include "../Util/StringUtil.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <bitset>
#include <iostream>
#include <limits> #include <limits>
FixedPointCoordinate::FixedPointCoordinate() FixedPointCoordinate::FixedPointCoordinate()
@ -39,7 +43,16 @@ FixedPointCoordinate::FixedPointCoordinate()
FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) FixedPointCoordinate::FixedPointCoordinate(int lat, int lon)
: lat(lat), : lat(lat),
lon(lon) lon(lon)
{ } {
if(0 != (lat >> 30)) {
std::bitset<32> y(lat);
SimpleLogger().Write(logDEBUG) << "broken lat: " << lat << ", bits: " << y;
}
if(0 != (lon >> 30)) {
std::bitset<32> x(lon);
SimpleLogger().Write(logDEBUG) << "broken lon: " << lon << ", bits: " << x;
}
}
void FixedPointCoordinate::Reset() { void FixedPointCoordinate::Reset() {
lat = std::numeric_limits<int>::min(); lat = std::numeric_limits<int>::min();
@ -159,3 +172,7 @@ void FixedPointCoordinate::convertInternalReversedCoordinateToString(
convertInternalLatLonToString(coord.lon, tmp); convertInternalLatLonToString(coord.lon, tmp);
output += tmp; output += tmp;
} }
void FixedPointCoordinate::Output(std::ostream & out) const {//, FixedPointCoordinate & c) {
out << "(" << lat << "," << lon << ")";
}

View File

@ -23,8 +23,8 @@ struct EdgeBasedNode {
name_id(std::numeric_limits<unsigned>::max()), name_id(std::numeric_limits<unsigned>::max()),
forward_weight(std::numeric_limits<int>::max() >> 1), forward_weight(std::numeric_limits<int>::max() >> 1),
reverse_weight(std::numeric_limits<int>::max() >> 1), reverse_weight(std::numeric_limits<int>::max() >> 1),
forward_offset_to_edge_based_node(0), forward_offset(0),
reverse_offset_to_edge_based_node(0) reverse_offset(0)
{ } { }
EdgeBasedNode( EdgeBasedNode(
@ -38,8 +38,8 @@ struct EdgeBasedNode {
NodeID name_id, NodeID name_id,
int forward_weight, int forward_weight,
int reverse_weight, int reverse_weight,
int forward_offset_to_edge_based_node, int forward_offset,
int reverse_offset_to_edge_based_node int reverse_offset
) : ) :
forward_edge_based_node_id(forward_edge_based_node_id), forward_edge_based_node_id(forward_edge_based_node_id),
reverse_edge_based_node_id(reverse_edge_based_node_id), reverse_edge_based_node_id(reverse_edge_based_node_id),
@ -51,8 +51,8 @@ struct EdgeBasedNode {
name_id(name_id), name_id(name_id),
forward_weight(forward_weight), forward_weight(forward_weight),
reverse_weight(reverse_weight), reverse_weight(reverse_weight),
forward_offset_to_edge_based_node(forward_offset_to_edge_based_node), forward_offset(forward_offset),
reverse_offset_to_edge_based_node(reverse_offset_to_edge_based_node) reverse_offset(reverse_offset)
{ } { }
// Computes: // Computes:

View File

@ -33,11 +33,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
struct PhantomNode { struct PhantomNode {
PhantomNode() : PhantomNode() :
forward_node_id(std::numeric_limits<unsigned>::max()), forward_node_id( SPECIAL_NODEID ),
reverse_node_id(std::numeric_limits<unsigned>::max()), reverse_node_id( SPECIAL_NODEID ),
name_id(std::numeric_limits<unsigned>::max()), name_id( std::numeric_limits<unsigned>::max() ),
forward_weight(INT_MAX), forward_weight(INVALID_EDGE_WEIGHT),
reverse_weight(INT_MAX), reverse_weight(INVALID_EDGE_WEIGHT),
forward_offset(0),
reverse_offset(0),
ratio(0.) ratio(0.)
{ } { }
@ -46,25 +48,44 @@ struct PhantomNode {
unsigned name_id; unsigned name_id;
int forward_weight; int forward_weight;
int reverse_weight; int reverse_weight;
int forward_offset;
int reverse_offset;
double ratio; double ratio;
FixedPointCoordinate location; FixedPointCoordinate location;
int GetForwardWeightPlusOffset() const {
return forward_weight + forward_offset;
}
int GetReverseWeightPlusOffset() const {
return reverse_weight + reverse_offset;
}
void Reset() { void Reset() {
forward_node_id = std::numeric_limits<unsigned>::max(); forward_node_id = SPECIAL_NODEID;
name_id = std::numeric_limits<unsigned>::max(); name_id = SPECIAL_NODEID;
forward_weight = INT_MAX; forward_weight = INVALID_EDGE_WEIGHT;
reverse_weight = INT_MAX; reverse_weight = INVALID_EDGE_WEIGHT;
forward_offset = 0;
reverse_offset = 0;
ratio = 0.; ratio = 0.;
location.Reset(); location.Reset();
} }
bool isBidirected() const { bool isBidirected() const {
return forward_node_id != UINT_MAX && reverse_node_id != UINT_MAX; return ( forward_node_id != SPECIAL_NODEID ) &&
( reverse_node_id != SPECIAL_NODEID );
} }
bool IsCompressed() const {
return (forward_offset != 0) || (reverse_offset != 0);
}
bool isValid(const unsigned numberOfNodes) const { bool isValid(const unsigned numberOfNodes) const {
return return
location.isValid() && location.isValid() &&
( (forward_node_id < numberOfNodes) || (reverse_node_id < numberOfNodes) ) && ( (forward_node_id < numberOfNodes) || (reverse_node_id < numberOfNodes) ) &&
( (forward_weight != INT_MAX) || (reverse_weight != INT_MAX) ) && ( (forward_weight != INVALID_EDGE_WEIGHT) || (reverse_weight != INVALID_EDGE_WEIGHT) ) &&
(ratio >= 0.) && (ratio >= 0.) &&
(ratio <= 1.) && (ratio <= 1.) &&
(name_id != std::numeric_limits<unsigned>::max()); (name_id != std::numeric_limits<unsigned>::max());
@ -88,7 +109,7 @@ struct PhantomNodes {
} }
bool AtLeastOnePhantomNodeIsUINTMAX() const { bool AtLeastOnePhantomNodeIsUINTMAX() const {
return !(startPhantom.forward_node_id == std::numeric_limits<unsigned>::max() || targetPhantom.forward_node_id == std::numeric_limits<unsigned>::max()); return !(startPhantom.forward_node_id == SPECIAL_NODEID || targetPhantom.forward_node_id == SPECIAL_NODEID);
} }
bool PhantomNodesHaveEqualLocation() const { bool PhantomNodesHaveEqualLocation() const {

View File

@ -115,6 +115,8 @@ public:
std::size_t size() const { return m_size; } std::size_t size() const { return m_size; }
bool empty() const { return 0 == size(); }
DataT & operator[](const unsigned index) { DataT & operator[](const unsigned index) {
BOOST_ASSERT_MSG(index < m_size, "invalid size"); BOOST_ASSERT_MSG(index < m_size, "invalid size");
return m_ptr[index]; return m_ptr[index];

View File

@ -115,6 +115,7 @@ public:
u << "," << data.id << "," << v << ")"; u << "," << data.id << "," << v << ")";
data.shortcut = false; data.shortcut = false;
BOOST_ASSERT(false);
} }
eid2 = FindEdgeInEitherDirection(data.id, v); eid2 = FindEdgeInEitherDirection(data.id, v);
if(eid2 == UINT_MAX) { if(eid2 == UINT_MAX) {
@ -122,6 +123,7 @@ public:
"cannot find second segment of edge (" << "cannot find second segment of edge (" <<
u << "," << data.id << "," << v << ")"; u << "," << data.id << "," << v << ")";
data.shortcut = false; data.shortcut = false;
BOOST_ASSERT(false);
} }
} }
} }
@ -165,7 +167,7 @@ public:
//searches for a specific edge //searches for a specific edge
EdgeIterator FindEdge( const NodeIterator from, const NodeIterator to ) const { EdgeIterator FindEdge( const NodeIterator from, const NodeIterator to ) const {
EdgeIterator smallestEdge = SPECIAL_EDGEID; EdgeIterator smallestEdge = SPECIAL_EDGEID;
EdgeWeight smallestWeight = UINT_MAX; EdgeWeight smallestWeight = INVALID_EDGE_WEIGHT;
for ( EdgeIterator edge = BeginEdges( from ); edge < EndEdges(from); edge++ ) { for ( EdgeIterator edge = BeginEdges( from ); edge < EndEdges(from); edge++ ) {
const NodeID target = GetTarget(edge); const NodeID target = GetTarget(edge);
const EdgeWeight weight = GetEdgeData(edge).distance; const EdgeWeight weight = GetEdgeData(edge).distance;

View File

@ -51,6 +51,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/algorithm/minmax_element.hpp> #include <boost/algorithm/minmax_element.hpp>
#include <boost/range/algorithm_ext/erase.hpp> #include <boost/range/algorithm_ext/erase.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
@ -68,7 +69,7 @@ const static uint32_t RTREE_LEAF_NODE_SIZE = 1170;
static boost::thread_specific_ptr<boost::filesystem::ifstream> thread_local_rtree_stream; static boost::thread_specific_ptr<boost::filesystem::ifstream> thread_local_rtree_stream;
template<class DataT, bool UseSharedMemory = false> template<class DataT, class CoordinateListT = std::vector<FixedPointCoordinate>, bool UseSharedMemory = false>
class StaticRTree : boost::noncopyable { class StaticRTree : boost::noncopyable {
public: public:
struct RectangleInt2D { struct RectangleInt2D {
@ -289,8 +290,9 @@ private:
typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree; typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree;
uint64_t m_element_count; uint64_t m_element_count;
const std::string m_leaf_node_filename; const std::string m_leaf_node_filename;
boost::shared_ptr<CoordinateListT> m_coordinate_list;
public: public:
//Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1] //Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1]
explicit StaticRTree( explicit StaticRTree(
@ -426,9 +428,11 @@ public:
//Read-only operation for queries //Read-only operation for queries
explicit StaticRTree( explicit StaticRTree(
const boost::filesystem::path & node_file, const boost::filesystem::path & node_file,
const boost::filesystem::path & leaf_file const boost::filesystem::path & leaf_file,
) : m_leaf_node_filename(leaf_file.string()) { const boost::shared_ptr<CoordinateListT> coordinate_list
) : m_leaf_node_filename( leaf_file.string() ) {
//open tree node file and load into RAM. //open tree node file and load into RAM.
m_coordinate_list = coordinate_list;
if ( !boost::filesystem::exists( node_file ) ) { if ( !boost::filesystem::exists( node_file ) ) {
throw OSRMException("ram index file does not exist"); throw OSRMException("ram index file does not exist");
@ -463,9 +467,11 @@ public:
explicit StaticRTree( explicit StaticRTree(
TreeNode * tree_node_ptr, TreeNode * tree_node_ptr,
const uint32_t number_of_nodes, const uint32_t number_of_nodes,
const boost::filesystem::path & leaf_file const boost::filesystem::path & leaf_file,
boost::shared_ptr<CoordinateListT> coordinate_list
) : m_search_tree(tree_node_ptr, number_of_nodes), ) : m_search_tree(tree_node_ptr, number_of_nodes),
m_leaf_node_filename(leaf_file.string()) m_leaf_node_filename(leaf_file.string()),
m_coordinate_list(coordinate_list)
{ {
//open leaf node file and store thread specific pointer //open leaf node file and store thread specific pointer
if ( !boost::filesystem::exists( leaf_file ) ) { if ( !boost::filesystem::exists( leaf_file ) ) {
@ -659,6 +665,8 @@ public:
result_phantom_node.name_id = current_edge.name_id; result_phantom_node.name_id = current_edge.name_id;
result_phantom_node.forward_weight = current_edge.forward_weight; result_phantom_node.forward_weight = current_edge.forward_weight;
result_phantom_node.reverse_weight = current_edge.reverse_weight; result_phantom_node.reverse_weight = current_edge.reverse_weight;
result_phantom_node.forward_offset = current_edge.forward_offset;
result_phantom_node.reverse_offset = current_edge.reverse_offset;
result_phantom_node.location = nearest; result_phantom_node.location = nearest;
current_start_coordinate.lat = current_edge.lat1; current_start_coordinate.lat = current_edge.lat1;
current_start_coordinate.lon = current_edge.lon1; current_start_coordinate.lon = current_edge.lon1;

View File

@ -139,5 +139,9 @@ void DescriptionFactory::BuildRouteSummary(
) { ) {
summary.startName = start_phantom.name_id; summary.startName = start_phantom.name_id;
summary.destName = target_phantom.name_id; summary.destName = target_phantom.name_id;
SimpleLogger().Write(logDEBUG) << "phantom start name: " << start_phantom.name_id << ", path: " << pathDescription.front().name_id;
SimpleLogger().Write(logDEBUG) << "phantom target name: " << target_phantom.name_id << ", path: " << pathDescription.back().name_id;
summary.BuildDurationAndLengthStrings(distance, time); summary.BuildDurationAndLengthStrings(distance, time);
} }

View File

@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef FIXED_POINT_COORDINATE_H_ #ifndef FIXED_POINT_COORDINATE_H_
#define FIXED_POINT_COORDINATE_H_ #define FIXED_POINT_COORDINATE_H_
#include <iostream> #include <iosfwd> //for std::ostream
static const double COORDINATE_PRECISION = 1000000.; static const double COORDINATE_PRECISION = 1000000.;
@ -37,7 +37,7 @@ struct FixedPointCoordinate {
int lon; int lon;
FixedPointCoordinate(); FixedPointCoordinate();
explicit FixedPointCoordinate (int lat, int lon); explicit FixedPointCoordinate( int lat, int lon);
void Reset(); void Reset();
bool isSet() const; bool isSet() const;
bool isValid() const; bool isValid() const;
@ -74,11 +74,13 @@ struct FixedPointCoordinate {
const FixedPointCoordinate & coord, const FixedPointCoordinate & coord,
std::string & output std::string & output
); );
void Output(std::ostream & out) const;
}; };
inline std::ostream & operator<<(std::ostream & out, const FixedPointCoordinate & c){ inline std::ostream& operator<<(std::ostream& o, FixedPointCoordinate const & c){
out << "(" << c.lat << "," << c.lon << ")"; c.Output(o);
return out; return o;
} }
#endif /* FIXED_POINT_COORDINATE_H_ */ #endif /* FIXED_POINT_COORDINATE_H_ */

View File

@ -113,26 +113,26 @@ public:
NodeID middle_node = UINT_MAX; NodeID middle_node = UINT_MAX;
forward_heap1.Insert( forward_heap1.Insert(
phantom_node_pair.startPhantom.forward_node_id, phantom_node_pair.startPhantom.forward_node_id,
-phantom_node_pair.startPhantom.forward_weight, -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(),
phantom_node_pair.startPhantom.forward_node_id phantom_node_pair.startPhantom.forward_node_id
); );
if(phantom_node_pair.startPhantom.isBidirected() ) { if(phantom_node_pair.startPhantom.isBidirected() ) {
forward_heap1.Insert( forward_heap1.Insert(
phantom_node_pair.startPhantom.reverse_node_id, phantom_node_pair.startPhantom.reverse_node_id,
-phantom_node_pair.startPhantom.reverse_weight, -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(),
phantom_node_pair.startPhantom.reverse_node_id phantom_node_pair.startPhantom.reverse_node_id
); );
} }
reverse_heap1.Insert( reverse_heap1.Insert(
phantom_node_pair.targetPhantom.forward_node_id, phantom_node_pair.targetPhantom.forward_node_id,
phantom_node_pair.targetPhantom.forward_weight, phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(),
phantom_node_pair.targetPhantom.forward_node_id phantom_node_pair.targetPhantom.forward_node_id
); );
if(phantom_node_pair.targetPhantom.isBidirected() ) { if(phantom_node_pair.targetPhantom.isBidirected() ) {
reverse_heap1.Insert( reverse_heap1.Insert(
phantom_node_pair.targetPhantom.reverse_node_id, phantom_node_pair.targetPhantom.reverse_node_id,
phantom_node_pair.targetPhantom.reverse_weight, phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(),
phantom_node_pair.targetPhantom.reverse_node_id phantom_node_pair.targetPhantom.reverse_node_id
); );
} }

View File

@ -202,7 +202,8 @@ public:
BOOST_ASSERT_MSG(!ed.shortcut, "original edge flagged as shortcut"); BOOST_ASSERT_MSG(!ed.shortcut, "original edge flagged as shortcut");
unsigned name_index = facade->GetNameIndexFromEdgeID(ed.id); unsigned name_index = facade->GetNameIndexFromEdgeID(ed.id);
TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id); TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id);
//TODO: reorder to always iterate over a result vector
//TODO: refactor to iterate over a result vector in both cases
if ( !facade->EdgeIsCompressed(ed.id) ){ if ( !facade->EdgeIsCompressed(ed.id) ){
SimpleLogger().Write() << "Edge " << ed.id << " is not compressed, smaller_edge_id: " << smaller_edge_id; SimpleLogger().Write() << "Edge " << ed.id << " is not compressed, smaller_edge_id: " << smaller_edge_id;
BOOST_ASSERT( !facade->EdgeIsCompressed(ed.id) ); BOOST_ASSERT( !facade->EdgeIsCompressed(ed.id) );
@ -218,10 +219,17 @@ public:
SimpleLogger().Write() << "Edge " << ed.id << " is compressed"; SimpleLogger().Write() << "Edge " << ed.id << " is compressed";
std::vector<unsigned> id_vector; std::vector<unsigned> id_vector;
facade->GetUncompressedGeometry(ed.id, id_vector); facade->GetUncompressedGeometry(ed.id, id_vector);
BOOST_FOREACH(const unsigned coordinate_id, id_vector){ if( unpacked_path.empty() ) {
//TODO: unpack entire geometry SimpleLogger().Write(logDEBUG) << "first segment(" << facade->GetEscapedNameForNameID(ed.id) << ") is packed";
//TODO: set distance to 0, see if works
}
// if( recursion_stack.empty() ) {
// SimpleLogger().Write(logDEBUG) << "last segment is packed";
// }
BOOST_FOREACH(const unsigned coordinate_id, id_vector){
//TODO: skip if first edge is compressed until start point is reached
unpacked_path.push_back( unpacked_path.push_back(
PathData( PathData(
coordinate_id, coordinate_id,
@ -238,6 +246,8 @@ public:
} }
} }
} }
inline void UnpackEdge( inline void UnpackEdge(

View File

@ -109,12 +109,12 @@ public:
forward_heap1.Insert( forward_heap1.Insert(
phantom_node_pair.startPhantom.forward_node_id, phantom_node_pair.startPhantom.forward_node_id,
distance1-phantom_node_pair.startPhantom.forward_weight, distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(),
phantom_node_pair.startPhantom.forward_node_id phantom_node_pair.startPhantom.forward_node_id
); );
forward_heap2.Insert( forward_heap2.Insert(
phantom_node_pair.startPhantom.forward_node_id, phantom_node_pair.startPhantom.forward_node_id,
distance1-phantom_node_pair.startPhantom.forward_weight, distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(),
phantom_node_pair.startPhantom.forward_node_id phantom_node_pair.startPhantom.forward_node_id
); );
} }
@ -122,12 +122,12 @@ public:
BOOST_ASSERT(phantom_node_pair.startPhantom.reverse_node_id != UINT_MAX); BOOST_ASSERT(phantom_node_pair.startPhantom.reverse_node_id != UINT_MAX);
forward_heap1.Insert( forward_heap1.Insert(
phantom_node_pair.startPhantom.reverse_node_id, phantom_node_pair.startPhantom.reverse_node_id,
distance2-phantom_node_pair.startPhantom.reverse_weight, distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(),
phantom_node_pair.startPhantom.reverse_node_id phantom_node_pair.startPhantom.reverse_node_id
); );
forward_heap2.Insert( forward_heap2.Insert(
phantom_node_pair.startPhantom.reverse_node_id, phantom_node_pair.startPhantom.reverse_node_id,
distance2-phantom_node_pair.startPhantom.reverse_weight, distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(),
phantom_node_pair.startPhantom.reverse_node_id phantom_node_pair.startPhantom.reverse_node_id
); );
} }
@ -135,7 +135,7 @@ public:
//insert new backward nodes into backward heap, unadjusted. //insert new backward nodes into backward heap, unadjusted.
reverse_heap1.Insert( reverse_heap1.Insert(
phantom_node_pair.targetPhantom.forward_node_id, phantom_node_pair.targetPhantom.forward_node_id,
phantom_node_pair.targetPhantom.forward_weight, phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(),
phantom_node_pair.targetPhantom.forward_node_id phantom_node_pair.targetPhantom.forward_node_id
); );
BOOST_ASSERT(phantom_node_pair.targetPhantom.forward_node_id != UINT_MAX); BOOST_ASSERT(phantom_node_pair.targetPhantom.forward_node_id != UINT_MAX);
@ -144,7 +144,7 @@ public:
BOOST_ASSERT(phantom_node_pair.startPhantom.forward_node_id != UINT_MAX); BOOST_ASSERT(phantom_node_pair.startPhantom.forward_node_id != UINT_MAX);
reverse_heap2.Insert( reverse_heap2.Insert(
phantom_node_pair.targetPhantom.reverse_node_id, phantom_node_pair.targetPhantom.reverse_node_id,
phantom_node_pair.targetPhantom.reverse_weight, phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(),
phantom_node_pair.targetPhantom.reverse_node_id phantom_node_pair.targetPhantom.reverse_node_id
); );
} }

View File

@ -45,6 +45,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osrm/Coordinate.h> #include <osrm/Coordinate.h>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
template<class EdgeDataT> template<class EdgeDataT>
class InternalDataFacade : public BaseDataFacade<EdgeDataT> { class InternalDataFacade : public BaseDataFacade<EdgeDataT> {
@ -61,7 +64,7 @@ private:
QueryGraph * m_query_graph; QueryGraph * m_query_graph;
std::string m_timestamp; std::string m_timestamp;
ShM<FixedPointCoordinate, false>::vector m_coordinate_list; boost::shared_ptr<ShM<FixedPointCoordinate, false>::vector> m_coordinate_list;
ShM<NodeID, false>::vector m_via_node_list; ShM<NodeID, false>::vector m_via_node_list;
ShM<unsigned, false>::vector m_name_ID_list; ShM<unsigned, false>::vector m_name_ID_list;
ShM<TurnInstruction, false>::vector m_turn_instruction_list; ShM<TurnInstruction, false>::vector m_turn_instruction_list;
@ -71,7 +74,13 @@ private:
ShM<unsigned, false>::vector m_compressed_geometry_indices; ShM<unsigned, false>::vector m_compressed_geometry_indices;
ShM<unsigned, false>::vector m_compressed_geometries; ShM<unsigned, false>::vector m_compressed_geometries;
StaticRTree<RTreeLeaf, false> * m_static_rtree; boost::shared_ptr<
StaticRTree<
RTreeLeaf,
ShM<FixedPointCoordinate, false>::vector,
false
>
> m_static_rtree;
void LoadTimestamp(const boost::filesystem::path & timestamp_path) { void LoadTimestamp(const boost::filesystem::path & timestamp_path) {
@ -131,15 +140,16 @@ private:
(char *)&number_of_coordinates, (char *)&number_of_coordinates,
sizeof(unsigned) sizeof(unsigned)
); );
m_coordinate_list.resize(number_of_coordinates); m_coordinate_list = boost::make_shared<std::vector<FixedPointCoordinate> >(number_of_coordinates);
for(unsigned i = 0; i < number_of_coordinates; ++i) { for(unsigned i = 0; i < number_of_coordinates; ++i) {
nodes_input_stream.read((char *)&current_node, sizeof(NodeInfo)); nodes_input_stream.read((char *)&current_node, sizeof(NodeInfo));
m_coordinate_list[i] = FixedPointCoordinate( m_coordinate_list->at(i) = FixedPointCoordinate(
current_node.lat, current_node.lat,
current_node.lon current_node.lon
); );
BOOST_ASSERT( ( m_coordinate_list->at(i).lat >> 30) == 0 );
BOOST_ASSERT( ( m_coordinate_list->at(i).lon >> 30) == 0 );
} }
std::vector<FixedPointCoordinate>(m_coordinate_list).swap(m_coordinate_list);
nodes_input_stream.close(); nodes_input_stream.close();
SimpleLogger().Write(logDEBUG) << "Loading edge data"; SimpleLogger().Write(logDEBUG) << "Loading edge data";
@ -221,9 +231,15 @@ private:
const boost::filesystem::path & ram_index_path, const boost::filesystem::path & ram_index_path,
const boost::filesystem::path & file_index_path const boost::filesystem::path & file_index_path
) { ) {
m_static_rtree = new StaticRTree<RTreeLeaf>( BOOST_ASSERT_MSG(
!m_coordinate_list->empty(),
"coordinates must be loaded before r-tree"
);
m_static_rtree = boost::make_shared<StaticRTree<RTreeLeaf> >(
ram_index_path, ram_index_path,
file_index_path file_index_path,
m_coordinate_list
); );
} }
@ -238,6 +254,8 @@ private:
BOOST_ASSERT_MSG(0 != number_of_names, "name file broken"); BOOST_ASSERT_MSG(0 != number_of_names, "name file broken");
BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken"); BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken");
SimpleLogger().Write(logDEBUG) << "no. of names: " << number_of_names;
m_name_begin_indices.resize(number_of_names); m_name_begin_indices.resize(number_of_names);
name_stream.read( name_stream.read(
(char*)&m_name_begin_indices[0], (char*)&m_name_begin_indices[0],
@ -258,7 +276,7 @@ private:
public: public:
~InternalDataFacade() { ~InternalDataFacade() {
delete m_query_graph; delete m_query_graph;
delete m_static_rtree; m_static_rtree.reset();
} }
explicit InternalDataFacade( const ServerPaths & server_paths ) { explicit InternalDataFacade( const ServerPaths & server_paths ) {
@ -379,7 +397,7 @@ public:
const unsigned id const unsigned id
) const { ) const {
// const unsigned coordinate_index = m_via_node_list.at(id); // const unsigned coordinate_index = m_via_node_list.at(id);
return m_coordinate_list.at(id); return m_coordinate_list->at(id);
}; };
bool EdgeIsCompressed( const unsigned id ) const { bool EdgeIsCompressed( const unsigned id ) const {
@ -471,7 +489,7 @@ public:
unsigned coordinate_id = m_compressed_geometries[geometry_index]; unsigned coordinate_id = m_compressed_geometries[geometry_index];
// uncomment to use compressed geometry // uncomment to use compressed geometry
result_nodes.push_back( coordinate_id ); result_nodes.push_back( coordinate_id );
SimpleLogger().Write() << "coordinate " << coordinate_id << " at " << m_coordinate_list.at(coordinate_id); SimpleLogger().Write() << "coordinate " << coordinate_id << " at " << m_coordinate_list->at(coordinate_id);
} }
} }

View File

@ -30,9 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//implements all data storage when shared memory _IS_ used //implements all data storage when shared memory _IS_ used
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include "BaseDataFacade.h" #include "BaseDataFacade.h"
#include "SharedDataType.h" #include "SharedDataType.h"
@ -42,6 +39,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../Util/ProgramOptions.h" #include "../../Util/ProgramOptions.h"
#include "../../Util/SimpleLogger.h" #include "../../Util/SimpleLogger.h"
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <algorithm> #include <algorithm>
template<class EdgeDataT> template<class EdgeDataT>
@ -55,7 +55,7 @@ private:
typedef typename StaticGraph<EdgeData, true>::_StrEdge GraphEdge; typedef typename StaticGraph<EdgeData, true>::_StrEdge GraphEdge;
typedef typename QueryGraph::InputEdge InputEdge; typedef typename QueryGraph::InputEdge InputEdge;
typedef typename super::RTreeLeaf RTreeLeaf; typedef typename super::RTreeLeaf RTreeLeaf;
typedef typename StaticRTree<RTreeLeaf, true>::TreeNode RTreeNode; typedef typename StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true>::TreeNode RTreeNode;
SharedDataLayout * data_layout; SharedDataLayout * data_layout;
char * shared_memory; char * shared_memory;
@ -72,13 +72,21 @@ private:
boost::shared_ptr<SharedMemory> m_large_memory; boost::shared_ptr<SharedMemory> m_large_memory;
std::string m_timestamp; std::string m_timestamp;
ShM<FixedPointCoordinate, true>::vector m_coordinate_list; boost::shared_ptr<
ShM<FixedPointCoordinate, true>::vector
> m_coordinate_list;
ShM<NodeID, true>::vector m_via_node_list; ShM<NodeID, true>::vector m_via_node_list;
ShM<unsigned, true>::vector m_name_ID_list; ShM<unsigned, true>::vector m_name_ID_list;
ShM<TurnInstruction, true>::vector m_turn_instruction_list; ShM<TurnInstruction, true>::vector m_turn_instruction_list;
ShM<char, true>::vector m_names_char_list; ShM<char, true>::vector m_names_char_list;
ShM<unsigned, true>::vector m_name_begin_indices; ShM<unsigned, true>::vector m_name_begin_indices;
boost::shared_ptr<StaticRTree<RTreeLeaf, true> > m_static_rtree; boost::shared_ptr<
StaticRTree<
RTreeLeaf,
ShM<FixedPointCoordinate, true>::vector,
true
>
> m_static_rtree;
// SharedDataFacade() { } // SharedDataFacade() { }
@ -95,13 +103,19 @@ private:
void LoadRTree( void LoadRTree(
const boost::filesystem::path & file_index_path const boost::filesystem::path & file_index_path
) { ) {
BOOST_ASSERT_MSG(
!m_coordinate_list->empty(),
"coordinates must be loaded before r-tree"
);
RTreeNode * tree_ptr = (RTreeNode *)( RTreeNode * tree_ptr = (RTreeNode *)(
shared_memory + data_layout->GetRSearchTreeOffset() shared_memory + data_layout->GetRSearchTreeOffset()
); );
m_static_rtree = boost::make_shared<StaticRTree<RTreeLeaf, true> >( m_static_rtree = boost::make_shared<StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true> >(
tree_ptr, tree_ptr,
data_layout->r_search_tree_size, data_layout->r_search_tree_size,
file_index_path file_index_path,
m_coordinate_list
); );
} }
@ -134,11 +148,10 @@ private:
FixedPointCoordinate * coordinate_list_ptr = (FixedPointCoordinate *)( FixedPointCoordinate * coordinate_list_ptr = (FixedPointCoordinate *)(
shared_memory + data_layout->GetCoordinateListOffset() shared_memory + data_layout->GetCoordinateListOffset()
); );
typename ShM<FixedPointCoordinate, true>::vector coordinate_list( m_coordinate_list = boost::make_shared<ShM<FixedPointCoordinate, true>::vector> (
coordinate_list_ptr, coordinate_list_ptr,
data_layout->coordinate_list_size data_layout->coordinate_list_size
); );
m_coordinate_list.swap( coordinate_list );
TurnInstruction * turn_instruction_list_ptr = (TurnInstruction *)( TurnInstruction * turn_instruction_list_ptr = (TurnInstruction *)(
shared_memory + data_layout->GetTurnInstructionListOffset() shared_memory + data_layout->GetTurnInstructionListOffset()
@ -309,7 +322,7 @@ public:
const unsigned id const unsigned id
) const { ) const {
// const NodeID node = m_via_node_list.at(id); // const NodeID node = m_via_node_list.at(id);
return m_coordinate_list.at(id); return m_coordinate_list->at(id);
}; };
virtual bool EdgeIsCompressed( const unsigned id ) const { virtual bool EdgeIsCompressed( const unsigned id ) const {

View File

@ -43,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/integer.hpp> #include <boost/integer.hpp>
typedef BaseDataFacade<QueryEdge::EdgeData>::RTreeLeaf RTreeLeaf; typedef BaseDataFacade<QueryEdge::EdgeData>::RTreeLeaf RTreeLeaf;
typedef StaticRTree<RTreeLeaf, true>::TreeNode RTreeNode; typedef StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true>::TreeNode RTreeNode;
typedef StaticGraph<QueryEdge::EdgeData> QueryGraph; typedef StaticGraph<QueryEdge::EdgeData> QueryGraph;
struct SharedDataLayout { struct SharedDataLayout {