2010-07-15 10:45:43 -04:00
|
|
|
/*
|
|
|
|
open source routing machine
|
|
|
|
Copyright (C) Dennis Luxen, others 2010
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU AFFERO General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2011-11-24 13:37:49 -05:00
|
|
|
|
2010-08-06 15:33:54 -04:00
|
|
|
#ifdef STXXL_VERBOSE_LEVEL
|
|
|
|
#undef STXXL_VERBOSE_LEVEL
|
|
|
|
#endif
|
|
|
|
#define STXXL_VERBOSE_LEVEL -1000
|
2010-07-15 10:45:43 -04:00
|
|
|
|
2011-03-22 13:38:18 -04:00
|
|
|
#include <algorithm>
|
2010-07-15 10:45:43 -04:00
|
|
|
#include <cassert>
|
|
|
|
#include <climits>
|
|
|
|
#include <cstdio>
|
2010-08-06 15:33:54 -04:00
|
|
|
#include <cstdlib>
|
2011-10-04 09:42:24 -04:00
|
|
|
#include <exception>
|
2010-07-15 10:45:43 -04:00
|
|
|
#include <iostream>
|
2011-01-09 16:42:27 -05:00
|
|
|
#include <fstream>
|
2010-07-15 10:45:43 -04:00
|
|
|
#include <sstream>
|
2010-08-06 15:33:54 -04:00
|
|
|
#include <string>
|
2010-07-15 10:45:43 -04:00
|
|
|
#include <vector>
|
|
|
|
|
2012-08-29 12:33:18 -04:00
|
|
|
extern "C" {
|
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
|
|
|
#include <lualib.h>
|
|
|
|
}
|
|
|
|
#include <luabind/luabind.hpp>
|
|
|
|
|
2010-08-06 15:33:54 -04:00
|
|
|
#include <libxml/xmlreader.h>
|
2011-10-04 09:42:24 -04:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
#include <boost/property_tree/ini_parser.hpp>
|
2011-03-24 11:06:49 -04:00
|
|
|
#include <unistd.h>
|
2010-07-15 10:45:43 -04:00
|
|
|
|
|
|
|
#include "typedefs.h"
|
2010-08-10 13:06:37 -04:00
|
|
|
#include "DataStructures/InputReaderFactory.h"
|
2012-08-29 12:33:18 -04:00
|
|
|
#include "Extractor/ExtractorCallbacks.h"
|
2012-08-27 11:40:59 -04:00
|
|
|
#include "Extractor/ExtractorStructs.h"
|
2012-08-29 12:33:18 -04:00
|
|
|
#include "Extractor/LuaUtil.h"
|
2012-08-27 11:40:59 -04:00
|
|
|
#include "Extractor/PBFParser.h"
|
|
|
|
#include "Extractor/XMLParser.h"
|
2011-03-24 11:06:49 -04:00
|
|
|
#include "Util/BaseConfiguration.h"
|
|
|
|
#include "Util/InputFileUtil.h"
|
2011-05-07 03:36:17 -04:00
|
|
|
#include "Util/MachineInfo.h"
|
2012-03-22 05:25:04 -04:00
|
|
|
#include "Util/StringUtil.h"
|
2011-03-24 11:06:49 -04:00
|
|
|
|
2012-08-29 12:33:18 -04:00
|
|
|
#include "Extractor/ExtractionContainers.h"
|
|
|
|
|
2011-10-04 09:42:24 -04:00
|
|
|
using namespace std;
|
|
|
|
|
2011-03-24 11:06:49 -04:00
|
|
|
typedef BaseConfiguration ExtractorConfiguration;
|
2010-07-15 10:45:43 -04:00
|
|
|
|
2011-07-06 08:33:41 -04:00
|
|
|
unsigned globalRestrictionCounter = 0;
|
2011-01-14 11:54:42 -05:00
|
|
|
ExtractorCallbacks * extractCallBacks;
|
2012-08-29 12:33:18 -04:00
|
|
|
//
|
2011-01-14 11:54:42 -05:00
|
|
|
bool nodeFunction(_Node n);
|
2011-07-06 08:33:41 -04:00
|
|
|
bool restrictionFunction(_RawRestrictionContainer r);
|
2011-01-14 11:54:42 -05:00
|
|
|
bool wayFunction(_Way w);
|
2011-01-09 16:42:27 -05:00
|
|
|
|
|
|
|
int main (int argc, char *argv[]) {
|
2012-01-31 08:48:46 -05:00
|
|
|
|
2012-02-08 04:35:59 -05:00
|
|
|
if(argc < 2) {
|
|
|
|
ERR("usage: \n" << argv[0] << " <file.osm/.osm.bz2/.osm.pbf>");
|
|
|
|
}
|
2011-12-01 09:12:30 -05:00
|
|
|
|
2012-01-31 08:48:46 -05:00
|
|
|
//Check if another instance of stxxl is already running or if there is a general problem
|
|
|
|
try {
|
|
|
|
stxxl::vector<unsigned> testForRunningInstance;
|
|
|
|
} catch(std::exception & e) {
|
|
|
|
ERR("Could not instantiate STXXL layer." << std::endl << e.what());
|
|
|
|
}
|
2012-02-13 09:21:51 -05:00
|
|
|
double startupTime = get_timestamp();
|
2012-01-31 08:48:46 -05:00
|
|
|
|
2011-12-01 09:12:30 -05:00
|
|
|
INFO("extracting data from input file " << argv[1]);
|
|
|
|
bool isPBF(false);
|
|
|
|
std::string outputFileName(argv[1]);
|
|
|
|
std::string restrictionsFileName(argv[1]);
|
|
|
|
std::string::size_type pos = outputFileName.find(".osm.bz2");
|
|
|
|
if(pos==std::string::npos) {
|
2011-01-12 13:08:10 -05:00
|
|
|
pos = outputFileName.find(".osm.pbf");
|
2011-12-01 09:12:30 -05:00
|
|
|
if(pos!=std::string::npos) {
|
2011-01-12 13:08:10 -05:00
|
|
|
isPBF = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(pos!=string::npos) {
|
|
|
|
outputFileName.replace(pos, 8, ".osrm");
|
2011-07-06 08:33:41 -04:00
|
|
|
restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
|
2011-01-12 13:08:10 -05:00
|
|
|
} else {
|
|
|
|
pos=outputFileName.find(".osm");
|
|
|
|
if(pos!=string::npos) {
|
|
|
|
outputFileName.replace(pos, 5, ".osrm");
|
2011-07-06 08:33:41 -04:00
|
|
|
restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
|
2011-01-12 13:08:10 -05:00
|
|
|
} else {
|
|
|
|
outputFileName.append(".osrm");
|
2011-07-06 08:33:41 -04:00
|
|
|
restrictionsFileName.append(".osrm.restrictions");
|
2011-01-12 13:08:10 -05:00
|
|
|
}
|
|
|
|
}
|
2011-12-01 09:12:30 -05:00
|
|
|
std::string adressFileName(outputFileName);
|
2011-10-04 09:42:24 -04:00
|
|
|
Settings settings;
|
|
|
|
|
|
|
|
boost::property_tree::ptree pt;
|
|
|
|
try {
|
2012-01-02 07:09:20 -05:00
|
|
|
INFO("Loading speed profiles");
|
|
|
|
boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt);
|
2011-10-04 09:42:24 -04:00
|
|
|
INFO("Found the following speed profiles: ");
|
|
|
|
int profileCounter(0);
|
|
|
|
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("")) {
|
2011-12-01 09:12:30 -05:00
|
|
|
std::string name = v.first;
|
2011-10-04 09:42:24 -04:00
|
|
|
cout << " [" << profileCounter << "]" << name << endl;
|
|
|
|
++profileCounter;
|
|
|
|
}
|
2011-12-01 09:12:30 -05:00
|
|
|
std::string usedSpeedProfile(pt.get_child("").begin()->first);
|
2011-10-04 09:42:24 -04:00
|
|
|
INFO("Using profile \"" << usedSpeedProfile << "\"")
|
|
|
|
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child(usedSpeedProfile)) {
|
2011-12-01 09:12:30 -05:00
|
|
|
std::string name = v.first;
|
|
|
|
std::string value = v.second.get<std::string>("");
|
2011-10-04 09:42:24 -04:00
|
|
|
DEBUG("inserting " << name << "=" << value);
|
2011-10-05 13:08:27 -04:00
|
|
|
if(name == "obeyOneways") {
|
|
|
|
if(value == "no")
|
|
|
|
settings.obeyOneways = false;
|
2012-03-22 05:25:04 -04:00
|
|
|
} else if(name == "obeyBollards") {
|
|
|
|
if(value == "no") {
|
|
|
|
settings.obeyBollards = false;
|
|
|
|
}
|
|
|
|
} else if(name == "useRestrictions") {
|
|
|
|
if(value == "no")
|
|
|
|
settings.useRestrictions = false;
|
2012-08-18 17:31:32 -04:00
|
|
|
} else if(name == "accessTags") {
|
|
|
|
std::vector<std::string> tokens;
|
|
|
|
stringSplit(value, ',', tokens);
|
|
|
|
settings.accessTags = tokens;
|
2012-03-22 05:25:04 -04:00
|
|
|
} else if(name == "excludeFromGrid") {
|
|
|
|
settings.excludeFromGrid = value;
|
|
|
|
} else if(name == "defaultSpeed") {
|
|
|
|
settings.defaultSpeed = atoi(value.c_str());
|
|
|
|
settings.speedProfile["default"] = std::make_pair(settings.defaultSpeed, settings.speedProfile.size() );
|
|
|
|
} else if( name == "takeMinimumOfSpeeds") {
|
|
|
|
settings.takeMinimumOfSpeeds = ("yes" == value);
|
2012-05-14 07:25:16 -04:00
|
|
|
} else if( name == "ignoreAreas") {
|
|
|
|
settings.ignoreAreas = ("yes" == value);
|
2012-03-22 05:25:04 -04:00
|
|
|
} else if( name == "accessRestrictedService") {
|
|
|
|
//split value at commas
|
|
|
|
std::vector<std::string> tokens;
|
|
|
|
stringSplit(value, ',', tokens);
|
|
|
|
//put each value into map
|
|
|
|
BOOST_FOREACH(std::string & s, tokens) {
|
|
|
|
INFO("adding " << s << " to accessRestrictedService");
|
|
|
|
settings.accessRestrictedService.insert(std::make_pair(s, true));
|
|
|
|
}
|
|
|
|
} else if( name == "accessRestrictionKeys") {
|
|
|
|
//split value at commas
|
|
|
|
std::vector<std::string> tokens;
|
|
|
|
stringSplit(value, ',', tokens);
|
|
|
|
//put each value into map
|
|
|
|
BOOST_FOREACH(std::string & s, tokens) {
|
|
|
|
INFO("adding " << s << " to accessRestrictionKeys");
|
|
|
|
settings.accessRestrictionKeys.insert(std::make_pair(s, true));
|
2011-10-05 13:08:27 -04:00
|
|
|
}
|
2012-08-18 17:31:32 -04:00
|
|
|
} else if( name == "accessForbiddenKeys") {
|
|
|
|
//split value at commas
|
|
|
|
std::vector<std::string> tokens;
|
|
|
|
stringSplit(value, ',', tokens);
|
|
|
|
//put each value into map
|
|
|
|
BOOST_FOREACH(std::string & s, tokens) {
|
|
|
|
INFO("adding " << s << " to accessForbiddenKeys");
|
|
|
|
settings.accessForbiddenKeys.insert(std::make_pair(s, true));
|
|
|
|
}
|
|
|
|
} else if( name == "accessForbiddenDefault") {
|
|
|
|
//split value at commas
|
|
|
|
std::vector<std::string> tokens;
|
|
|
|
stringSplit(value, ',', tokens);
|
|
|
|
//put each value into map
|
|
|
|
BOOST_FOREACH(std::string & s, tokens) {
|
|
|
|
INFO("adding " << s << " to accessForbiddenDefault");
|
|
|
|
settings.accessForbiddenDefault.insert(std::make_pair(s, true));
|
|
|
|
}
|
2011-10-05 13:08:27 -04:00
|
|
|
}
|
2012-03-22 05:25:04 -04:00
|
|
|
settings.speedProfile[name] = std::make_pair(std::atoi(value.c_str()), settings.speedProfile.size() );
|
2011-10-04 09:42:24 -04:00
|
|
|
}
|
|
|
|
} catch(std::exception& e) {
|
|
|
|
ERR("caught: " << e.what() );
|
|
|
|
}
|
2011-03-24 11:06:49 -04:00
|
|
|
|
2012-08-29 12:33:18 -04:00
|
|
|
/*** Setup Scripting Environment ***/
|
|
|
|
|
|
|
|
// Create a new lua state
|
|
|
|
lua_State *myLuaState = luaL_newstate();
|
|
|
|
|
|
|
|
// Connect LuaBind to this lua state
|
|
|
|
luabind::open(myLuaState);
|
|
|
|
|
|
|
|
// Add our function to the state's global scope
|
|
|
|
luabind::module(myLuaState) [
|
|
|
|
luabind::def("print", LUA_print<std::string>)
|
|
|
|
];
|
|
|
|
|
|
|
|
if(0 != luaL_dostring(
|
|
|
|
myLuaState,
|
|
|
|
"print('Initializing LUA engine')\n"
|
|
|
|
)) {
|
|
|
|
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
|
|
|
|
}
|
|
|
|
|
|
|
|
luabind::module(myLuaState) [
|
|
|
|
luabind::class_<HashTable<std::string, std::string> >("keyVals")
|
|
|
|
.def("Add", &HashTable<std::string, std::string>::Add)
|
|
|
|
.def("Find", &HashTable<std::string, std::string>::Find)
|
|
|
|
];
|
|
|
|
|
|
|
|
luabind::module(myLuaState) [
|
|
|
|
luabind::class_<ImportNode>("Node")
|
|
|
|
.def(luabind::constructor<>())
|
|
|
|
.def_readwrite("lat", &ImportNode::lat)
|
|
|
|
.def_readwrite("lon", &ImportNode::lon)
|
|
|
|
.def_readwrite("id", &ImportNode::id)
|
|
|
|
.def_readwrite("bollard", &ImportNode::bollard)
|
|
|
|
.def_readwrite("traffic_light", &ImportNode::trafficLight)
|
|
|
|
.def_readwrite("tags", &ImportNode::keyVals)
|
|
|
|
];
|
|
|
|
// Now call our function in a lua script
|
|
|
|
if(0 != luaL_dofile(myLuaState, "profile.lua")) {
|
|
|
|
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
|
|
|
|
}
|
|
|
|
|
|
|
|
//open string library;
|
|
|
|
luaopen_string(myLuaState);
|
|
|
|
|
|
|
|
/*** End of Scripting Environment Setup; ***/
|
|
|
|
|
2011-03-24 11:06:49 -04:00
|
|
|
unsigned amountOfRAM = 1;
|
2011-05-07 03:36:17 -04:00
|
|
|
unsigned installedRAM = GetPhysicalmemory();
|
2011-07-06 08:33:41 -04:00
|
|
|
if(installedRAM < 2048264) {
|
2011-12-01 09:12:30 -05:00
|
|
|
WARN("Machine has less than 2GB RAM.");
|
2011-03-24 11:06:49 -04:00
|
|
|
}
|
|
|
|
if(testDataFile("extractor.ini")) {
|
|
|
|
ExtractorConfiguration extractorConfig("extractor.ini");
|
|
|
|
unsigned memoryAmountFromFile = atoi(extractorConfig.GetParameter("Memory").c_str());
|
2011-10-05 12:04:01 -04:00
|
|
|
if( memoryAmountFromFile != 0 && memoryAmountFromFile <= installedRAM/(1024*1024))
|
2011-03-24 11:06:49 -04:00
|
|
|
amountOfRAM = memoryAmountFromFile;
|
2011-12-01 09:12:30 -05:00
|
|
|
INFO("Using " << amountOfRAM << " GB of RAM for buffers");
|
2011-03-24 11:06:49 -04:00
|
|
|
}
|
|
|
|
|
2011-12-01 09:12:30 -05:00
|
|
|
StringMap stringMap;
|
2012-08-29 12:33:18 -04:00
|
|
|
ExtractionContainers externalMemory;
|
2011-01-12 13:08:10 -05:00
|
|
|
|
2011-10-05 13:08:27 -04:00
|
|
|
stringMap[""] = 0;
|
2011-10-04 09:42:24 -04:00
|
|
|
extractCallBacks = new ExtractorCallbacks(&externalMemory, settings, &stringMap);
|
2011-07-06 08:33:41 -04:00
|
|
|
BaseParser<_Node, _RawRestrictionContainer, _Way> * parser;
|
2011-03-18 06:55:18 -04:00
|
|
|
if(isPBF) {
|
2011-01-12 13:08:10 -05:00
|
|
|
parser = new PBFParser(argv[1]);
|
2011-03-18 06:55:18 -04:00
|
|
|
} else {
|
2011-01-12 13:08:10 -05:00
|
|
|
parser = new XMLParser(argv[1]);
|
2011-03-18 06:55:18 -04:00
|
|
|
}
|
2012-08-29 12:33:18 -04:00
|
|
|
parser->RegisterCallbacks(&nodeFunction, &restrictionFunction, &wayFunction);
|
|
|
|
parser->RegisterLUAState(myLuaState);
|
|
|
|
|
2012-01-31 14:38:52 -05:00
|
|
|
if(!parser->Init())
|
|
|
|
INFO("Parser not initialized!");
|
2011-12-01 09:12:30 -05:00
|
|
|
parser->Parse();
|
2011-01-12 13:08:10 -05:00
|
|
|
|
2012-08-29 12:33:18 -04:00
|
|
|
externalMemory.PrepareData(settings, outputFileName, restrictionsFileName, amountOfRAM);
|
2011-01-12 13:08:10 -05:00
|
|
|
|
2012-01-31 14:38:52 -05:00
|
|
|
stringMap.clear();
|
2012-02-13 09:21:51 -05:00
|
|
|
delete parser;
|
2011-01-14 11:54:42 -05:00
|
|
|
delete extractCallBacks;
|
2012-05-10 05:23:46 -04:00
|
|
|
INFO("[extractor] finished.");
|
|
|
|
std::cout << "\nRun:\n"
|
|
|
|
"./osrm-prepare " << outputFileName << " " << restrictionsFileName << std::endl;
|
2011-01-12 13:08:10 -05:00
|
|
|
return 0;
|
2010-07-15 10:45:43 -04:00
|
|
|
}
|
2011-01-14 11:54:42 -05:00
|
|
|
|
|
|
|
bool nodeFunction(_Node n) {
|
|
|
|
extractCallBacks->nodeFunction(n);
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-18 06:55:18 -04:00
|
|
|
|
2011-07-06 08:33:41 -04:00
|
|
|
bool restrictionFunction(_RawRestrictionContainer r) {
|
|
|
|
extractCallBacks->restrictionFunction(r);
|
2011-10-08 14:37:16 -04:00
|
|
|
++globalRestrictionCounter;
|
2011-01-14 11:54:42 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool wayFunction(_Way w) {
|
|
|
|
extractCallBacks->wayFunction(w);
|
|
|
|
return true;
|
|
|
|
}
|