Space requirements are better now
This commit is contained in:
parent
d32734af0b
commit
8d008f9dcc
@ -51,7 +51,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
|
||||
assert( edge.data.distance > 0 );
|
||||
edge.data.shortcut = false;
|
||||
edge.data.roundabout = i->isRoundabout();
|
||||
edge.data.middleName.nameID = i->name();
|
||||
edge.data.nameID = i->name();
|
||||
edge.data.type = i->type();
|
||||
edge.data.forward = i->isForward();
|
||||
edge.data.backward = i->isBackward();
|
||||
@ -66,7 +66,6 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
|
||||
}
|
||||
}
|
||||
|
||||
INFO("edges.size()=" << edges.size());
|
||||
|
||||
#ifdef _GLIBCXX_PARALLEL
|
||||
__gnu_parallel::sort( edges.begin(), edges.end() );
|
||||
@ -79,14 +78,12 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
|
||||
}
|
||||
|
||||
template<>
|
||||
void EdgeBasedGraphFactory::GetEdgeBasedEdges( std::vector< EdgeBasedEdge >& edges ) {
|
||||
void EdgeBasedGraphFactory::GetEdgeBasedEdges( std::vector< EdgeBasedEdge >& outputEdgeList ) {
|
||||
|
||||
GUARANTEE(0 == edges.size(), "Vector passed to " << __FUNCTION__ << " is not empty");
|
||||
GUARANTEE(0 == outputEdgeList.size(), "Vector passed to EdgeBasedGraphFactory::GetEdgeBasedEdges(..) is not empty");
|
||||
GUARANTEE(0 != edgeBasedEdges.size(), "No edges in edge based graph");
|
||||
|
||||
BOOST_FOREACH ( EdgeBasedEdge currentEdge, edgeBasedEdges) {
|
||||
edges.push_back(currentEdge);
|
||||
}
|
||||
edgeBasedEdges.swap(outputEdgeList);
|
||||
}
|
||||
|
||||
void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes) {
|
||||
@ -97,8 +94,6 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nod
|
||||
void EdgeBasedGraphFactory::Run() {
|
||||
INFO("Generating Edge based representation of input data");
|
||||
|
||||
_edgeBasedGraph.reset(new _EdgeBasedDynamicGraph(_nodeBasedGraph->GetNumberOfEdges() ) );
|
||||
|
||||
std::vector<_Restriction>::iterator restrictionIterator = inputRestrictions.begin();
|
||||
Percent p(_nodeBasedGraph->GetNumberOfNodes());
|
||||
int numberOfResolvedRestrictions(0);
|
||||
@ -141,25 +136,21 @@ void EdgeBasedGraphFactory::Run() {
|
||||
ERR("edgeBasedTarget" << edgeBasedTarget << ">" << _nodeBasedGraph->GetNumberOfEdges());
|
||||
}
|
||||
|
||||
_EdgeBasedEdge newEdge;
|
||||
newEdge.source = edgeBasedSource;
|
||||
newEdge.target = edgeBasedTarget;
|
||||
|
||||
//incorporate turn costs, this is just a simple model and can (read: must) be extended
|
||||
double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
|
||||
|
||||
newEdge.data.distance = (int)( _nodeBasedGraph->GetEdgeData(e1).distance *(1+std::abs((angle-180.)/180.)));
|
||||
newEdge.data.forward = true;
|
||||
newEdge.data.backward = false;
|
||||
newEdge.data.via = v;
|
||||
newEdge.data.nameID = _nodeBasedGraph->GetEdgeData(e2).middleName.nameID;
|
||||
newEdge.data.turnInstruction = AnalyzeTurn(u, v, w);
|
||||
//create Edge for NearestNeighborlookup
|
||||
unsigned distance = (int)( _nodeBasedGraph->GetEdgeData(e1).distance *(1+std::abs((angle-180.)/180.)));
|
||||
unsigned nameID = _nodeBasedGraph->GetEdgeData(e2).nameID;
|
||||
short turnInstruction = AnalyzeTurn(u, v, w);
|
||||
|
||||
//create edge-based graph edge
|
||||
//EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, EdgeWeight w, bool f, bool b, short ty)
|
||||
EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction);
|
||||
edgeBasedEdges.push_back(newEdge);
|
||||
EdgeBasedNode currentNode;
|
||||
|
||||
if(_nodeBasedGraph->GetEdgeData(e1).type != 14) {
|
||||
currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).middleName.nameID;
|
||||
currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID;
|
||||
currentNode.lat1 = inputNodeInfoList[u].lat;
|
||||
currentNode.lon1 = inputNodeInfoList[u].lon;
|
||||
currentNode.lat2 = inputNodeInfoList[v].lat;
|
||||
@ -188,8 +179,8 @@ short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const N
|
||||
_NodeBasedDynamicGraph::EdgeIterator edge1 = _nodeBasedGraph->FindEdge(u, v);
|
||||
_NodeBasedDynamicGraph::EdgeIterator edge2 = _nodeBasedGraph->FindEdge(v, w);
|
||||
|
||||
_NodeBasedDynamicGraph::EdgeData data1 = _nodeBasedGraph->GetEdgeData(edge1);
|
||||
_NodeBasedDynamicGraph::EdgeData data2 = _nodeBasedGraph->GetEdgeData(edge2);
|
||||
_NodeBasedDynamicGraph::EdgeData & data1 = _nodeBasedGraph->GetEdgeData(edge1);
|
||||
_NodeBasedDynamicGraph::EdgeData & data2 = _nodeBasedGraph->GetEdgeData(edge2);
|
||||
|
||||
double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
|
||||
|
||||
@ -214,7 +205,7 @@ short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const N
|
||||
}
|
||||
|
||||
//If street names stay the same and if we are certain that it is not a roundabout, we skip it.
|
||||
if(data1.middleName.nameID == data2.middleName.nameID)
|
||||
if(data1.nameID == data2.nameID)
|
||||
return TurnInstructions.NoTurn;
|
||||
|
||||
return TurnInstructions.GetTurnDirectionOfInstruction(angle);
|
||||
|
@ -37,21 +37,15 @@
|
||||
|
||||
class EdgeBasedGraphFactory {
|
||||
private:
|
||||
union _MiddleName {
|
||||
unsigned middle;
|
||||
unsigned nameID;
|
||||
};
|
||||
|
||||
struct _NodeBasedEdgeData {
|
||||
int distance;
|
||||
unsigned edgeBasedNodeID;
|
||||
unsigned originalEdges;
|
||||
bool shortcut;
|
||||
bool forward;
|
||||
bool backward;
|
||||
bool roundabout;
|
||||
unsigned nameID;
|
||||
bool shortcut:1;
|
||||
bool forward:1;
|
||||
bool backward:1;
|
||||
bool roundabout:1;
|
||||
short type;
|
||||
_MiddleName middleName;
|
||||
} data;
|
||||
|
||||
struct _EdgeBasedEdgeData {
|
||||
@ -83,16 +77,13 @@ public:
|
||||
unsigned weight;
|
||||
};
|
||||
|
||||
typedef DynamicGraph< _EdgeBasedEdgeData> _EdgeBasedDynamicGraph;
|
||||
typedef _EdgeBasedDynamicGraph::InputEdge _EdgeBasedEdge;
|
||||
private:
|
||||
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
|
||||
boost::shared_ptr<_EdgeBasedDynamicGraph> _edgeBasedGraph;
|
||||
|
||||
std::vector<_Restriction> & inputRestrictions;
|
||||
std::vector<NodeInfo> & inputNodeInfoList;
|
||||
|
||||
std::vector<_EdgeBasedEdge> edgeBasedEdges;
|
||||
std::vector<EdgeBasedEdge> edgeBasedEdges;
|
||||
std::vector<EdgeBasedNode> edgeBasedNodes;
|
||||
|
||||
template<class CoordinateT>
|
||||
|
@ -92,24 +92,24 @@ public:
|
||||
_via(myEdge.data.via),
|
||||
_nameID1(myEdge.data.nameID),
|
||||
_weight(myEdge.data.distance),
|
||||
forward(myEdge.data.forward),
|
||||
backward(myEdge.data.backward),
|
||||
_forward(myEdge.data.forward),
|
||||
_backward(myEdge.data.backward),
|
||||
_turnInstruction(myEdge.data.turnInstruction) { }
|
||||
|
||||
/** Default constructor. target and weight are set to 0.*/
|
||||
EdgeBasedEdge() :
|
||||
_source(0), _target(0), _via(0), _nameID1(0), _weight(0), forward(0), backward(0), _turnInstruction(0) { assert(false); } //shall not be used.
|
||||
_source(0), _target(0), _via(0), _nameID1(0), _weight(0), _forward(0), _backward(0), _turnInstruction(0) { assert(false); } //shall not be used.
|
||||
|
||||
explicit EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, unsigned n2, EdgeWeight w, bool f, bool b, short ty) :
|
||||
_source(s), _target(t), _via(v), _nameID1(n1), _weight(w), forward(f), backward(b), _turnInstruction(ty) { assert(ty >= 0); }
|
||||
explicit EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, EdgeWeight w, bool f, bool b, short ty) :
|
||||
_source(s), _target(t), _via(v), _nameID1(n1), _weight(w), _forward(f), _backward(b), _turnInstruction(ty) { assert(ty >= 0); }
|
||||
|
||||
NodeID target() const {return _target; }
|
||||
NodeID source() const {return _source; }
|
||||
EdgeWeight weight() const {return _weight; }
|
||||
NodeID via() const { return _via; }
|
||||
short turnInstruction() const { assert(_turnInstruction >= 0); return _turnInstruction; }
|
||||
bool isBackward() const { return backward; }
|
||||
bool isForward() const { return forward; }
|
||||
bool isBackward() const { return _backward; }
|
||||
bool isForward() const { return _forward; }
|
||||
|
||||
unsigned getNameIDOfTurnTarget() const { return _nameID1; }
|
||||
|
||||
@ -117,10 +117,9 @@ public:
|
||||
NodeID _target;
|
||||
NodeID _via;
|
||||
unsigned _nameID1;
|
||||
// unsigned _nameID2;
|
||||
EdgeWeight _weight;
|
||||
bool forward;
|
||||
bool backward;
|
||||
bool _forward;
|
||||
bool _backward;
|
||||
short _turnInstruction;
|
||||
|
||||
};
|
||||
|
@ -51,7 +51,6 @@ void omp_set_num_threads(int i) {}
|
||||
#include "Contractor/EdgeBasedGraphFactory.h"
|
||||
#include "DataStructures/BinaryHeap.h"
|
||||
#include "DataStructures/ExtractorStructs.h"
|
||||
#include "DataStructures/LevelInformation.h"
|
||||
#include "DataStructures/NNGrid.h"
|
||||
#include "Util/BaseConfiguration.h"
|
||||
#include "Util/InputFileUtil.h"
|
||||
@ -63,12 +62,12 @@ typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
|
||||
typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
|
||||
typedef BaseConfiguration ContractorConfiguration;
|
||||
|
||||
vector<NodeInfo> int2ExtNodeMap;
|
||||
vector<_Restriction> inputRestrictions;
|
||||
std::vector<NodeInfo> internalToExternaleNodeMapping;
|
||||
std::vector<_Restriction> inputRestrictions;
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
if(argc < 3) {
|
||||
cerr << "usage: " << endl << argv[0] << " <osrm-data> <osrm-restrictions>" << endl;
|
||||
cerr << "usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions>" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
INFO("Using restrictions from file: " << argv[2]);
|
||||
@ -91,17 +90,17 @@ int main (int argc, char *argv[]) {
|
||||
}
|
||||
omp_set_num_threads(numberOfThreads);
|
||||
|
||||
cout << "preprocessing data from input file " << argv[1];
|
||||
std::cout << "preprocessing data from input file " << argv[1];
|
||||
#ifdef _GLIBCXX_PARALLEL
|
||||
cout << " using STL parallel mode" << std::endl;
|
||||
std::cout << " using STL parallel mode" << std::endl;
|
||||
#else
|
||||
cout << " using STL serial mode" << std::endl;
|
||||
std::cout << " using STL serial mode" << std::endl;
|
||||
#endif
|
||||
|
||||
ifstream in;
|
||||
in.open (argv[1], ifstream::in | ifstream::binary);
|
||||
if (!in.is_open()) {
|
||||
cerr << "Cannot open " << argv[1] << endl; exit(-1);
|
||||
cerr << "Cannot open " << argv[1] << std::endl; exit(-1);
|
||||
}
|
||||
|
||||
char nodeOut[1024];
|
||||
@ -122,11 +121,14 @@ int main (int argc, char *argv[]) {
|
||||
strcat(fileIndexOut, ".fileIndex");
|
||||
strcat(levelInfoOut, ".levels");
|
||||
|
||||
vector<ImportEdge> edgeList;
|
||||
NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &int2ExtNodeMap, inputRestrictions);
|
||||
std::vector<ImportEdge> edgeList;
|
||||
NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &internalToExternaleNodeMapping, inputRestrictions);
|
||||
in.close();
|
||||
|
||||
EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (n, edgeList, inputRestrictions, int2ExtNodeMap);
|
||||
EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (n, edgeList, inputRestrictions, internalToExternaleNodeMapping);
|
||||
edgeList.clear();
|
||||
std::vector<ImportEdge>().swap(edgeList);
|
||||
|
||||
edgeBasedGraphFactory->Run();
|
||||
n = edgeBasedGraphFactory->GetNumberOfNodes();
|
||||
std::vector<EdgeBasedEdge> edgeBasedEdgeList;
|
||||
@ -134,52 +136,32 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
std::vector<EdgeBasedGraphFactory::EdgeBasedNode> nodeBasedEdgeList;
|
||||
edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList);
|
||||
INFO("size of nodeBasedEdgeList: " << nodeBasedEdgeList.size());
|
||||
DELETE(edgeBasedGraphFactory);
|
||||
|
||||
WritableGrid * writeableGrid = new WritableGrid();
|
||||
cout << "building grid ..." << flush;
|
||||
writeableGrid->ConstructGrid(nodeBasedEdgeList, &int2ExtNodeMap, ramIndexOut, fileIndexOut);
|
||||
delete writeableGrid;
|
||||
std::cout << "building grid ..." << std::flush;
|
||||
writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut);
|
||||
DELETE( writeableGrid );
|
||||
std::cout << "writing node map ..." << std::flush;
|
||||
ofstream mapOutFile(nodeOut, ios::binary);
|
||||
|
||||
for(NodeID i = 0; i < int2ExtNodeMap.size(); i++) {
|
||||
mapOutFile.write((char *)&(int2ExtNodeMap.at(i)), sizeof(NodeInfo));
|
||||
for(NodeID i = 0; i < internalToExternaleNodeMapping.size(); i++) {
|
||||
mapOutFile.write((char *)&(internalToExternaleNodeMapping.at(i)), sizeof(NodeInfo));
|
||||
}
|
||||
mapOutFile.close();
|
||||
std::cout << "ok" << std::endl;
|
||||
|
||||
int2ExtNodeMap.clear();
|
||||
internalToExternaleNodeMapping.clear();
|
||||
std::vector<NodeInfo>().swap(internalToExternaleNodeMapping);
|
||||
inputRestrictions.clear();
|
||||
std::vector<_Restriction>().swap(inputRestrictions);
|
||||
|
||||
cout << "initializing contractor ..." << flush;
|
||||
std::cout << "initializing contractor ..." << std::flush;
|
||||
Contractor* contractor = new Contractor( n, edgeBasedEdgeList );
|
||||
double contractionStartedTimestamp(get_timestamp());
|
||||
contractor->Run();
|
||||
INFO("Contraction took " << get_timestamp() - contractionStartedTimestamp << " sec");
|
||||
|
||||
LevelInformation * levelInfo = contractor->GetLevelInformation();
|
||||
std::cout << "sorting level info" << std::endl;
|
||||
for(unsigned currentLevel = levelInfo->GetNumberOfLevels(); currentLevel>0; currentLevel--) {
|
||||
std::vector<unsigned> & level = levelInfo->GetLevel(currentLevel-1);
|
||||
std::sort(level.begin(), level.end());
|
||||
}
|
||||
|
||||
std::cout << "writing level info" << std::endl;
|
||||
ofstream levelOutFile(levelInfoOut, ios::binary);
|
||||
unsigned numberOfLevels = levelInfo->GetNumberOfLevels();
|
||||
levelOutFile.write((char *)&numberOfLevels, sizeof(unsigned));
|
||||
for(unsigned currentLevel = 0; currentLevel < levelInfo->GetNumberOfLevels(); currentLevel++ ) {
|
||||
std::vector<unsigned> & level = levelInfo->GetLevel(currentLevel);
|
||||
unsigned sizeOfLevel = level.size();
|
||||
levelOutFile.write((char *)&sizeOfLevel, sizeof(unsigned));
|
||||
for(unsigned currentLevelEntry = 0; currentLevelEntry < sizeOfLevel; currentLevelEntry++) {
|
||||
unsigned node = level[currentLevelEntry];
|
||||
levelOutFile.write((char *)&node, sizeof(unsigned));
|
||||
assert(node < n);
|
||||
}
|
||||
}
|
||||
levelOutFile.close();
|
||||
std::vector< ContractionCleanup::Edge > contractedEdges;
|
||||
contractor->GetEdges( contractedEdges );
|
||||
|
||||
@ -189,9 +171,9 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
std::vector< InputEdge> cleanedEdgeList;
|
||||
cleanup->GetData(cleanedEdgeList);
|
||||
delete cleanup;
|
||||
DELETE( cleanup );
|
||||
|
||||
cout << "Serializing edges " << flush;
|
||||
std::cout << "Serializing edges " << std::flush;
|
||||
ofstream edgeOutFile(edgeOut, ios::binary);
|
||||
Percent p(cleanedEdgeList.size());
|
||||
for(std::vector< InputEdge>::iterator it = cleanedEdgeList.begin(); it != cleanedEdgeList.end(); it++) {
|
||||
@ -203,6 +185,6 @@ int main (int argc, char *argv[]) {
|
||||
edgeOutFile.close();
|
||||
cleanedEdgeList.clear();
|
||||
|
||||
cout << "finished" << endl;
|
||||
std::cout << "finished" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user