Make output more verbose while extracting data.
This commit is contained in:
parent
051b710484
commit
7c05cf9980
@ -17,19 +17,22 @@ along with this program; if not, write to the Free Software
|
|||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
*/
|
*/
|
||||||
|
#ifdef STXXL_VERBOSE_LEVEL
|
||||||
|
#undef STXXL_VERBOSE_LEVEL
|
||||||
|
#endif
|
||||||
|
#define STXXL_VERBOSE_LEVEL -1000
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <libxml/xmlreader.h>
|
#include <libxml/xmlreader.h>
|
||||||
|
|
||||||
#include <google/sparse_hash_map>
|
#include <google/sparse_hash_map>
|
||||||
|
|
||||||
#include <stxxl.h>
|
#include <stxxl.h>
|
||||||
|
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
@ -52,216 +55,220 @@ NodeMap * nodeMap = new NodeMap();
|
|||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if(argc <= 1)
|
if(argc <= 1)
|
||||||
{
|
{
|
||||||
cerr << "usage: " << endl << argv[0] << " <file.osm>" << endl;
|
cerr << "usage: " << endl << argv[0] << " <file.osm>" << endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
cout << "reading input file. This may take some time ..." << flush;
|
cout << "reading input file. This may take some time ..." << flush;
|
||||||
double time = get_timestamp();
|
double time = get_timestamp();
|
||||||
settings.speedProfile.names.insert(settings.speedProfile.names.begin(), names, names+13);
|
settings.speedProfile.names.insert(settings.speedProfile.names.begin(), names, names+13);
|
||||||
settings.speedProfile.speed.insert(settings.speedProfile.speed.begin(), speeds, speeds+13);
|
settings.speedProfile.speed.insert(settings.speedProfile.speed.begin(), speeds, speeds+13);
|
||||||
|
|
||||||
xmlTextReaderPtr inputReader = xmlNewTextReaderFilename( argv[1] );
|
xmlTextReaderPtr inputReader = xmlNewTextReaderFilename( argv[1] );
|
||||||
nodeMap->set_empty_key(UINT_MAX);
|
nodeMap->set_empty_key(UINT_MAX);
|
||||||
try {
|
try {
|
||||||
while ( xmlTextReaderRead( inputReader ) == 1 ) {
|
while ( xmlTextReaderRead( inputReader ) == 1 ) {
|
||||||
const int type = xmlTextReaderNodeType( inputReader );
|
const int type = xmlTextReaderNodeType( inputReader );
|
||||||
|
|
||||||
//1 is Element
|
//1 is Element
|
||||||
if ( type != 1 )
|
if ( type != 1 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
xmlChar* currentName = xmlTextReaderName( inputReader );
|
xmlChar* currentName = xmlTextReaderName( inputReader );
|
||||||
if ( currentName == NULL )
|
if ( currentName == NULL )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( xmlStrEqual( currentName, ( const xmlChar* ) "node" ) == 1 ) {
|
if ( xmlStrEqual( currentName, ( const xmlChar* ) "node" ) == 1 ) {
|
||||||
_Node node = _ReadXMLNode( inputReader );
|
_Node node = _ReadXMLNode( inputReader );
|
||||||
allNodes.push_back(node);
|
allNodes.push_back(node);
|
||||||
if ( node.trafficSignal )
|
if ( node.trafficSignal )
|
||||||
SignalNodes.push_back( node.id );
|
SignalNodes.push_back( node.id );
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) {
|
else if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) {
|
||||||
_Way way = _ReadXMLWay( inputReader, settings );
|
_Way way = _ReadXMLWay( inputReader, settings );
|
||||||
|
|
||||||
if ( way.usefull && way.access && way.path.size() ) {
|
if ( way.usefull && way.access && way.path.size() ) {
|
||||||
for ( unsigned i = 0; i < way.path.size(); ++i ) {
|
for ( unsigned i = 0; i < way.path.size(); ++i ) {
|
||||||
usedNodes.push_back(way.path[i]);
|
usedNodes.push_back(way.path[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( way.direction == _Way::opposite )
|
if ( way.direction == _Way::opposite )
|
||||||
std::reverse( way.path.begin(), way.path.end() );
|
std::reverse( way.path.begin(), way.path.end() );
|
||||||
|
|
||||||
{
|
{
|
||||||
vector< NodeID > & path = way.path;
|
vector< NodeID > & path = way.path;
|
||||||
double speed = way.maximumSpeed;
|
double speed = way.maximumSpeed;
|
||||||
assert(way.type > -1 || way.maximumSpeed != -1);
|
assert(way.type > -1 || way.maximumSpeed != -1);
|
||||||
assert(path.size()>0);
|
assert(path.size()>0);
|
||||||
|
|
||||||
for(vector< NodeID >::size_type n = 0; n < path.size()-1; n++)
|
for(vector< NodeID >::size_type n = 0; n < path.size()-1; n++)
|
||||||
{
|
{
|
||||||
_Edge e;
|
_Edge e;
|
||||||
e.start = way.path[n];
|
e.start = way.path[n];
|
||||||
e.target = way.path[n+1];
|
e.target = way.path[n+1];
|
||||||
e.type = way.type;
|
e.type = way.type;
|
||||||
e.direction = way.direction;
|
e.direction = way.direction;
|
||||||
e.speed = way.maximumSpeed;
|
e.speed = way.maximumSpeed;
|
||||||
allEdges.push_back(e);
|
allEdges.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlFree( currentName );
|
xmlFree( currentName );
|
||||||
}
|
}
|
||||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
time = get_timestamp();
|
time = get_timestamp();
|
||||||
unsigned memory_to_use = 1024 * 1024 * 1024;
|
unsigned memory_to_use = 1024 * 1024 * 1024;
|
||||||
|
|
||||||
cout << "Sorting used nodes ..." << flush;
|
cout << "Sorting used nodes ..." << flush;
|
||||||
stxxl::sort(usedNodes.begin(), usedNodes.end(), Cmp(), memory_to_use);
|
stxxl::sort(usedNodes.begin(), usedNodes.end(), Cmp(), memory_to_use);
|
||||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
time = get_timestamp();
|
time = get_timestamp();
|
||||||
cout << "Erasing duplicate entries ..." << flush;
|
cout << "Erasing duplicate entries ..." << flush;
|
||||||
stxxl::vector<NodeID>::iterator NewEnd = unique ( usedNodes.begin(),usedNodes.end() ) ;
|
stxxl::vector<NodeID>::iterator NewEnd = unique ( usedNodes.begin(),usedNodes.end() ) ;
|
||||||
usedNodes.resize ( NewEnd - usedNodes.begin() );
|
usedNodes.resize ( NewEnd - usedNodes.begin() );
|
||||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
time = get_timestamp();
|
time = get_timestamp();
|
||||||
|
|
||||||
cout << "Sorting all nodes ..." << flush;
|
cout << "Sorting all nodes ..." << flush;
|
||||||
stxxl::ksort(allNodes.begin(), allNodes.end(), memory_to_use);
|
stxxl::ksort(allNodes.begin(), allNodes.end(), memory_to_use);
|
||||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
time = get_timestamp();
|
time = get_timestamp();
|
||||||
|
|
||||||
string name(argv[1]);
|
string name(argv[1]);
|
||||||
int pos=name.find(".osm"); // pos=9
|
int pos=name.find(".osm"); // pos=9
|
||||||
if(pos!=string::npos)
|
if(pos!=string::npos)
|
||||||
{
|
{
|
||||||
name.replace(pos, 5, ".osrm");
|
name.replace(pos, 5, ".osrm");
|
||||||
} else {
|
} else {
|
||||||
name.append(".osrm");
|
name.append(".osrm");
|
||||||
}
|
}
|
||||||
|
|
||||||
ofstream fout;
|
ofstream fout;
|
||||||
fout.open(name.c_str());
|
fout.open(name.c_str());
|
||||||
// ifstream inway("_ways", ios::binary);
|
// ifstream inway("_ways", ios::binary);
|
||||||
|
|
||||||
cout << "Writing used nodes ..." << flush;
|
cout << "Confirming used nodes ..." << flush;
|
||||||
NodeID counter = 0;
|
NodeID counter = 0;
|
||||||
NodeID notfound = 0;
|
NodeID notfound = 0;
|
||||||
STXXLNodeVector::iterator nvit = allNodes.begin();
|
STXXLNodeVector::iterator nvit = allNodes.begin();
|
||||||
STXXLNodeIDVector::iterator niit = usedNodes.begin();
|
STXXLNodeIDVector::iterator niit = usedNodes.begin();
|
||||||
while(niit != usedNodes.end() && nvit != allNodes.end())
|
while(niit != usedNodes.end() && nvit != allNodes.end())
|
||||||
{
|
{
|
||||||
if(*niit < nvit->id){
|
if(*niit < nvit->id){
|
||||||
niit++;
|
niit++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(*niit > nvit->id)
|
if(*niit > nvit->id)
|
||||||
{
|
{
|
||||||
nvit++;
|
nvit++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(*niit == nvit->id)
|
if(*niit == nvit->id)
|
||||||
{
|
{
|
||||||
confirmedNodes.push_back(*nvit);
|
confirmedNodes.push_back(*nvit);
|
||||||
nodeMap->insert(std::make_pair(nvit->id, *nvit));
|
nodeMap->insert(std::make_pair(nvit->id, *nvit));
|
||||||
niit++;
|
niit++;
|
||||||
nvit++;
|
nvit++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fout << confirmedNodes.size() << endl;
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
for(STXXLNodeVector::iterator ut = confirmedNodes.begin(); ut != confirmedNodes.end(); ut++)
|
time = get_timestamp();
|
||||||
{
|
|
||||||
fout << ut->id<< " " << ut->lon << " " << ut->lat << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
cout << "Writing used nodes ..." << flush;
|
||||||
time = get_timestamp();
|
fout << confirmedNodes.size() << endl;
|
||||||
|
for(STXXLNodeVector::iterator ut = confirmedNodes.begin(); ut != confirmedNodes.end(); ut++)
|
||||||
|
{
|
||||||
|
fout << ut->id<< " " << ut->lon << " " << ut->lat << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
cout << "confirming used ways ..." << endl;
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
for(STXXLEdgeVector::iterator eit = allEdges.begin(); eit != allEdges.end(); eit++)
|
time = get_timestamp();
|
||||||
{
|
|
||||||
assert(eit->type > -1 || eit->speed != -1);
|
|
||||||
|
|
||||||
NodeMap::iterator startit = nodeMap->find(eit->start);
|
cout << "confirming used ways ..." << endl;
|
||||||
if(startit == nodeMap->end())
|
for(STXXLEdgeVector::iterator eit = allEdges.begin(); eit != allEdges.end(); eit++)
|
||||||
{
|
{
|
||||||
continue;
|
assert(eit->type > -1 || eit->speed != -1);
|
||||||
}
|
|
||||||
NodeMap::iterator targetit = nodeMap->find(eit->target);
|
|
||||||
|
|
||||||
if(targetit == nodeMap->end())
|
NodeMap::iterator startit = nodeMap->find(eit->start);
|
||||||
{
|
if(startit == nodeMap->end())
|
||||||
continue;
|
{
|
||||||
}
|
continue;
|
||||||
confirmedEdges.push_back(*eit);
|
}
|
||||||
}
|
NodeMap::iterator targetit = nodeMap->find(eit->target);
|
||||||
fout << confirmedEdges.size() << "\n";
|
|
||||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
|
||||||
time = get_timestamp();
|
|
||||||
|
|
||||||
cout << "writing confirmed ways ..." << endl;
|
if(targetit == nodeMap->end())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
confirmedEdges.push_back(*eit);
|
||||||
|
}
|
||||||
|
fout << confirmedEdges.size() << "\n";
|
||||||
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
|
time = get_timestamp();
|
||||||
|
|
||||||
for(STXXLEdgeVector::iterator eit = confirmedEdges.begin(); eit != confirmedEdges.end(); eit++)
|
cout << "writing confirmed ways ..." << endl;
|
||||||
{
|
|
||||||
NodeMap::iterator startit = nodeMap->find(eit->start);
|
|
||||||
if(startit == nodeMap->end())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
NodeMap::iterator targetit = nodeMap->find(eit->target);
|
|
||||||
|
|
||||||
if(targetit == nodeMap->end())
|
for(STXXLEdgeVector::iterator eit = confirmedEdges.begin(); eit != confirmedEdges.end(); eit++)
|
||||||
{
|
{
|
||||||
continue;
|
NodeMap::iterator startit = nodeMap->find(eit->start);
|
||||||
}
|
if(startit == nodeMap->end())
|
||||||
double distance = ApproximateDistance(startit->second.lat, startit->second.lon, targetit->second.lat, targetit->second.lon);
|
{
|
||||||
if(eit->speed == -1)
|
continue;
|
||||||
eit->speed = settings.speedProfile.speed[eit->type];
|
}
|
||||||
double weight = ( distance * 10. ) / (eit->speed / 3.6);
|
NodeMap::iterator targetit = nodeMap->find(eit->target);
|
||||||
double intWeight = max(1, (int) weight);
|
|
||||||
switch(eit->direction)
|
|
||||||
{
|
|
||||||
case _Way::notSure:
|
|
||||||
fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 0 << " " << intWeight << "\n";
|
|
||||||
break;
|
|
||||||
case _Way::oneway:
|
|
||||||
fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 1 << " " << intWeight << "\n";
|
|
||||||
break;
|
|
||||||
case _Way::bidirectional:
|
|
||||||
fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 0 << " " << intWeight << "\n";
|
|
||||||
break;
|
|
||||||
case _Way::opposite:
|
|
||||||
fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 1 << " " << intWeight << "\n";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fout.close();
|
|
||||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
|
||||||
time = get_timestamp();
|
|
||||||
} catch ( const std::exception& e ) {
|
|
||||||
cerr << "Caught Execption:" << e.what() << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << endl << "Statistics:" << endl;
|
if(targetit == nodeMap->end())
|
||||||
cout << "-----------" << endl;
|
{
|
||||||
cout << "Usable Nodes: " << confirmedNodes.size() << endl;
|
continue;
|
||||||
cout << "Usable Ways : " << confirmedEdges.size() << endl;
|
}
|
||||||
|
double distance = ApproximateDistance(startit->second.lat, startit->second.lon, targetit->second.lat, targetit->second.lon);
|
||||||
|
if(eit->speed == -1)
|
||||||
|
eit->speed = settings.speedProfile.speed[eit->type];
|
||||||
|
double weight = ( distance * 10. ) / (eit->speed / 3.6);
|
||||||
|
double intWeight = max(1, (int) weight);
|
||||||
|
switch(eit->direction)
|
||||||
|
{
|
||||||
|
case _Way::notSure:
|
||||||
|
fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 0 << " " << intWeight << "\n";
|
||||||
|
break;
|
||||||
|
case _Way::oneway:
|
||||||
|
fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 1 << " " << intWeight << "\n";
|
||||||
|
break;
|
||||||
|
case _Way::bidirectional:
|
||||||
|
fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 0 << " " << intWeight << "\n";
|
||||||
|
break;
|
||||||
|
case _Way::opposite:
|
||||||
|
fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 1 << " " << intWeight << "\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fout.close();
|
||||||
|
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||||
|
time = get_timestamp();
|
||||||
|
} catch ( const std::exception& e ) {
|
||||||
|
cerr << "Caught Execption:" << e.what() << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
SignalNodes.clear();
|
cout << endl << "Statistics:" << endl;
|
||||||
usedNodes.clear();
|
cout << "-----------" << endl;
|
||||||
allNodes.clear();
|
cout << "Usable Nodes: " << confirmedNodes.size() << endl;
|
||||||
confirmedNodes.clear();
|
cout << "Usable Ways : " << confirmedEdges.size() << endl;
|
||||||
allEdges.clear();
|
|
||||||
confirmedEdges.clear();
|
|
||||||
|
|
||||||
xmlFreeTextReader(inputReader);
|
SignalNodes.clear();
|
||||||
return 0;
|
usedNodes.clear();
|
||||||
|
allNodes.clear();
|
||||||
|
confirmedNodes.clear();
|
||||||
|
allEdges.clear();
|
||||||
|
confirmedEdges.clear();
|
||||||
|
|
||||||
|
xmlFreeTextReader(inputReader);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user