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
|
|
|
|
2012-08-29 12:33:18 -04:00
|
|
|
#include "Extractor/ExtractorCallbacks.h"
|
2012-08-30 10:59:41 -04:00
|
|
|
#include "Extractor/ExtractionContainers.h"
|
2012-11-19 13:04:59 -05:00
|
|
|
#include "Extractor/ScriptingEnvironment.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"
|
2013-01-01 18:33:14 -05:00
|
|
|
#include "Util/OpenMPWrapper.h"
|
2012-11-22 11:23:31 -05:00
|
|
|
#include "Util/StringUtil.h"
|
2013-06-24 16:47:35 -04:00
|
|
|
#include "typedefs.h"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <string>
|
2011-10-04 09:42:24 -04:00
|
|
|
|
2011-03-24 11:06:49 -04:00
|
|
|
typedef BaseConfiguration ExtractorConfiguration;
|
2010-07-15 10:45:43 -04:00
|
|
|
|
2011-01-14 11:54:42 -05:00
|
|
|
ExtractorCallbacks * extractCallBacks;
|
2011-01-09 16:42:27 -05:00
|
|
|
|
|
|
|
int main (int argc, char *argv[]) {
|
2013-01-01 11:25:40 -05:00
|
|
|
double earliestTime = get_timestamp();
|
|
|
|
|
2012-02-08 04:35:59 -05:00
|
|
|
if(argc < 2) {
|
2012-10-06 11:21:53 -04:00
|
|
|
ERR("usage: \n" << argv[0] << " <file.osm/.osm.bz2/.osm.pbf> [<profile.lua>]");
|
2012-02-08 04:35:59 -05:00
|
|
|
}
|
2011-12-01 09:12:30 -05:00
|
|
|
|
2012-11-22 13:24:34 -05:00
|
|
|
/*** Setup Scripting Environment ***/
|
|
|
|
ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua"));
|
|
|
|
|
2012-11-22 11:23:31 -05:00
|
|
|
unsigned numberOfThreads = omp_get_num_procs();
|
|
|
|
if(testDataFile("extractor.ini")) {
|
|
|
|
ExtractorConfiguration extractorConfig("extractor.ini");
|
|
|
|
unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads"));
|
|
|
|
if( rawNumber != 0 && rawNumber <= numberOfThreads)
|
|
|
|
numberOfThreads = rawNumber;
|
|
|
|
}
|
|
|
|
omp_set_num_threads(numberOfThreads);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-12-29 15:02:26 -05:00
|
|
|
if(pos!=std::string::npos) {
|
2011-01-12 13:08:10 -05:00
|
|
|
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");
|
2012-12-29 15:02:26 -05:00
|
|
|
if(pos!=std::string::npos) {
|
2011-01-12 13:08:10 -05:00
|
|
|
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-03-24 11:06:49 -04:00
|
|
|
|
|
|
|
unsigned amountOfRAM = 1;
|
2013-06-24 16:47:35 -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
|
|
|
}
|
2013-06-24 16:47:35 -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;
|
2012-08-30 10:59:41 -04:00
|
|
|
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
|
2013-02-10 04:59:54 -05:00
|
|
|
BaseParser* parser;
|
2011-03-18 06:55:18 -04:00
|
|
|
if(isPBF) {
|
2013-02-10 12:28:04 -05:00
|
|
|
parser = new PBFParser(argv[1], extractCallBacks, scriptingEnvironment);
|
2011-03-18 06:55:18 -04:00
|
|
|
} else {
|
2013-02-10 12:28:04 -05:00
|
|
|
parser = new XMLParser(argv[1], extractCallBacks, scriptingEnvironment);
|
2011-03-18 06:55:18 -04:00
|
|
|
}
|
2013-06-24 16:47:35 -04:00
|
|
|
|
2013-02-10 12:28:04 -05:00
|
|
|
if(!parser->ReadHeader()) {
|
2012-11-19 05:52:34 -05:00
|
|
|
ERR("Parser not initialized!");
|
2013-02-10 12:28:04 -05:00
|
|
|
}
|
2013-02-10 04:59:54 -05:00
|
|
|
INFO("Parsing in progress..");
|
2012-11-19 05:52:34 -05:00
|
|
|
double time = get_timestamp();
|
2011-12-01 09:12:30 -05:00
|
|
|
parser->Parse();
|
2013-02-10 04:59:54 -05:00
|
|
|
INFO("Parsing finished after " << get_timestamp() - time << " seconds");
|
2011-01-12 13:08:10 -05:00
|
|
|
|
2012-08-30 10:59:41 -04:00
|
|
|
externalMemory.PrepareData(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;
|
2013-01-01 11:25:40 -05:00
|
|
|
INFO("finished after " << get_timestamp() - earliestTime << "s");
|
|
|
|
|
2012-05-10 05:23:46 -04:00
|
|
|
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
|
|
|
}
|