BREAKING CHANGE, REPROCESS YOUR OSM FILES

Ferry egdes are now ignores by nearest neighbor grid
This commit is contained in:
Dennis Luxen 2010-09-02 15:47:55 +00:00
parent e79e36bea9
commit 1ba915cbed
9 changed files with 48 additions and 101 deletions

View File

@ -25,7 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#else
#include <algorithm>
#endif
#include "DynamicGraph.h"
#include "../DataStructures/DynamicGraph.h"
#include <algorithm>
#include <ctime>
#include <vector>
@ -460,65 +460,8 @@ public:
}
}
NodeID GetNumberOfComponents()
{
NodeID unique = 1;
NodeID largestRun = 0;
NodeID tmp = 1;
_components = new std::vector<NodeID>(_graph->GetNumberOfNodes(), 0);
for(NodeID i = 0; i < _graph->GetNumberOfNodes(); i++)
{
BFSAtNode(i);
}
#ifdef _GLIBCXX_PARALLEL
__gnu_parallel::sort( _components->begin(), _components->end() );
#else
std::sort(_components->begin(), _components->end());
#endif
for(NodeID i = 0; i < _graph->GetNumberOfNodes()-1; i++)
{
if( _components->at(i) != _components->at(i+1)){
if(tmp > largestRun)
{
largestRun = tmp;
}
tmp = 1;
unique++;
}
else
tmp++;
}
if(tmp > largestRun)
largestRun = tmp;
_components->clear();
cout << "Largest component has size: " << largestRun << endl;
return unique;
}
private:
void BFSAtNode(const NodeID n){
std::stack<NodeID> * bfsStack = new std::stack<NodeID>();
if(_components->at(n) != 0)
return;
_components->at(n) = n+1;
bfsStack->push(n);
while(!bfsStack->empty())
{
NodeID node = bfsStack->top();
bfsStack->pop();
for(_DynamicGraph::EdgeIterator e = _graph->BeginEdges(node); e < _graph->EndEdges(node); e++)
{
if(_components->at(_graph->GetTarget(e))!=0)
continue;
_components->at(_graph->GetTarget(e)) = n+1;
bfsStack->push(_graph->GetTarget(e));
}
}
delete bfsStack;
}
double _Timestamp() {
return time(NULL);
}

View File

@ -45,6 +45,7 @@ template<typename EdgeT>
inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) {
NodeID n, source, target, id;
EdgeID m;
bool locatable;
int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap;
ext2IntNodeMap.set_empty_key(UINT_MAX);
@ -62,7 +63,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
for (EdgeID i=0; i<m; i++) {
EdgeWeight weight;
int length;
in >> source >> target >> length >> dir >> weight;
in >> source >> target >> length >> dir >> weight >> locatable;
assert(length > 0);
assert(weight > 0);
@ -91,7 +92,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); }
EdgeT inputEdge(source, target, weight, forward, backward);
EdgeT inputEdge(source, target, weight, forward, backward, locatable);
edgeList.push_back(inputEdge);
}
ext2IntNodeMap.clear();

View File

@ -73,7 +73,7 @@ public:
currentEdge = _graph->FindEdge( phantomNodes->startNode2, phantomNodes->startNode1 );
if(currentEdge != UINT_MAX && _graph->GetEdgeData(currentEdge).forward && phantomNodes->startRatio < phantomNodes->targetRatio)
{ //upperbound auf kantenlänge setzen
cout << "start and target on same edge" << endl;
// cout << "start and target on same edge" << endl;
onSameEdge = true;
_upperbound = 10 * ApproximateDistance(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
} else if (currentEdge != UINT_MAX && !_graph->GetEdgeData(currentEdge).backward) {

View File

@ -44,7 +44,7 @@ public:
/** Default constructor. target and weight are set to 0.*/
Edge() { assert(false); } //shall not be used.
explicit Edge(NodeID s, NodeID t, EdgeWeight w, bool f, bool b) : _source(s), _target(t), _weight(w), forward(f), backward(b) { }
explicit Edge(NodeID s, NodeID t, EdgeWeight w, bool f, bool b, bool l) : _source(s), _target(t), _weight(w), forward(f), backward(b), locatable(l) { }
NodeID target() const {return _target; }
NodeID source() const {return _source;}
@ -54,12 +54,15 @@ public:
bool isForward() const { return forward; }
bool isLocatable() const { return locatable; }
private:
NodeID _source;
NodeID _target;
EdgeWeight _weight:30;
EdgeWeight _weight:29;
bool forward:1;
bool backward:1;
bool locatable:1;
};
typedef Edge ImportEdge;

View File

@ -45,8 +45,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "Contractor/BinaryHeap.h"
#include "Contractor/Contractor.h"
#include "Contractor/ContractionCleanup.h"
#include "Contractor/DynamicGraph.h"
#include "DataStructures/NNGrid.h"
using namespace std;
@ -95,6 +93,8 @@ int main (int argc, char *argv[])
Percent p(edgeList.size());
for(NodeID i = 0; i < edgeList.size(); i++)
{
if(!edgeList[i].isLocatable())
continue;
p.printIncrement();
int slat = int2ExtNodeMap->at(edgeList[i].source()).lat;
int slon = int2ExtNodeMap->at(edgeList[i].source()).lon;

View File

@ -246,20 +246,21 @@ int main (int argc, char *argv[])
double weight = ( distance * 10. ) / (eit->speed / 3.6);
int intWeight = max(1, (int) weight);
int intDist = max(1, (int)distance);
int ferryIndex = settings.indexInAccessListOf("ferry");
switch(eit->direction)
{
case _Way::notSure:
fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << "\n";
fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << " " << (eit->type == ferryIndex ? false :true ) << "\n";
break;
case _Way::oneway:
fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << "\n";
fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << " " << (eit->type == ferryIndex ? false :true ) << "\n";
break;
case _Way::bidirectional:
fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << "\n";
fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << " " << (eit->type == ferryIndex ? false :true ) << "\n";
break;
case _Way::opposite:
fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << "\n";
fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << " " << (eit->type == ferryIndex ? false :true ) << "\n";
break;
default:
assert(false);

View File

@ -47,7 +47,6 @@ typedef http::server<StaticGraph<EdgeData> > server;
/*
* TODO: Description of command line arguments
*/
int main (int argc, char *argv[])
{
double time;
@ -99,38 +98,38 @@ int main (int argc, char *argv[])
cout << "deserializing node map and building nearest neighbor grid ..." << flush;
nodeInfoHelper->initNNGrid(in2);
cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
// time = get_timestamp();
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(nodeInfoHelper->getNumberOfNodes()-1, *edgelist);
delete edgelist;
cout << "checking data sanity ..." << flush;
NodeID numberOfNodes = graph->GetNumberOfNodes();
for ( NodeID node = 0; node < numberOfNodes; ++node ) {
for ( StaticGraph<EdgeData>::EdgeIterator edge = graph->BeginEdges( node ), endEdges = graph->EndEdges( node ); edge != endEdges; ++edge ) {
const NodeID start = node;
const NodeID target = graph->GetTarget( edge );
const EdgeData& data = graph->GetEdgeData( edge );
const NodeID middle = data.middle;
assert(start != target);
if(data.shortcut)
{
if(graph->FindEdge(start, middle) == SPECIAL_EDGEID && graph->FindEdge(middle, start) == SPECIAL_EDGEID)
{
assert(false);
cerr << "hierarchy broken" << endl; exit(-1);
}
if(graph->FindEdge(middle, target) == SPECIAL_EDGEID && graph->FindEdge(target, middle) == SPECIAL_EDGEID)
{
assert(false);
cerr << "hierarchy broken" << endl; exit(-1);
}
}
}
if(graph->GetOutDegree(node) == 0)
{
cerr << "found node with degree 0: " << node << endl;
}
}
cout << "in " << get_timestamp() - time << "s" << endl;
// cout << "checking data sanity ..." << flush;
// NodeID numberOfNodes = graph->GetNumberOfNodes();
// for ( NodeID node = 0; node < numberOfNodes; ++node ) {
// for ( StaticGraph<EdgeData>::EdgeIterator edge = graph->BeginEdges( node ), endEdges = graph->EndEdges( node ); edge != endEdges; ++edge ) {
// const NodeID start = node;
// const NodeID target = graph->GetTarget( edge );
// const EdgeData& data = graph->GetEdgeData( edge );
// const NodeID middle = data.middle;
// assert(start != target);
// if(data.shortcut)
// {
// if(graph->FindEdge(start, middle) == SPECIAL_EDGEID && graph->FindEdge(middle, start) == SPECIAL_EDGEID)
// {
// assert(false);
// cerr << "hierarchy broken" << endl; exit(-1);
// }
// if(graph->FindEdge(middle, target) == SPECIAL_EDGEID && graph->FindEdge(target, middle) == SPECIAL_EDGEID)
// {
// assert(false);
// cerr << "hierarchy broken" << endl; exit(-1);
// }
// }
// }
// if(graph->GetOutDegree(node) == 0)
// {
// cerr << "found node with degree 0: " << node << endl;
// }
// }
// cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "building search graph ..." << flush;

View File

@ -52,7 +52,7 @@ typedef NodeCoords<NodeID> NodeInfo;
#include "Contractor/Contractor.h"
#include "Contractor/ContractionCleanup.h"
typedef ContractionCleanup::Edge::EdgeData EdgeData;
#include "Contractor/DynamicGraph.h"
#include "DataStructures/DynamicGraph.h"
#include "Contractor/SearchEngine.h"
#endif /* TYPEDEFS_H_ */