Permalink
Browse files

Merging changes for 0.3.3

  • Loading branch information...
2 parents f9ab842 + 2cc2c96 commit 42b68fa83450f780d2a782da1724132dd2d3592f DennisOSRM committed Mar 1, 2013
Showing with 3,840 additions and 2,522 deletions.
  1. +14 −13 .gitignore
  2. +0 −1 Algorithms/CRC32.h
  3. +3 −3 Algorithms/ObjectToBase64.h
  4. +2 −11 Algorithms/StronglyConnectedComponents.h
  5. +7 −5 Contractor/Contractor.h
  6. +66 −48 Contractor/EdgeBasedGraphFactory.cpp
  7. +46 −37 Contractor/EdgeBasedGraphFactory.h
  8. +6 −3 DataStructures/BinaryHeap.h
  9. +38 −27 DataStructures/DeallocatingVector.h
  10. +17 −28 DataStructures/DynamicGraph.h
  11. +48 −41 DataStructures/ImportEdge.h
  12. +5 −5 DataStructures/InputReaderFactory.h
  13. +13 −10 Extractor/LuaUtil.h → DataStructures/MercatorUtil.h
  14. +50 −42 DataStructures/NNGrid.h
  15. +25 −12 DataStructures/NodeInformationHelpDesk.h
  16. +1 −1 DataStructures/QueryEdge.h
  17. +18 −17 DataStructures/SearchEngine.h
  18. +3 −23 DataStructures/{Util.h → TimingUtil.h}
  19. +4 −38 DataStructures/TurnInstructions.h
  20. +3 −3 DataStructures/XORFastHash.h
  21. +2 −6 Descriptors/DescriptionFactory.h
  22. +2 −1 Descriptors/GPXDescriptor.h
  23. +12 −10 Descriptors/JSONDescriptor.h
  24. +116 −0 Extractor/BaseParser.cpp
  25. +20 −11 Extractor/BaseParser.h
  26. +50 −49 Extractor/ExtractionContainers.cpp
  27. +2 −2 Extractor/ExtractionContainers.h
  28. +21 −8 Extractor/ExtractionHelperFunctions.h
  29. +69 −32 Extractor/ExtractorCallbacks.cpp
  30. +3 −3 Extractor/ExtractorCallbacks.h
  31. +44 −41 Extractor/ExtractorStructs.h
  32. +490 −0 Extractor/PBFParser.cpp
  33. +52 −551 Extractor/PBFParser.h
  34. +26 −40 Extractor/ScriptingEnvironment.cpp
  35. +3 −1 Extractor/ScriptingEnvironment.h
  36. +276 −0 Extractor/XMLParser.cpp
  37. +25 −291 Extractor/XMLParser.h
  38. +3 −3 Plugins/LocatePlugin.h
  39. +1 −2 Plugins/NearestPlugin.h
  40. +18 −3 Rakefile
  41. +205 −147 RoutingAlgorithms/AlternativePathRouting.h
  42. +34 −38 RoutingAlgorithms/BasicRoutingInterface.h
  43. +45 −111 RoutingAlgorithms/ShortestPathRouting.h
  44. +1 −1 SConstruct
  45. +1 −1 Server/APIGrammar.h
  46. +17 −14 Server/BasicDatastructures.h
  47. +0 −1 Server/Connection.h
  48. +10 −8 Server/RequestHandler.h
  49. +34 −0 Util/ContainerUtils.h
  50. +7 −6 Util/GraphLoader.h
  51. +52 −0 Util/LuaUtil.h
  52. +25 −3 Util/MachineInfo.h
  53. +31 −49 Util/StringUtil.h
  54. +26 −28 createHierarchy.cpp
  55. +15 −13 extractor.cpp
  56. +92 −75 features/bicycle/access.feature
  57. +64 −0 features/bicycle/access_node.feature
  58. +10 −10 features/bicycle/cycleway.feature
  59. +3 −76 features/bicycle/ferry.feature
  60. +51 −14 features/bicycle/maxspeed.feature
  61. +72 −71 features/bicycle/oneway.feature
  62. +87 −0 features/bicycle/pushing.feature
  63. +109 −71 features/bicycle/restrictions.feature
  64. +7 −0 features/bicycle/train.feature
  65. +33 −0 features/bicycle/turn_penalty.feature
  66. +33 −27 features/bicycle/way.feature
  67. +25 −5 features/car/maxspeed.feature
  68. 0 features/car/permissive.feature
  69. +11 −11 features/car/restrictions.feature
  70. +31 −0 features/car/shuttle_train.feature
  71. +20 −0 features/foot/maxspeed.feature
  72. +56 −0 features/nearest/pick.feature
  73. +105 −0 features/nearest/projection.feature
  74. +17 −7 features/step_definitions/data.rb
  75. +51 −0 features/step_definitions/nearest.rb
  76. +5 −2 features/step_definitions/routability.rb
  77. +7 −24 features/step_definitions/routing.rb
  78. +14 −6 features/support/data.rb
  79. +30 −0 features/support/fuzzy.rb
  80. +18 −10 features/support/hash.rb
  81. +17 −0 features/support/nearest.rb
  82. +3 −0 features/support/shortcuts.rb
  83. +2 −2 features/testbot/distance.feature
  84. +42 −0 features/testbot/duration.feature
  85. +3 −3 features/testbot/{weight.feature → fastest.feature}
  86. +146 −32 features/testbot/ferry.feature
  87. +22 −0 features/testbot/graph.feature
  88. +96 −0 features/testbot/impedance.feature
  89. +52 −0 features/testbot/maxspeed.feature
  90. +18 −0 features/testbot/opposite.feature
  91. +35 −0 features/testbot/routes.feature
  92. +13 −5 features/testbot/turns.feature
  93. +48 −51 profile.lua
  94. +150 −94 profiles/bicycle.lua
  95. +47 −50 profiles/car.lua
  96. +10 −11 profiles/foot.lua
  97. +13 −0 profiles/lib/access.lua
  98. +46 −10 profiles/testbot.lua
  99. +8 −0 profiles/turnbot.lua
  100. +1 −1 test/.stxxl
  101. +10 −12 typedefs.h
View
27 .gitignore
@@ -54,30 +54,31 @@ stxxl.errlog
# compiled protobuffers #
#########################
-DataStructures/pbf-proto/*.pb.h
-DataStructures/pbf-proto/*.pb.cc
+/DataStructures/pbf-proto/*.pb.h
+/DataStructures/pbf-proto/*.pb.cc
# External Libs #
#################
-lib/
-win/lib
+/lib/
+/win/lib
# Visual Studio Temp + build Files #
####################################
-win/*.user
-win/*.ncb
-win/*.suo
-win/Debug/
-win/Release/
-win/bin/
-win/bin-debug/
+/win/*.user
+/win/*.ncb
+/win/*.suo
+/win/Debug/
+/win/Release/
+/win/bin/
+/win/bin-debug/
/osrm-extract
/osrm-routed
/osrm-prepare
/nohup.out
# Sandbox folder #
###################
-sandbox/
+/sandbox/
-test/profile.lua
+/test/profile.lua
+/profile.lua
View
1 Algorithms/CRC32.h
@@ -27,7 +27,6 @@
class CRC32 {
private:
unsigned crc;
- unsigned slowcrc_table[1<<8];
typedef boost::crc_optimal<32, 0x1EDC6F41, 0x0, 0x0, true, true> my_crc_32_type;
typedef unsigned (CRC32::*CRC32CFunctionPtr)(char *str, unsigned len, unsigned crc);
View
6 Algorithms/ObjectToBase64.h
@@ -33,12 +33,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
typedef
boost::archive::iterators::base64_from_binary<
- boost::archive::iterators::transform_width<string::const_iterator, 6, 8>
+ boost::archive::iterators::transform_width<std::string::const_iterator, 6, 8>
> base64_t;
typedef
boost::archive::iterators::transform_width<
- boost::archive::iterators::binary_from_base64<string::const_iterator>, 8, 6
+ boost::archive::iterators::binary_from_base64<std::string::const_iterator>, 8, 6
> binary_t;
template<class ToEncodeT>
@@ -54,7 +54,7 @@ static void EncodeObjectToBase64(const ToEncodeT & object, std::string& encoded)
template<class ToEncodeT>
static void DecodeObjectFromBase64(ToEncodeT & object, const std::string& _encoded) {
try {
- string encoded(_encoded);
+ std::string encoded(_encoded);
//replace "-" with "+" and "_" with "/"
replaceAll(encoded, "-", "+");
replaceAll(encoded, "_", "/");
View
13 Algorithms/StronglyConnectedComponents.h
@@ -52,21 +52,12 @@ class TarjanSCC {
unsigned edgeBasedNodeID;
unsigned nameID:31;
bool shortcut:1;
+ short type;
+ bool isAccessRestricted:1;
bool forward:1;
bool backward:1;
bool roundabout:1;
bool ignoreInGrid:1;
- short type;
- bool isAccessRestricted;
- };
-
- struct _EdgeBasedEdgeData {
- int distance;
- unsigned via;
- unsigned nameID;
- bool forward;
- bool backward;
- TurnInstruction turnInstruction;
};
typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
View
12 Contractor/Contractor.h
@@ -157,11 +157,13 @@ class Contractor {
forwardEdge.data.distance = backwardEdge.data.distance = std::numeric_limits< int >::max();
//remove parallel edges
while ( i < edges.size() && edges[i].source == source && edges[i].target == target ) {
- if ( edges[i].data.forward )
+ if ( edges[i].data.forward) {
forwardEdge.data.distance = std::min( edges[i].data.distance, forwardEdge.data.distance );
- if ( edges[i].data.backward )
+ }
+ if ( edges[i].data.backward) {
backwardEdge.data.distance = std::min( edges[i].data.distance, backwardEdge.data.distance );
- i++;
+ }
+ ++i;
}
//merge edges (s,t) and (t,s) into bidirectional edge
if ( forwardEdge.data.distance == backwardEdge.data.distance ) {
@@ -242,7 +244,7 @@ class Contractor {
nodePriority[x] = _Evaluate( data, &nodeData[x], x );
}
}
- std::cout << "ok" << std::endl << "preprocessing ..." << std::flush;
+ std::cout << "ok" << std::endl << "preprocessing " << numberOfNodes << " nodes ..." << std::flush;
bool flushedContractor = false;
while ( numberOfContractedNodes < numberOfNodes ) {
@@ -274,7 +276,7 @@ class Contractor {
TemporaryStorage & tempStorage = TemporaryStorage::GetInstance();
//Write dummy number of edges to temporary file
// std::ofstream temporaryEdgeStorage(temporaryEdgeStorageFilename.c_str(), std::ios::binary);
- long initialFilePosition = tempStorage.tell(temporaryStorageSlotID);
+ uint64_t initialFilePosition = tempStorage.tell(temporaryStorageSlotID);
unsigned numberOfTemporaryEdges = 0;
tempStorage.writeToSlot(temporaryStorageSlotID, (char*)&numberOfTemporaryEdges, sizeof(unsigned));
View
114 Contractor/EdgeBasedGraphFactory.cpp
@@ -21,8 +21,8 @@
#include "EdgeBasedGraphFactory.h"
template<>
-EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdge> & inputEdges, std::vector<NodeID> & bn, std::vector<NodeID> & tl, std::vector<_Restriction> & irs, std::vector<NodeInfo> & nI, SpeedProfileProperties sp) : inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()), speedProfile(sp) {
- BOOST_FOREACH(_Restriction & restriction, irs) {
+EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdge> & inputEdges, std::vector<NodeID> & bn, std::vector<NodeID> & tl, std::vector<_Restriction> & irs, std::vector<NodeInfo> & nI, SpeedProfileProperties sp) : speedProfile(sp), inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) {
+ BOOST_FOREACH(const _Restriction & restriction, irs) {
std::pair<NodeID, NodeID> restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode);
unsigned index;
RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource);
@@ -44,18 +44,12 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
_restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly));
}
- BOOST_FOREACH(NodeID id, bn) {
- _barrierNodes[id] = true;
- }
- BOOST_FOREACH(NodeID id, tl) {
- _trafficLights[id] = true;
- }
+ _barrierNodes.insert(bn.begin(), bn.end());
+ _trafficLights.insert(tl.begin(), tl.end());
DeallocatingVector< _NodeBasedEdge > edges;
- // edges.reserve( 2 * inputEdges.size() );
+ _NodeBasedEdge edge;
for ( std::vector< NodeBasedEdge >::const_iterator i = inputEdges.begin(); i != inputEdges.end(); ++i ) {
-
- _NodeBasedEdge edge;
if(!i->isForward()) {
edge.source = i->target();
edge.target = i->source();
@@ -67,9 +61,9 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
edge.data.forward = i->isForward();
edge.data.backward = i->isBackward();
}
- if(edge.source == edge.target)
- continue;
-
+ if(edge.source == edge.target) {
+ continue;
+ }
edge.data.distance = (std::max)((int)i->weight(), 1 );
assert( edge.data.distance > 0 );
edge.data.shortcut = false;
@@ -79,6 +73,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
edge.data.type = i->type();
edge.data.isAccessRestricted = i->isAccessRestricted();
edge.data.edgeBasedNodeID = edges.size();
+ edge.data.contraFlow = i->isContraFlow();
edges.push_back( edge );
if( edge.data.backward ) {
std::swap( edge.source, edge.target );
@@ -108,16 +103,12 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes( DeallocatingVector< EdgeBasedNode
nodes.swap(edgeBasedNodes);
}
-void EdgeBasedGraphFactory::GetOriginalEdgeData( std::vector< OriginalEdgeData> & oed) {
- oed.swap(originalEdgeData);
-}
-
NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const {
std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v);
RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource);
if (restrIter != _restrictionMap.end()) {
unsigned index = restrIter->second;
- BOOST_FOREACH(RestrictionSource restrictionTarget, _restrictionBucketVector.at(index)) {
+ BOOST_FOREACH(const RestrictionSource & restrictionTarget, _restrictionBucketVector.at(index)) {
if(restrictionTarget.second) {
return restrictionTarget.first;
}
@@ -159,7 +150,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(
edgeBasedNodes.push_back(currentNode);
}
-void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
+void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State *myLuaState) {
Percent p(_nodeBasedGraph->GetNumberOfNodes());
int numberOfSkippedTurns(0);
int nodeBasedEdgeCounter(0);
@@ -243,12 +234,16 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
std::vector<NodeID>().swap(vectorOfComponentSizes);
std::vector<NodeID>().swap(componentsIndex);
+ std::vector<OriginalEdgeData> original_edge_data_vector;
+ original_edge_data_vector.reserve(10000);
+
//Loop over all turns and generate new set of edges.
//Three nested loop look super-linear, but we are dealing with a linear number of turns only.
for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) {
for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) {
++nodeBasedEdgeCounter;
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);
+ bool isBollardNode = (_barrierNodes.find(v) != _barrierNodes.end());
//EdgeWeight heightPenalty = ComputeHeightPenalty(u, v);
NodeID onlyToNode = CheckForEmanatingIsOnlyTurn(u, v);
for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) {
@@ -258,7 +253,7 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
++numberOfSkippedTurns;
continue;
}
- bool isBollardNode = (_barrierNodes.find(v) != _barrierNodes.end());
+
if(u == w && 1 != _nodeBasedGraph->GetOutDegree(v) ) {
continue;
}
@@ -278,30 +273,30 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
if(_trafficLights.find(v) != _trafficLights.end()) {
distance += speedProfile.trafficSignalPenalty;
}
- TurnInstruction turnInstruction = AnalyzeTurn(u, v, w);
+ unsigned penalty = 0;
+ TurnInstruction turnInstruction = AnalyzeTurn(u, v, w, penalty, myLuaState);
if(turnInstruction == TurnInstructions.UTurn)
distance += speedProfile.uTurnPenalty;
// if(!edgeData1.isAccessRestricted && edgeData2.isAccessRestricted) {
// distance += TurnInstructions.AccessRestrictionPenalty;
// turnInstruction |= TurnInstructions.AccessRestrictionFlag;
// }
-
+ distance += penalty;
+
//distance += heightPenalty;
//distance += ComputeTurnPenalty(u, v, w);
assert(edgeData1.edgeBasedNodeID != edgeData2.edgeBasedNodeID);
- if(originalEdgeData.size() == originalEdgeData.capacity()-3) {
- originalEdgeData.reserve(originalEdgeData.size()*1.2);
- }
OriginalEdgeData oed(v,edgeData2.nameID, turnInstruction);
- EdgeBasedEdge newEdge(edgeData1.edgeBasedNodeID, edgeData2.edgeBasedNodeID, edgeBasedEdges.size(), distance, true, false );
- originalEdgeData.push_back(oed);
- if(originalEdgeData.size() > 100000) {
- originalEdgeDataOutFile.write((char*)&(originalEdgeData[0]), originalEdgeData.size()*sizeof(OriginalEdgeData));
- originalEdgeData.clear();
- }
+ original_edge_data_vector.push_back(oed);
++numberOfOriginalEdges;
- ++nodeBasedEdgeCounter;
+
+ if(original_edge_data_vector.size() > 100000) {
+ originalEdgeDataOutFile.write((char*)&(original_edge_data_vector[0]), original_edge_data_vector.size()*sizeof(OriginalEdgeData));
+ original_edge_data_vector.clear();
+ }
+
+ EdgeBasedEdge newEdge(edgeData1.edgeBasedNodeID, edgeData2.edgeBasedNodeID, edgeBasedEdges.size(), distance, true, false );
edgeBasedEdges.push_back(newEdge);
} else {
++numberOfSkippedTurns;
@@ -311,8 +306,7 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
}
p.printIncrement();
}
- numberOfOriginalEdges += originalEdgeData.size();
- originalEdgeDataOutFile.write((char*)&(originalEdgeData[0]), originalEdgeData.size()*sizeof(OriginalEdgeData));
+ originalEdgeDataOutFile.write((char*)&(original_edge_data_vector[0]), original_edge_data_vector.size()*sizeof(OriginalEdgeData));
originalEdgeDataOutFile.seekp(std::ios::beg);
originalEdgeDataOutFile.write((char*)&numberOfOriginalEdges, sizeof(unsigned));
originalEdgeDataOutFile.close();
@@ -326,12 +320,27 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
// std::vector<EdgeBasedNode>(edgeBasedNodes).swap(edgeBasedNodes);
// INFO("size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity());
INFO("Node-based graph contains " << nodeBasedEdgeCounter << " edges");
+ INFO("Edge-based graph contains " << edgeBasedEdges.size() << " edges");
// INFO("Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << 2*((double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter));
INFO("Edge-based graph skipped " << numberOfSkippedTurns << " turns, defined by " << numberOfTurnRestrictions << " restrictions.");
INFO("Generated " << edgeBasedNodes.size() << " edge based nodes");
}
-TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const {
+TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty, lua_State *myLuaState) const {
+ const double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
+
+ if( speedProfile.has_turn_penalty_function ) {
+ try {
+ //call lua profile to compute turn penalty
+ penalty = luabind::call_function<int>( myLuaState, "turn_function", 180-angle );
+ } catch (const luabind::error &er) {
+ std::cerr << er.what() << std::endl;
+ //TODO handle lua errors
+ }
+ } else {
+ penalty = 0;
+ }
+
if(u == w) {
return TurnInstructions.UTurn;
}
@@ -342,33 +351,42 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID
_NodeBasedDynamicGraph::EdgeData & data1 = _nodeBasedGraph->GetEdgeData(edge1);
_NodeBasedDynamicGraph::EdgeData & data2 = _nodeBasedGraph->GetEdgeData(edge2);
+ if(!data1.contraFlow && data2.contraFlow) {
+ return TurnInstructions.EnterAgainstAllowedDirection;
+ }
+ if(data1.contraFlow && !data2.contraFlow) {
+ return TurnInstructions.LeaveAgainstAllowedDirection;
+ }
+
//roundabouts need to be handled explicitely
if(data1.roundabout && data2.roundabout) {
//Is a turn possible? If yes, we stay on the roundabout!
if( 1 == (_nodeBasedGraph->EndEdges(v) - _nodeBasedGraph->BeginEdges(v)) ) {
//No turn possible.
return TurnInstructions.NoTurn;
- } else {
- return TurnInstructions.StayOnRoundAbout;
}
+ return TurnInstructions.StayOnRoundAbout;
}
//Does turn start or end on roundabout?
if(data1.roundabout || data2.roundabout) {
//We are entering the roundabout
- if( (!data1.roundabout) && data2.roundabout)
+ if( (!data1.roundabout) && data2.roundabout) {
return TurnInstructions.EnterRoundAbout;
+ }
//We are leaving the roundabout
- else if(data1.roundabout && (!data2.roundabout) )
+ if(data1.roundabout && (!data2.roundabout) ) {
return TurnInstructions.LeaveRoundAbout;
+ }
}
//If street names stay the same and if we are certain that it is not a roundabout, we skip it.
- if( (data1.nameID == data2.nameID) && (0 != data1.nameID))
+ if( (data1.nameID == data2.nameID) && (0 != data1.nameID)) {
return TurnInstructions.NoTurn;
- if( (data1.nameID == data2.nameID) && (0 == data1.nameID) && (_nodeBasedGraph->GetOutDegree(v) <= 2) )
+ }
+ if( (data1.nameID == data2.nameID) && (0 == data1.nameID) && (_nodeBasedGraph->GetOutDegree(v) <= 2) ) {
return TurnInstructions.NoTurn;
+ }
- double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
return TurnInstructions.GetTurnDirectionOfInstruction(angle);
}
@@ -379,12 +397,12 @@ unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const {
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
template<class CoordinateT>
double EdgeBasedGraphFactory::GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const {
- const int v1x = A.lon - C.lon;
- const int v1y = A.lat - C.lat;
- const int v2x = B.lon - C.lon;
- const int v2y = B.lat - C.lat;
+ const double v1x = (A.lon - C.lon)/100000.;
+ const double v1y = lat2y(A.lat/100000.) - lat2y(C.lat/100000.);
+ const double v2x = (B.lon - C.lon)/100000.;
+ const double v2y = lat2y(B.lat/100000.) - lat2y(C.lat/100000.);
- double angle = (atan2((double)v2y,v2x) - atan2((double)v1y,v1x) )*180/M_PI;
+ double angle = (atan2(v2y,v2x) - atan2(v1y,v1x) )*180/M_PI;
while(angle < 0)
angle += 360;
return angle;
View
83 Contractor/EdgeBasedGraphFactory.h
@@ -34,48 +34,32 @@
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/make_shared.hpp>
+#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
-
+#include <boost/unordered_map.hpp>
+#include <boost/unordered_set.hpp>
#include "../typedefs.h"
#include "../DataStructures/DeallocatingVector.h"
#include "../DataStructures/DynamicGraph.h"
#include "../Extractor/ExtractorStructs.h"
#include "../DataStructures/HashTable.h"
#include "../DataStructures/ImportEdge.h"
+#include "../DataStructures/MercatorUtil.h"
#include "../DataStructures/QueryEdge.h"
#include "../DataStructures/Percent.h"
#include "../DataStructures/TurnInstructions.h"
#include "../Util/BaseConfiguration.h"
-class EdgeBasedGraphFactory {
-private:
- struct _NodeBasedEdgeData {
- int distance;
- unsigned edgeBasedNodeID;
- unsigned nameID:31;
- bool shortcut:1;
- bool forward:1;
- bool backward:1;
- bool roundabout:1;
- bool ignoreInGrid:1;
- short type;
- bool isAccessRestricted;
- };
+extern "C" {
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+}
+#include <luabind/luabind.hpp>
- struct _EdgeBasedEdgeData {
- int distance;
- unsigned via;
- unsigned nameID;
- bool forward;
- bool backward;
- TurnInstruction turnInstruction;
- };
- typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
- typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge;
- std::vector<NodeInfo> inputNodeInfoList;
- unsigned numberOfTurnRestrictions;
+class EdgeBasedGraphFactory : boost::noncopyable {
public:
struct EdgeBasedNode {
bool operator<(const EdgeBasedNode & other) const {
@@ -95,16 +79,45 @@ class EdgeBasedGraphFactory {
bool ignoreInGrid:1;
};
-
struct SpeedProfileProperties{
- SpeedProfileProperties() : trafficSignalPenalty(0), uTurnPenalty(0) {}
+ SpeedProfileProperties() : trafficSignalPenalty(0), uTurnPenalty(0), has_turn_penalty_function(false) {}
int trafficSignalPenalty;
int uTurnPenalty;
+ bool has_turn_penalty_function;
} speedProfile;
+
private:
+ struct _NodeBasedEdgeData {
+ int distance;
+ unsigned edgeBasedNodeID;
+ unsigned nameID;
+ short type;
+ bool isAccessRestricted:1;
+ bool shortcut:1;
+ bool forward:1;
+ bool backward:1;
+ bool roundabout:1;
+ bool ignoreInGrid:1;
+ bool contraFlow:1;
+ };
+
+ struct _EdgeBasedEdgeData {
+ int distance;
+ unsigned via;
+ unsigned nameID;
+ bool forward;
+ bool backward;
+ TurnInstruction turnInstruction;
+ };
+
+ typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
+ typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge;
+ std::vector<NodeInfo> inputNodeInfoList;
+ unsigned numberOfTurnRestrictions;
+
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
- boost::unordered_map<NodeID, bool> _barrierNodes;
- boost::unordered_map<NodeID, bool> _trafficLights;
+ boost::unordered_set<NodeID> _barrierNodes;
+ boost::unordered_set<NodeID> _trafficLights;
typedef std::pair<NodeID, NodeID> RestrictionSource;
typedef std::pair<NodeID, bool> RestrictionTarget;
@@ -113,10 +126,8 @@ class EdgeBasedGraphFactory {
std::vector<EmanatingRestrictionsVector> _restrictionBucketVector;
RestrictionMap _restrictionMap;
-
DeallocatingVector<EdgeBasedEdge> edgeBasedEdges;
DeallocatingVector<EdgeBasedNode> edgeBasedNodes;
- std::vector<OriginalEdgeData> originalEdgeData;
NodeID CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const;
bool CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const;
@@ -127,18 +138,16 @@ class EdgeBasedGraphFactory {
bool belongsToTinyComponent);
template<class CoordinateT>
double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const;
-// SRTMLookup srtmLookup;
-
public:
template< class InputEdgeT >
explicit EdgeBasedGraphFactory(int nodes, std::vector<InputEdgeT> & inputEdges, std::vector<NodeID> & _bollardNodes, std::vector<NodeID> & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector<NodeInfo> & nI, SpeedProfileProperties speedProfile);
- void Run(const char * originalEdgeDataFilename);
+ void Run(const char * originalEdgeDataFilename, lua_State *myLuaState);
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
void GetEdgeBasedNodes( DeallocatingVector< EdgeBasedNode> & nodes);
void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData);
- TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const;
+ TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty, lua_State *myLuaState) const;
unsigned GetNumberOfNodes() const;
};
View
9 DataStructures/BinaryHeap.h
@@ -75,10 +75,13 @@ template< typename NodeID, typename Key >
class UnorderedMapStorage {
public:
- UnorderedMapStorage( size_t ) { }
+ UnorderedMapStorage( size_t ) {
+ //hash table gets 1000 Buckets
+ nodes.rehash(1000);
+ }
- Key &operator[]( NodeID node ) {
- return nodes[node];
+ Key &operator[]( const NodeID node ) {
+ return nodes[node];
}
void Clear() {
View
65 DataStructures/DeallocatingVector.h
@@ -22,7 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#define DEALLOCATINGVECTOR_H_
#include <cassert>
-#include <cstdlib>
#include <vector>
#if __cplusplus > 199711L
@@ -32,7 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#endif
-template<typename ElementT, size_t bucketSizeC = 10485760/sizeof(ElementT), bool DeallocateC = false>
+template<typename ElementT, std::size_t bucketSizeC = 8388608/sizeof(ElementT), bool DeallocateC = false>
class DeallocatingVectorIterator : public std::iterator<std::random_access_iterator_tag, ElementT> {
protected:
@@ -42,21 +41,21 @@ class DeallocatingVectorIterator : public std::iterator<std::random_access_itera
DeallocatingVectorIteratorState();
public:
explicit DeallocatingVectorIteratorState(const DeallocatingVectorIteratorState &r) : mData(r.mData), mIndex(r.mIndex), mBucketList(r.mBucketList) {}
- //explicit DeallocatingVectorIteratorState(const ElementT * ptr, const size_t idx, const std::vector<ElementT *> & input_list) : mData(ptr), mIndex(idx), mBucketList(input_list) {}
- explicit DeallocatingVectorIteratorState(const size_t idx, std::vector<ElementT *> & input_list) : mData(DEALLOCATION_VECTOR_NULL_PTR), mIndex(idx), mBucketList(input_list) {
+ //explicit DeallocatingVectorIteratorState(const ElementT * ptr, const std::size_t idx, const std::vector<ElementT *> & input_list) : mData(ptr), mIndex(idx), mBucketList(input_list) {}
+ explicit DeallocatingVectorIteratorState(const std::size_t idx, std::vector<ElementT *> & input_list) : mData(DEALLOCATION_VECTOR_NULL_PTR), mIndex(idx), mBucketList(input_list) {
setPointerForIndex();
}
ElementT * mData;
- size_t mIndex;
+ std::size_t mIndex;
std::vector<ElementT *> & mBucketList;
inline void setPointerForIndex() {
if(bucketSizeC*mBucketList.size() <= mIndex) {
mData = DEALLOCATION_VECTOR_NULL_PTR;
return;
}
- size_t _bucket = mIndex/bucketSizeC;
- size_t _index = mIndex%bucketSizeC;
+ std::size_t _bucket = mIndex/bucketSizeC;
+ std::size_t _index = mIndex%bucketSizeC;
mData = &(mBucketList[_bucket][_index]);
if(DeallocateC) {
@@ -104,8 +103,8 @@ class DeallocatingVectorIterator : public std::iterator<std::random_access_itera
template<typename T2>
DeallocatingVectorIterator(const DeallocatingVectorIterator<T2> & r) : mState(r.mState) {}
- DeallocatingVectorIterator(size_t idx, std::vector<ElementT *> & input_list) : mState(idx, input_list) {}
- //DeallocatingVectorIterator(size_t idx, const std::vector<ElementT *> & input_list) : mState(idx, input_list) {}
+ DeallocatingVectorIterator(std::size_t idx, std::vector<ElementT *> & input_list) : mState(idx, input_list) {}
+ //DeallocatingVectorIterator(std::size_t idx, const std::vector<ElementT *> & input_list) : mState(idx, input_list) {}
DeallocatingVectorIterator(const DeallocatingVectorIteratorState & r) : mState(r) {}
template<typename T2>
@@ -185,10 +184,10 @@ class DeallocatingVectorIterator : public std::iterator<std::random_access_itera
}
};
-template<typename ElementT, size_t bucketSizeC = 10485760/sizeof(ElementT) >
+template<typename ElementT, std::size_t bucketSizeC = 8388608/sizeof(ElementT) >
class DeallocatingVector {
private:
- size_t mCurrentSize;
+ std::size_t mCurrentSize;
std::vector<ElementT *> mBucketList;
public:
@@ -227,29 +226,29 @@ class DeallocatingVector {
}
inline void push_back(const ElementT & element) {
- size_t _capacity = capacity();
+ std::size_t _capacity = capacity();
if(mCurrentSize == _capacity) {
mBucketList.push_back(new ElementT[bucketSizeC]);
}
- size_t _index = size()%bucketSizeC;
+ std::size_t _index = size()%bucketSizeC;
mBucketList.back()[_index] = element;
++mCurrentSize;
}
- inline void reserve(const size_t) const {
+ inline void reserve(const std::size_t) const {
//don't do anything
}
- inline void resize(const size_t new_size) {
+ inline void resize(const std::size_t new_size) {
if(new_size > mCurrentSize) {
while(capacity() < new_size) {
mBucketList.push_back(new ElementT[bucketSizeC]);
}
mCurrentSize = new_size;
}
if(new_size < mCurrentSize) {
- size_t number_of_necessary_buckets = 1+(new_size / bucketSizeC);
+ std::size_t number_of_necessary_buckets = 1+(new_size / bucketSizeC);
for(unsigned i = number_of_necessary_buckets; i < mBucketList.size(); ++i) {
delete[] mBucketList[i];
@@ -259,49 +258,61 @@ class DeallocatingVector {
}
}
- inline size_t size() const {
+ inline std::size_t size() const {
return mCurrentSize;
}
- inline size_t capacity() const {
+ inline std::size_t capacity() const {
return mBucketList.size() * bucketSizeC;
}
inline iterator begin() {
- return iterator(static_cast<size_t>(0), mBucketList);
+ return iterator(static_cast<std::size_t>(0), mBucketList);
}
inline iterator end() {
return iterator(size(), mBucketList);
}
inline deallocation_iterator dbegin() {
- return deallocation_iterator(static_cast<size_t>(0), mBucketList);
+ return deallocation_iterator(static_cast<std::size_t>(0), mBucketList);
}
inline deallocation_iterator dend() {
return deallocation_iterator(size(), mBucketList);
}
inline const_iterator begin() const {
- return const_iterator(static_cast<size_t>(0), mBucketList);
+ return const_iterator(static_cast<std::size_t>(0), mBucketList);
}
inline const_iterator end() const {
return const_iterator(size(), mBucketList);
}
- inline ElementT & operator[](const size_t index) {
- size_t _bucket = index / bucketSizeC;
- size_t _index = index % bucketSizeC;
+ inline ElementT & operator[](const std::size_t index) {
+ std::size_t _bucket = index / bucketSizeC;
+ std::size_t _index = index % bucketSizeC;
return (mBucketList[_bucket][_index]);
}
- const inline ElementT & operator[](const size_t index) const {
- size_t _bucket = index / bucketSizeC;
- size_t _index = index % bucketSizeC;
+ const inline ElementT & operator[](const std::size_t index) const {
+ std::size_t _bucket = index / bucketSizeC;
+ std::size_t _index = index % bucketSizeC;
return (mBucketList[_bucket][_index]);
}
+
+ inline ElementT & back() {
+ std::size_t _bucket = mCurrentSize / bucketSizeC;
+ std::size_t _index = mCurrentSize % bucketSizeC;
+ return (mBucketList[_bucket][_index]);
+ }
+
+ const inline ElementT & back() const {
+ std::size_t _bucket = mCurrentSize / bucketSizeC;
+ std::size_t _index = mCurrentSize % bucketSizeC;
+ return (mBucketList[_bucket][_index]);
+ }
};
#endif /* DEALLOCATINGVECTOR_H_ */
View
45 DataStructures/DynamicGraph.h
@@ -59,8 +59,8 @@ class DynamicGraph {
{
m_numNodes = nodes;
m_numEdges = ( EdgeIterator ) graph.size();
- m_nodes.reserve( m_numNodes );
- m_nodes.resize( m_numNodes );
+ m_nodes.reserve( m_numNodes +1);
+ m_nodes.resize( m_numNodes +1);
EdgeIterator edge = 0;
EdgeIterator position = 0;
for ( NodeIterator node = 0; node < m_numNodes; ++node ) {
@@ -72,6 +72,7 @@ class DynamicGraph {
m_nodes[node].edges = edge - lastEdge;
position += m_nodes[node].edges;
}
+ m_nodes.back().firstEdge = position;
m_edges.reserve( position * 1.1 );
m_edges.resize( position );
edge = 0;
@@ -97,40 +98,33 @@ class DynamicGraph {
return m_numEdges;
}
- unsigned GetOutDegree( const NodeIterator &n ) const
- {
+ unsigned GetOutDegree( const NodeIterator n ) const {
return m_nodes[n].edges;
}
- NodeIterator GetTarget( const EdgeIterator &e ) const
- {
+ NodeIterator GetTarget( const EdgeIterator e ) const {
return NodeIterator( m_edges[e].target );
}
- EdgeDataT &GetEdgeData( const EdgeIterator &e )
- {
+ EdgeDataT &GetEdgeData( const EdgeIterator e ) {
return m_edges[e].data;
}
- const EdgeDataT &GetEdgeData( const EdgeIterator &e ) const
- {
+ const EdgeDataT &GetEdgeData( const EdgeIterator e ) const {
return m_edges[e].data;
}
- EdgeIterator BeginEdges( const NodeIterator &n ) const
- {
+ EdgeIterator BeginEdges( const NodeIterator n ) const {
//assert( EndEdges( n ) - EdgeIterator( _nodes[n].firstEdge ) <= 100 );
return EdgeIterator( m_nodes[n].firstEdge );
}
- EdgeIterator EndEdges( const NodeIterator &n ) const
- {
+ EdgeIterator EndEdges( const NodeIterator n ) const {
return EdgeIterator( m_nodes[n].firstEdge + m_nodes[n].edges );
}
//adds an edge. Invalidates edge iterators for the source node
- EdgeIterator InsertEdge( const NodeIterator &from, const NodeIterator &to, const EdgeDataT &data )
- {
+ EdgeIterator InsertEdge( const NodeIterator from, const NodeIterator to, const EdgeDataT &data ) {
Node &node = m_nodes[from];
EdgeIterator newFirstEdge = node.edges + node.firstEdge;
if ( newFirstEdge >= m_edges.size() || !isDummy( newFirstEdge ) ) {
@@ -164,7 +158,7 @@ class DynamicGraph {
}
//removes an edge. Invalidates edge iterators for the source node
- void DeleteEdge( const NodeIterator source, const EdgeIterator &e ) {
+ void DeleteEdge( const NodeIterator source, const EdgeIterator e ) {
Node &node = m_nodes[source];
--m_numEdges;
--node.edges;
@@ -175,8 +169,7 @@ class DynamicGraph {
}
//removes all edges (source,target)
- int DeleteEdgesTo( const NodeIterator source, const NodeIterator target )
- {
+ int DeleteEdgesTo( const NodeIterator source, const NodeIterator target ) {
int deleted = 0;
for ( EdgeIterator i = BeginEdges( source ), iend = EndEdges( source ); i < iend - deleted; ++i ) {
if ( m_edges[i].target == target ) {
@@ -196,8 +189,7 @@ class DynamicGraph {
}
//searches for a specific edge
- EdgeIterator FindEdge( const NodeIterator &from, const NodeIterator &to ) const
- {
+ EdgeIterator FindEdge( const NodeIterator from, const NodeIterator to ) const {
for ( EdgeIterator i = BeginEdges( from ), iend = EndEdges( from ); i != iend; ++i ) {
if ( m_edges[i].target == to ) {
return i;
@@ -208,13 +200,11 @@ class DynamicGraph {
protected:
- bool isDummy( EdgeIterator edge ) const
- {
+ bool isDummy( EdgeIterator edge ) const {
return m_edges[edge].target == (std::numeric_limits< NodeIterator >::max)();
}
- void makeDummy( EdgeIterator edge )
- {
+ void makeDummy( EdgeIterator edge ) {
m_edges[edge].target = (std::numeric_limits< NodeIterator >::max)();
}
@@ -233,9 +223,8 @@ class DynamicGraph {
NodeIterator m_numNodes;
EdgeIterator m_numEdges;
- DeallocatingVector< Node > m_nodes;
- DeallocatingVector< Edge > m_edges;
-
+ std::vector< Node > m_nodes;
+ DeallocatingVector< Edge > m_edges;
};
#endif // DYNAMICGRAPH_H_INCLUDED
View
89 DataStructures/ImportEdge.h
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
-*/
+ */
#ifndef EDGE_H
#define EDGE_H
@@ -40,12 +40,8 @@ class NodeBasedEdge {
return (source() < e.source());
}
- /** Default constructor. target and weight are set to 0.*/
- NodeBasedEdge() :
- _source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _type(0), _roundabout(false), _ignoreInGrid(false), _accessRestricted(false) { assert(false); } //shall not be used.
-
- explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra, bool ig, bool ar) :
- _source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra), _ignoreInGrid(ig), _accessRestricted(ar) { if(ty < 0) {ERR("Type: " << ty);}; }
+ explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra, bool ig, bool ar, bool cf) :
+ _source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra), _ignoreInGrid(ig), _accessRestricted(ar), _contraFlow(cf) { if(ty < 0) {ERR("Type: " << ty);}; }
NodeID target() const {return _target; }
NodeID source() const {return _source; }
@@ -59,6 +55,7 @@ class NodeBasedEdge {
bool isRoundabout() const { return _roundabout; }
bool ignoreInGrid() const { return _ignoreInGrid; }
bool isAccessRestricted() const { return _accessRestricted; }
+ bool isContraFlow() const { return _contraFlow; }
NodeID _source;
NodeID _target;
@@ -70,6 +67,13 @@ class NodeBasedEdge {
bool _roundabout;
bool _ignoreInGrid;
bool _accessRestricted;
+ bool _contraFlow;
+
+private:
+ /** Default constructor. target and weight are set to 0.*/
+ NodeBasedEdge() :
+ _source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _type(0), _roundabout(false), _ignoreInGrid(false), _accessRestricted(false), _contraFlow(false) { assert(false); } //shall not be used.
+
};
class EdgeBasedEdge {
@@ -91,43 +95,46 @@ class EdgeBasedEdge {
template<class EdgeT>
EdgeBasedEdge(const EdgeT & myEdge ) :
- _source(myEdge.source),
- _target(myEdge.target),
- _edgeID(myEdge.data.via),
-// _nameID1(myEdge.data.nameID),
- _weight(myEdge.data.distance),
- _forward(myEdge.data.forward),
- _backward(myEdge.data.backward)//,
-// _turnInstruction(myEdge.data.turnInstruction)
- { }
+ m_source(myEdge.source),
+ m_target(myEdge.target),
+ m_edgeID(myEdge.data.via),
+ m_weight(myEdge.data.distance),
+ m_forward(myEdge.data.forward),
+ m_backward(myEdge.data.backward)
+ { }
/** Default constructor. target and weight are set to 0.*/
EdgeBasedEdge() :
- _source(0), _target(0), _edgeID(0), _weight(0), _forward(false), _backward(false) { }
-
- explicit EdgeBasedEdge(NodeID s, NodeID t, NodeID v, EdgeWeight w, bool f, bool b) :
- _source(s), _target(t), _edgeID(v), _weight(w), _forward(f), _backward(b){}
-
- NodeID target() const {return _target; }
- NodeID source() const {return _source; }
- EdgeWeight weight() const {return _weight; }
- NodeID id() const { return _edgeID; }
- bool isBackward() const { return _backward; }
- bool isForward() const { return _forward; }
-
- NodeID _source;
- NodeID _target;
- NodeID _edgeID;
- EdgeWeight _weight:30;
- bool _forward:1;
- bool _backward:1;
-};
-
-struct MinimalEdgeData {
-public:
- EdgeWeight distance;
- bool forward;
- bool backward;
+ m_source(0),
+ m_target(0),
+ m_edgeID(0),
+ m_weight(0),
+ m_forward(false),
+ m_backward(false)
+ { }
+
+ explicit EdgeBasedEdge(const NodeID s, const NodeID t, const NodeID v, const EdgeWeight w, const bool f, const bool b) :
+ m_source(s),
+ m_target(t),
+ m_edgeID(v),
+ m_weight(w),
+ m_forward(f),
+ m_backward(b)
+ {}
+
+ NodeID target() const {return m_target; }
+ NodeID source() const {return m_source; }
+ EdgeWeight weight() const {return m_weight; }
+ NodeID id() const { return m_edgeID; }
+ bool isBackward() const { return m_backward; }
+ bool isForward() const { return m_forward; }
+private:
+ NodeID m_source;
+ NodeID m_target;
+ NodeID m_edgeID;
+ EdgeWeight m_weight:30;
+ bool m_forward:1;
+ bool m_backward:1;
};
typedef NodeBasedEdge ImportEdge;
View
10 DataStructures/InputReaderFactory.h
@@ -43,21 +43,21 @@ int readFromBz2Stream( void* pointer, char* buffer, int len ) {
return read;
} else if(BZ_STREAM_END == context->error) {
BZ2_bzReadGetUnused(&context->error, context->bz2, &unusedTmpVoid, &context->nUnused);
- if(BZ_OK != context->error) { cerr << "Could not BZ2_bzReadGetUnused" << endl; exit(-1);};
+ if(BZ_OK != context->error) {std::cerr << "Could not BZ2_bzReadGetUnused" <<std::endl; exit(-1);};
unusedTmp = (char*)unusedTmpVoid;
for(int i=0;i<context->nUnused;i++) {
context->unused[i] = unusedTmp[i];
}
BZ2_bzReadClose(&context->error, context->bz2);
- if(BZ_OK != context->error) { cerr << "Could not BZ2_bzReadClose" << endl; exit(-1);};
+ if(BZ_OK != context->error) {std::cerr << "Could not BZ2_bzReadClose" <<std::endl; exit(-1);};
context->error = BZ_STREAM_END; // set to the stream end for next call to this function
if(0 == context->nUnused && feof(context->file)) {
return read;
} else {
context->bz2 = BZ2_bzReadOpen(&context->error, context->file, 0, 0, context->unused, context->nUnused);
- if(NULL == context->bz2){ cerr << "Could not open file" << endl; exit(-1);};
+ if(NULL == context->bz2){std::cerr << "Could not open file" <<std::endl; exit(-1);};
}
- } else { cerr << "Could not read bz2 file" << endl; exit(-1); }
+ } else { std::cerr << "Could not read bz2 file" << std::endl; exit(-1); }
}
return read;
}
@@ -74,7 +74,7 @@ xmlTextReaderPtr inputReaderFactory( const char* name )
{
std::string inputName(name);
- if(inputName.find(".osm.bz2")!=string::npos)
+ if(inputName.find(".osm.bz2")!=std::string::npos)
{
BZ2Context* context = new BZ2Context();
context->error = false;
View
23 Extractor/LuaUtil.h → DataStructures/MercatorUtil.h
@@ -16,20 +16,23 @@ You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
- */
+*/
+#ifndef MERCATORUTIL_H_
+#define MERCATORUTIL_H_
+#include <cmath>
-#ifndef LUAUTIL_H_
-#define LUAUTIL_H_
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
-#include <iostream>
-
-template<typename T>
-void LUA_print(T number) {
- std::cout << "[LUA] " << number << std::endl;
+inline double y2lat(double a) {
+ return 180/M_PI * (2 * atan(exp(a*M_PI/180)) - M_PI/2);
}
+inline double lat2y(double a) {
+ return 180/M_PI * log(tan(M_PI/4+a*(M_PI/180)/2));
+}
-
-#endif /* LUAUTIL_H_ */
+#endif /* MERCATORUTIL_H_ */
View
92 DataStructures/NNGrid.h
@@ -21,10 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef NNGRID_H_
#define NNGRID_H_
-#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
+#include <cstring>
+
+#include <algorithm>
#include <fstream>
#include <limits>
#include <vector>
@@ -42,12 +44,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <boost/unordered_map.hpp>
#include "DeallocatingVector.h"
-//#include "ExtractorStructs.h"
#include "GridEdge.h"
#include "Percent.h"
#include "PhantomNodes.h"
-#include "Util.h"
+#include "MercatorUtil.h"
#include "StaticGraph.h"
+#include "TimingUtil.h"
#include "../Algorithms/Bresenham.h"
namespace NNGrid{
@@ -58,15 +60,15 @@ template<bool WriteAccess = false>
class NNGrid {
public:
NNGrid() /*: cellCache(500), fileCache(500)*/ {
- ramIndexTable.resize((1024*1024), ULONG_MAX);
+ ramIndexTable.resize((1024*1024), std::numeric_limits<uint64_t>::max());
}
NNGrid(const char* rif, const char* _i) {
if(WriteAccess) {
ERR("Not available in Write mode");
}
iif = std::string(_i);
- ramIndexTable.resize((1024*1024), ULONG_MAX);
+ ramIndexTable.resize((1024*1024), std::numeric_limits<uint64_t>::max());
ramInFile.open(rif, std::ios::in | std::ios::binary);
if(!ramInFile) { ERR(rif << " not found"); }
@@ -87,13 +89,13 @@ class NNGrid {
void OpenIndexFiles() {
assert(ramInFile.is_open());
- ramInFile.read(static_cast<char*>(static_cast<void*>(&ramIndexTable[0]) ), sizeof(unsigned long)*1024*1024);
+ ramInFile.read(static_cast<char*>(static_cast<void*>(&ramIndexTable[0]) ), sizeof(uint64_t)*1024*1024);
ramInFile.close();
}
#ifndef ROUTED
template<typename EdgeT>
- inline void ConstructGrid(DeallocatingVector<EdgeT> & edgeList, char * ramIndexOut, char * fileIndexOut) {
+ inline void ConstructGrid(DeallocatingVector<EdgeT> & edgeList, const char * ramIndexOut, const char * fileIndexOut) {
//TODO: Implement this using STXXL-Streams
Percent p(edgeList.size());
BOOST_FOREACH(EdgeT & edge, edgeList) {
@@ -106,6 +108,9 @@ class NNGrid {
int tlon = edge.lon2;
AddEdge( _GridEdge( edge.id, edge.nameID, edge.weight, _Coordinate(slat, slon), _Coordinate(tlat, tlon), edge.belongsToTinyComponent ) );
}
+ if( 0 == entries.size() ) {
+ ERR("No viable edges for nearest neighbor index. Aborting");
+ }
double timestamp = get_timestamp();
//create index file on disk, old one is over written
indexOutFile.open(fileIndexOut, std::ios::out | std::ios::binary | std::ios::trunc);
@@ -114,8 +119,8 @@ class NNGrid {
INFO("finished sorting after " << (get_timestamp() - timestamp) << "s");
std::vector<GridEntry> entriesInFileWithRAMSameIndex;
unsigned indexInRamTable = entries.begin()->ramIndex;
- unsigned long lastPositionInIndexFile = 0;
- cout << "writing data ..." << flush;
+ uint64_t lastPositionInIndexFile = 0;
+ std::cout << "writing data ..." << std::flush;
p.reinit(entries.size());
boost::unordered_map< unsigned, unsigned > cellMap(1024);
BOOST_FOREACH(GridEntry & gridEntry, entries) {
@@ -143,9 +148,9 @@ class NNGrid {
indexOutFile.close();
//Serialize RAM Index
- ofstream ramFile(ramIndexOut, std::ios::out | std::ios::binary | std::ios::trunc);
+ std::ofstream ramFile(ramIndexOut, std::ios::out | std::ios::binary | std::ios::trunc);
//write 4 MB of index Table in RAM
- ramFile.write((char *)&ramIndexTable[0], sizeof(unsigned long)*1024*1024 );
+ ramFile.write((char *)&ramIndexTable[0], sizeof(uint64_t)*1024*1024 );
//close ram index file
ramFile.close();
}
@@ -174,10 +179,10 @@ class NNGrid {
// INFO("looked up " << candidates.size());
_GridEdge smallestEdge;
_Coordinate tmp, edgeStartCoord, edgeEndCoord;
- double dist = numeric_limits<double>::max();
+ double dist = std::numeric_limits<double>::max();
double r, tmpDist;
- BOOST_FOREACH(_GridEdge candidate, candidates) {
+ BOOST_FOREACH(const _GridEdge & candidate, candidates) {
if(candidate.belongsToTinyComponent && ignoreTinyComponents)
continue;
r = 0.;
@@ -216,7 +221,7 @@ class NNGrid {
// }
// INFO("startCoord: " << smallestEdge.startCoord << "; targetCoord: " << smallestEdge.targetCoord << "; newEndpoint: " << resultNode.location);
- double ratio = (foundNode ? std::min(1., ApproximateDistance(smallestEdge.startCoord, resultNode.location)/ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord)) : 0);
+ const double ratio = (foundNode ? std::min(1., ApproximateDistance(smallestEdge.startCoord, resultNode.location)/ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord)) : 0);
resultNode.location.lat = round(100000.*(y2lat(static_cast<double>(resultNode.location.lat)/100000.)));
// INFO("Length of vector: " << ApproximateDistance(smallestEdge.startCoord, resultNode.location)/ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord));
//Hack to fix rounding errors and wandering via nodes.
@@ -227,12 +232,13 @@ class NNGrid {
resultNode.weight1 *= ratio;
if(INT_MAX != resultNode.weight2) {
- resultNode.weight2 -= resultNode.weight1;
+ resultNode.weight2 *= (1.-ratio);
}
resultNode.ratio = ratio;
-// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2 << ", ratio: " << ratio);
// INFO("start: " << edgeStartCoord << ", end: " << edgeEndCoord);
-// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--");
+// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no"));
+// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2 << ", ratio: " << ratio);
+ // INFO("distance to input coordinate: " << ApproximateDistance(location, resultNode.location) << "\n--");
// double time2 = get_timestamp();
// INFO("NN-Lookup in " << 1000*(time2-time1) << "ms");
return foundNode;
@@ -264,7 +270,7 @@ class NNGrid {
}
_Coordinate tmp;
double dist = (std::numeric_limits<double>::max)();
- BOOST_FOREACH(_GridEdge candidate, candidates) {
+ BOOST_FOREACH(const _GridEdge & candidate, candidates) {
double r = 0.;
double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r);
if(tmpDist < dist) {
@@ -310,17 +316,18 @@ class NNGrid {
cellMap.insert(insertionVector.begin(), insertionVector.end());
}
- inline bool DoubleEpsilonCompare(const double d1, const double d2) {
+ inline bool DoubleEpsilonCompare(const double d1, const double d2) const {
return (std::fabs(d1 - d2) < FLT_EPSILON);
}
- inline unsigned FillCell(std::vector<GridEntry>& entriesWithSameRAMIndex, const unsigned long fileOffset, boost::unordered_map< unsigned, unsigned > & cellMap ) {
+#ifndef ROUTED
+ inline unsigned FillCell(std::vector<GridEntry>& entriesWithSameRAMIndex, const uint64_t fileOffset, boost::unordered_map< unsigned, unsigned > & cellMap ) {
std::vector<char> tmpBuffer(32*32*4096,0);
- unsigned long indexIntoTmpBuffer = 0;
+ uint64_t indexIntoTmpBuffer = 0;
unsigned numberOfWrittenBytes = 0;
assert(indexOutFile.is_open());
- std::vector<unsigned long> cellIndex(32*32,ULONG_MAX);
+ std::vector<uint64_t> cellIndex(32*32,std::numeric_limits<uint64_t>::max());
for(unsigned i = 0; i < entriesWithSameRAMIndex.size() -1; ++i) {
assert(entriesWithSameRAMIndex[i].ramIndex== entriesWithSameRAMIndex[i+1].ramIndex);
@@ -356,8 +363,8 @@ class NNGrid {
indexIntoTmpBuffer += FlushEntriesWithSameFileIndexToBuffer(entriesWithSameFileIndex, tmpBuffer, indexIntoTmpBuffer);
assert(entriesWithSameFileIndex.size() == 0);
- indexOutFile.write(static_cast<char*>(static_cast<void*>(&cellIndex[0])),32*32*sizeof(unsigned long));
- numberOfWrittenBytes += 32*32*sizeof(unsigned long);
+ indexOutFile.write(static_cast<char*>(static_cast<void*>(&cellIndex[0])),32*32*sizeof(uint64_t));
+ numberOfWrittenBytes += 32*32*sizeof(uint64_t);
//write contents of tmpbuffer to disk
indexOutFile.write(&tmpBuffer[0], indexIntoTmpBuffer*sizeof(char));
@@ -366,7 +373,7 @@ class NNGrid {
return numberOfWrittenBytes;
}
- inline unsigned FlushEntriesWithSameFileIndexToBuffer( std::vector<GridEntry> &vectorWithSameFileIndex, std::vector<char> & tmpBuffer, const unsigned long index) const {
+ inline unsigned FlushEntriesWithSameFileIndexToBuffer( std::vector<GridEntry> &vectorWithSameFileIndex, std::vector<char> & tmpBuffer, const uint64_t index) const {
sort( vectorWithSameFileIndex.begin(), vectorWithSameFileIndex.end() );
vectorWithSameFileIndex.erase(unique(vectorWithSameFileIndex.begin(), vectorWithSameFileIndex.end()), vectorWithSameFileIndex.end());
const unsigned lengthOfBucket = vectorWithSameFileIndex.size();
@@ -391,11 +398,12 @@ class NNGrid {
vectorWithSameFileIndex.clear();
return counter;
}
+#endif
inline void GetContentsOfFileBucketEnumerated(const unsigned fileIndex, std::vector<_GridEdge>& result) const {
unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex);
- unsigned long startIndexInFile = ramIndexTable[ramIndex];
- if(startIndexInFile == ULONG_MAX) {
+ uint64_t startIndexInFile = ramIndexTable[ramIndex];
+ if(startIndexInFile == std::numeric_limits<uint64_t>::max()) {
return;
}
unsigned enumeratedIndex = GetCellIndexFromRAMAndFileIndex(ramIndex, fileIndex);
@@ -409,14 +417,14 @@ class NNGrid {
}
//only read the single necessary cell index
- localStream->seekg(startIndexInFile+(enumeratedIndex*sizeof(unsigned long)));
- unsigned long fetchedIndex = 0;
- localStream->read(static_cast<char*>( static_cast<void*>(&fetchedIndex)), sizeof(unsigned long));
+ localStream->seekg(startIndexInFile+(enumeratedIndex*sizeof(uint64_t)));
+ uint64_t fetchedIndex = 0;
+ localStream->read(static_cast<char*>( static_cast<void*>(&fetchedIndex)), sizeof(uint64_t));
- if(fetchedIndex == ULONG_MAX) {
+ if(fetchedIndex == std::numeric_limits<uint64_t>::max()) {
return;
}
- const unsigned long position = fetchedIndex + 32*32*sizeof(unsigned long) ;
+ const uint64_t position = fetchedIndex + 32*32*sizeof(uint64_t) ;
unsigned lengthOfBucket;
unsigned currentSizeOfResult = result.size();
@@ -428,12 +436,12 @@ class NNGrid {
inline void GetContentsOfFileBucket(const unsigned fileIndex, std::vector<_GridEdge>& result, boost::unordered_map< unsigned, unsigned> & cellMap) {
unsigned ramIndex = GetRAMIndexFromFileIndex(fileIndex);
- unsigned long startIndexInFile = ramIndexTable[ramIndex];
- if(startIndexInFile == ULONG_MAX) {
+ uint64_t startIndexInFile = ramIndexTable[ramIndex];
+ if(startIndexInFile == std::numeric_limits<uint64_t>::max()) {
return;
}
- unsigned long cellIndex[32*32];
+ uint64_t cellIndex[32*32];
cellMap.clear();
BuildCellIndexToFileIndexMap(ramIndex, cellMap);
@@ -446,12 +454,12 @@ class NNGrid {
}
localStream->seekg(startIndexInFile);
- localStream->read(static_cast<char*>(static_cast<void*>( cellIndex)), 32*32*sizeof(unsigned long));
+ localStream->read(static_cast<char*>(static_cast<void*>( cellIndex)), 32*32*sizeof(uint64_t));
assert(cellMap.find(fileIndex) != cellMap.end());
- if(cellIndex[cellMap[fileIndex]] == ULONG_MAX) {
+ if(cellIndex[cellMap[fileIndex]] == std::numeric_limits<uint64_t>::max()) {
return;
}
- const unsigned long position = cellIndex[cellMap[fileIndex]] + 32*32*sizeof(unsigned long) ;
+ const uint64_t position = cellIndex[cellMap[fileIndex]] + 32*32*sizeof(uint64_t) ;
unsigned lengthOfBucket;
unsigned currentSizeOfResult = result.size();
@@ -543,7 +551,7 @@ class NNGrid {
}
}
- inline unsigned GetFileIndexForLatLon(const int lt, const int ln) {
+ inline unsigned GetFileIndexForLatLon(const int lt, const int ln) const {
double lat = lt/100000.;
double lon = ln/100000.;
@@ -574,14 +582,14 @@ class NNGrid {
return ramIndex;
}
- const static unsigned long END_OF_BUCKET_DELIMITER = UINT_MAX;
+ const static uint64_t END_OF_BUCKET_DELIMITER = boost::integer_traits<uint64_t>::const_max;
- std::ofstream indexOutFile;
std::ifstream ramInFile;
#ifndef ROUTED
+ std::ofstream indexOutFile;
stxxl::vector<GridEntry> entries;
#endif
- std::vector<unsigned long> ramIndexTable; //8 MB for first level index in RAM
+ std::vector<uint64_t> ramIndexTable; //8 MB for first level index in RAM
std::string iif;
// LRUCache<int,std::vector<unsigned> > cellCache;
// LRUCache<int,std::vector<_Edge> > fileCache;
View
37 DataStructures/NodeInformationHelpDesk.h
@@ -25,13 +25,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <iostream>
#include <vector>
+#include <boost/noncopyable.hpp>
+
#include "../typedefs.h"
#include "../DataStructures/QueryEdge.h"
#include "NNGrid.h"
#include "PhantomNodes.h"
#include "NodeCoords.h"
-class NodeInformationHelpDesk{
+class NodeInformationHelpDesk : boost::noncopyable{
public:
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) {
readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
@@ -59,34 +61,43 @@ class NodeInformationHelpDesk{
DEBUG("Loading edge data");
unsigned numberOfOrigEdges(0);
edgesInStream.read((char*)&numberOfOrigEdges, sizeof(unsigned));
- origEdgeData.resize(numberOfOrigEdges);
- edgesInStream.read((char*)&(origEdgeData[0]), numberOfOrigEdges*sizeof(OriginalEdgeData));
+ origEdgeData_viaNode.resize(numberOfOrigEdges);
+ origEdgeData_nameID.resize(numberOfOrigEdges);
+ origEdgeData_turnInstruction.resize(numberOfOrigEdges);
+
+ OriginalEdgeData deserialized_originalEdgeData;
+ for(unsigned i = 0; i < numberOfOrigEdges; ++i) {
+ edgesInStream.read((char*)&(deserialized_originalEdgeData), sizeof(OriginalEdgeData));
+ origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode;
+ origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID;
+ origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction;
+ }
edgesInStream.close();
DEBUG("Loaded " << numberOfOrigEdges << " orig edges");
DEBUG("Opening NN indices");
readOnlyGrid->OpenIndexFiles();
}
- void initNNGrid() {
- readOnlyGrid->OpenIndexFiles();
- }
+// void initNNGrid() {
+// readOnlyGrid->OpenIndexFiles();
+// }
inline int getLatitudeOfNode(const unsigned id) const {
- const NodeID node = origEdgeData.at(id).viaNode;
+ const NodeID node = origEdgeData_viaNode.at(id);
return coordinateVector.at(node).lat;
}
inline int getLongitudeOfNode(const unsigned id) const {
- const NodeID node = origEdgeData.at(id).viaNode;
+ const NodeID node = origEdgeData_viaNode.at(id);
return coordinateVector.at(node).lon;
}
inline unsigned getNameIndexFromEdgeID(const unsigned id) const {
- return origEdgeData.at(id).nameID;
+ return origEdgeData_nameID.at(id);
}
inline TurnInstruction getTurnInstructionFromEdgeID(const unsigned id) const {
- return origEdgeData.at(id).turnInstruction;
+ return origEdgeData_turnInstruction.at(id);
}
inline NodeID getNumberOfNodes() const { return numberOfNodes; }
@@ -96,7 +107,7 @@ class NodeInformationHelpDesk{
return readOnlyGrid->FindNearestCoordinateOnEdgeInNodeBasedGraph(coord, result);
}
- inline bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode, const unsigned zoomLevel) const {
+ inline bool FindPhantomNodeForCoordinate( const _Coordinate & location, PhantomNode & resultNode, const unsigned zoomLevel) {
return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode, zoomLevel);
}
@@ -114,7 +125,9 @@ class NodeInformationHelpDesk{
private:
std::vector<_Coordinate> coordinateVector;
- std::vector<OriginalEdgeData> origEdgeData;
+ std::vector<NodeID> origEdgeData_viaNode;
+ std::vector<unsigned> origEdgeData_nameID;
+ std::vector<TurnInstruction> origEdgeData_turnInstruction;
ReadOnlyGrid * readOnlyGrid;
const unsigned numberOfNodes;
View
2 DataStructures/QueryEdge.h
@@ -41,8 +41,8 @@ struct QueryEdge {
NodeID target;
struct EdgeData {
NodeID id:31;
- int distance:30;
bool shortcut:1;
+ int distance:30;
bool forward:1;
bool backward:1;
} data;
View
35 DataStructures/SearchEngine.h
@@ -42,60 +42,61 @@ struct _HeapData {
_HeapData( NodeID p ) : parent(p) { }
};
-typedef boost::thread_specific_ptr<BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> > > SearchEngineHeapPtr;
+typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> > QueryHeapType;
+typedef boost::thread_specific_ptr<QueryHeapType> SearchEngineHeapPtr;
template<class EdgeData, class GraphT>
struct SearchEngineData {
- typedef SearchEngineHeapPtr HeapPtr;
typedef GraphT Graph;
- SearchEngineData(GraphT * g, NodeInformationHelpDesk * nh, std::vector<string> & n) :graph(g), nodeHelpDesk(nh), names(n) {}
+ typedef QueryHeapType QueryHeap;
+ SearchEngineData(GraphT * g, NodeInformationHelpDesk * nh, std::vector<std::string> & n) :graph(g), nodeHelpDesk(nh), names(n) {}
const GraphT * graph;
NodeInformationHelpDesk * nodeHelpDesk;
- std::vector<string> & names;
- static HeapPtr forwardHeap;
- static HeapPtr backwardHeap;
- static HeapPtr forwardHeap2;
- static HeapPtr backwardHeap2;
- static HeapPtr forwardHeap3;
- static HeapPtr backwardHeap3;
+ std::vector<std::string> & names;
+ static SearchEngineHeapPtr forwardHeap;
+ static SearchEngineHeapPtr backwardHeap;
+ static SearchEngineHeapPtr forwardHeap2;
+ static SearchEngineHeapPtr backwardHeap2;
+ static SearchEngineHeapPtr forwardHeap3;
+ static SearchEngineHeapPtr backwardHeap3;
inline void InitializeOrClearFirstThreadLocalStorage() {
if(!forwardHeap.get()) {
- forwardHeap.reset(new BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> >(nodeHelpDesk->getNumberOfNodes()));
+ forwardHeap.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
}
else
forwardHeap->Clear();
if(!backwardHeap.get()) {
- backwardHeap.reset(new BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> >(nodeHelpDesk->getNumberOfNodes()));
+ backwardHeap.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
}
else
backwardHeap->Clear();
}
inline void InitializeOrClearSecondThreadLocalStorage() {
if(!forwardHeap2.get()) {
- forwardHeap2.reset(new BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> >(nodeHelpDesk->getNumberOfNodes()));
+ forwardHeap2.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
}
else
forwardHeap2->Clear();
if(!backwardHeap2.get()) {
- backwardHeap2.reset(new BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> >(nodeHelpDesk->getNumberOfNodes()));
+ backwardHeap2.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
}
else
backwardHeap2->Clear();
}
inline void InitializeOrClearThirdThreadLocalStorage() {
if(!forwardHeap3.get()) {
- forwardHeap3.reset(new BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> >(nodeHelpDesk->getNumberOfNodes()));
+ forwardHeap3.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
}
else
forwardHeap3->Clear();
if(!backwardHeap3.get()) {
- backwardHeap3.reset(new BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> >(nodeHelpDesk->getNumberOfNodes()));
+ backwardHeap3.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
}
else
backwardHeap3->Clear();
@@ -113,7 +114,7 @@ class SearchEngine {
ShortestPathRouting<SearchEngineDataT> shortestPath;
AlternativeRouting<SearchEngineDataT> alternativePaths;
- SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector<string> & n) :
+ SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector<std::string> & n) :
_queryData(g, nh, n),
shortestPath(_queryData),
alternativePaths(_queryData)
View
26 DataStructures/Util.h → DataStructures/TimingUtil.h
@@ -18,16 +18,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
-#ifndef TIMEUTIL_H_
-#define TIMEUTIL_H_
+#ifndef TIMINGUTIL_H_
+#define TIMINGUTIL_H_
#include <climits>
-#include <cmath>
#include <cstdlib>
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
#ifdef _WIN32
#include <sys/timeb.h>
@@ -43,28 +39,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <sys/time.h>
#endif
-#ifdef _WIN32
- #include <boost/functional/hash.hpp>
-#else
- #include <tr1/functional_hash.h>
-#endif
-#include <boost/thread.hpp>
-
/** Returns a timestamp (now) in seconds (incl. a fractional part). */
static inline double get_timestamp() {
struct timeval tp;
gettimeofday(&tp, NULL);
return double(tp.tv_sec) + tp.tv_usec / 1000000.;
}
-static inline double y2lat(double a) { return 180/M_PI * (2 * atan(exp(a*M_PI/180)) - M_PI/2); }
-static inline double lat2y(double a) { return 180/M_PI * log(tan(M_PI/4+a*(M_PI/180)/2)); }
-
-static inline unsigned boost_thread_id_hash(boost::thread::id const& id) {
- std::stringstream ostr;
- ostr << id;
- std::tr1::hash<std::string> h;
- return h(ostr.str());
-}
-#endif /* TIMEUTIL_H_ */
+#endif /* TIMINGUTIL_H_ */
View
42 DataStructures/TurnInstructions.h
@@ -21,12 +21,12 @@
#ifndef TURNINSTRUCTIONS_H_
#define TURNINSTRUCTIONS_H_
-#include <string>
+#include <boost/noncopyable.hpp>
typedef unsigned char TurnInstruction;
//This is a hack until c++0x is available enough to use scoped enums
-struct TurnInstructionsClass {
+struct TurnInstructionsClass : boost::noncopyable {
const static TurnInstruction NoTurn = 0; //Give no instruction at all
const static TurnInstruction GoStraight = 1; //Tell user to go straight!
@@ -44,48 +44,14 @@ struct TurnInstructionsClass {
const static TurnInstruction StayOnRoundAbout = 13;
const static TurnInstruction StartAtEndOfStreet = 14;
const static TurnInstruction ReachedYourDestination = 15;
+ const static TurnInstruction EnterAgainstAllowedDirection = 16;
+ const static TurnInstruction LeaveAgainstAllowedDirection = 17;
const static TurnInstruction AccessRestrictionFlag = 128;
const static TurnInstruction InverseAccessRestrictionFlag = 0x7f; // ~128 does not work without a warning.
const static int AccessRestrictionPenalty = 1 << 15; //unrelated to the bit set in the restriction flag
-// std::string TurnStrings[16];
-// std::string Ordinals[12];
-
- //This is a hack until c++0x is available enough to use initializer lists.
-// TurnInstructionsClass(){
-// TurnStrings [0] = "";
-// TurnStrings [1] = "Continue";
-// TurnStrings [2] = "Turn slight right";
-// TurnStrings [3] = "Turn right";
-// TurnStrings [4] = "Turn sharp right";
-// TurnStrings [5] = "U-Turn";
-// TurnStrings [6] = "Turn sharp left";
-// TurnStrings [7] = "Turn left";
-// TurnStrings [8] = "Turn slight left";
-// TurnStrings [9] = "Reach via point";
-// TurnStrings[10] = "Head";
-// TurnStrings[11] = "Enter roundabout";
-// TurnStrings[12] = "Leave roundabout";
-// TurnStrings[13] = "Stay on roundabout";
-// TurnStrings[14] = "Start";
-// TurnStrings[15] = "You have reached your destination";
-//
-// Ordinals[0] = "zeroth";
-// Ordinals[1] = "first";
-// Ordinals[2] = "second";
-// Ordinals[3] = "third";
-// Ordinals[4] = "fourth";
-// Ordinals[5] = "fifth";
-// Ordinals[6] = "sixth";
-// Ordinals[7] = "seventh";
-// Ordinals[8] = "eighth";
-// Ordinals[9] = "nineth";
-// Ordinals[10] = "tenth";
-// Ordinals[11] = "one of the too many";
-// };
-
static inline TurnInstruction GetTurnDirectionOfInstruction( const double angle ) {
if(angle >= 23 && angle < 67) {
return TurnSharpRight;
View
6 DataStructures/XORFastHash.h
@@ -49,7 +49,7 @@ class XORFastHash { //65k entries
table1.resize(2 << 16);
table2.resize(2 << 16);
for(unsigned i = 0; i < (2 << 16); ++i) {
- table1[i] = i; table2[i];
+ table1[i] = i; table2[i] = i;
}
std::random_shuffle(table1.begin(), table1.end());
std::random_shuffle(table2.begin(), table2.end());
@@ -75,8 +75,8 @@ class XORMiniHash { //256 entries
table3.resize(1 << 8);
table4.resize(1 << 8);
for(unsigned i = 0; i < (1 << 8); ++i) {
- table1[i] = i; table2[i];
- table3[i] = i; table4[i];
+ table1[i] = i; table2[i] = i;
+ table3[i] = i; table4[i] = i;
}
std::random_shuffle(table1.begin(), table1.end());
std::random_shuffle(table2.begin(), table2.end());
View
8 Descriptors/DescriptionFactory.h
@@ -53,13 +53,9 @@ class DescriptionFactory {
_RouteSummary() : lengthString("0"), durationString("0"), startName(0), destName(0) {}
void BuildDurationAndLengthStrings(const double distance, const unsigned time) {
//compute distance/duration for route summary
- std::ostringstream s;
- s << round(distance);
- lengthString = s.str();
+ intToString(round(distance), lengthString);
int travelTime = time/10 + 1;
- s.str("");
- s << travelTime;
- durationString = s.str();
+ intToString(travelTime, durationString);
}
} summary;
View
3 Descriptors/GPXDescriptor.h
@@ -39,14 +39,15 @@ class GPXDescriptor : public BaseDescriptor<SearchEngineT>{
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
"\">";
+ reply.content += "<metadata><copyright author=\"Project OSRM\"><license>Data (c) OpenStreetMap contributors (ODbL)</license></copyright></metadata>";
reply.content += "<rte>";
if(rawRoute.lengthOfShortestPath != INT_MAX && rawRoute.computedShortestPath.size()) {
convertInternalLatLonToString(phantomNodes.startPhantom.location.lat, tmp);
reply.content += "<rtept lat=\"" + tmp + "\" ";
convertInternalLatLonToString(phantomNodes.startPhantom.location.lon, tmp);
reply.content += "lon=\"" + tmp + "\"></rtept>";
- BOOST_FOREACH(_PathData pathData, rawRoute.computedShortestPath) {
+ BOOST_FOREACH(const _PathData & pathData, rawRoute.computedShortestPath) {
sEngine.GetCoordinatesForNodeID(pathData.node, current);
convertInternalLatLonToString(current.lat, tmp);
View
22 Descriptors/JSONDescriptor.h
@@ -246,7 +246,7 @@ class JSONDescriptor : public BaseDescriptor<SearchEngineT>{
reply.content += "}";
}
- void GetRouteNames(std::vector<Segment> & shortestSegments, std::vector<Segment> & alternativeSegments, SearchEngineT &sEngine, RouteNames & routeNames) {
+ void GetRouteNames(std::vector<Segment> & shortestSegments, std::vector<Segment> & alternativeSegments, const SearchEngineT &sEngine, RouteNames & routeNames) {
/*** extract names for both alternatives ***/
Segment shortestSegment1, shortestSegment2;
@@ -262,23 +262,25 @@ class JSONDescriptor : public BaseDescriptor<SearchEngineT>{
std::vector<Segment> shortestDifference(shortestSegments.size());
std::vector<Segment> alternativeDifference(alternativeSegments.size());
std::set_difference(shortestSegments.begin(), shortestSegments.end(), alternativeSegments.begin(), alternativeSegments.end(), shortestDifference.begin(), boost::bind(&Segment::nameID, _1) < boost::bind(&Segment::nameID, _2) );
- if(0 < shortestDifference.size() ) {
- unsigned i = 0;
- while( i < shortestDifference.size() && shortestDifference[i].nameID == shortestSegments[0].nameID) {
+ int size_of_difference = shortestDifference.size();
+ if(0 < size_of_difference ) {
+ int i = 0;
+ while( i < size_of_difference && shortestDifference[i].nameID == shortestSegments[0].nameID) {
++i;
}
- if(i < shortestDifference.size()) {
+ if(i < size_of_difference ) {
shortestSegment2 = shortestDifference[i];
}
}
std::set_difference(alternativeSegments.begin(), alternativeSegments.end(), shortestSegments.begin(), shortestSegments.end(), alternativeDifference.begin(), boost::bind(&Segment::nameID, _1) < boost::bind(&Segment::nameID, _2) );
- if(0 < alternativeDifference.size() ) {
- unsigned i = 0;
- while( i < alternativeDifference.size() && alternativeDifference[i].nameID == alternativeSegments[0].nameID) {
+ size_of_difference = alternativeDifference.size();
+ if(0 < size_of_difference ) {
+ int i = 0;
+ while( i < size_of_difference && alternativeDifference[i].nameID == alternativeSegments[0].nameID) {
++i;
}
- if(i < alternativeDifference.size()) {
+ if(i < size_of_difference ) {
alternativeSegment2 = alternativeDifference[i];
}
}