2010-07-15 10:45:43 -04:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
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"
|
2013-08-10 07:29:24 -04:00
|
|
|
#include "Util/GitDescription.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"
|
2013-08-05 11:28:57 -04:00
|
|
|
#include "Util/OSRMException.h"
|
2013-08-10 07:29:24 -04:00
|
|
|
#include "Util/ProgramOptions.h"
|
2013-08-08 08:17:01 -04:00
|
|
|
#include "Util/SimpleLogger.h"
|
2012-11-22 11:23:31 -05:00
|
|
|
#include "Util/StringUtil.h"
|
2013-07-22 10:34:06 -04:00
|
|
|
#include "Util/UUID.h"
|
2013-06-24 16:47:35 -04:00
|
|
|
#include "typedefs.h"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
2013-06-26 20:05:03 -04:00
|
|
|
|
2014-05-20 18:09:57 -04:00
|
|
|
#include <thread>
|
2014-05-06 12:35:51 -04:00
|
|
|
#include <chrono>
|
2013-06-24 16:47:35 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
2014-05-09 12:40:07 -04:00
|
|
|
#include <unordered_map>
|
2011-10-04 09:42:24 -04:00
|
|
|
|
2014-05-20 18:09:57 -04:00
|
|
|
#include <tbb/task_scheduler_init.h>
|
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
ExtractorCallbacks *extractor_callbacks;
|
2013-07-22 10:34:06 -04:00
|
|
|
UUID uuid;
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-08 08:17:01 -04:00
|
|
|
LogPolicy::GetInstance().Unmute();
|
2014-05-08 13:40:29 -04:00
|
|
|
std::chrono::time_point<std::chrono::steady_clock> startup_time =
|
|
|
|
std::chrono::steady_clock::now();
|
2013-08-10 07:29:24 -04:00
|
|
|
|
|
|
|
boost::filesystem::path config_file_path, input_path, profile_path;
|
2014-05-20 18:09:57 -04:00
|
|
|
unsigned int requested_num_threads;
|
2013-08-10 07:29:24 -04:00
|
|
|
|
|
|
|
// declare a group of options that will be allowed only on command line
|
|
|
|
boost::program_options::options_description generic_options("Options");
|
2014-05-08 13:40:29 -04:00
|
|
|
generic_options.add_options()("version,v", "Show version")("help,h",
|
|
|
|
"Show this help message")(
|
|
|
|
"config,c",
|
|
|
|
boost::program_options::value<boost::filesystem::path>(&config_file_path)
|
|
|
|
->default_value("extractor.ini"),
|
|
|
|
"Path to a configuration file.");
|
2013-08-10 07:29:24 -04:00
|
|
|
|
|
|
|
// declare a group of options that will be allowed both on command line and in config file
|
|
|
|
boost::program_options::options_description config_options("Configuration");
|
2014-05-08 13:40:29 -04:00
|
|
|
config_options.add_options()("profile,p",
|
|
|
|
boost::program_options::value<boost::filesystem::path>(
|
|
|
|
&profile_path)->default_value("profile.lua"),
|
|
|
|
"Path to LUA routing profile")(
|
|
|
|
"threads,t",
|
2014-05-20 18:09:57 -04:00
|
|
|
boost::program_options::value<unsigned int>(&requested_num_threads)->default_value(8),
|
2014-05-08 13:40:29 -04:00
|
|
|
"Number of threads to use");
|
|
|
|
|
|
|
|
// hidden options, will be allowed both on command line and in config file, but will not be
|
|
|
|
// shown to the user
|
2013-08-10 07:29:24 -04:00
|
|
|
boost::program_options::options_description hidden_options("Hidden options");
|
2014-05-08 13:40:29 -04:00
|
|
|
hidden_options.add_options()(
|
|
|
|
"input,i",
|
|
|
|
boost::program_options::value<boost::filesystem::path>(&input_path),
|
|
|
|
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
2013-08-10 07:29:24 -04:00
|
|
|
|
|
|
|
// positional option
|
|
|
|
boost::program_options::positional_options_description positional_options;
|
|
|
|
positional_options.add("input", 1);
|
|
|
|
|
|
|
|
// combine above options for parsing
|
|
|
|
boost::program_options::options_description cmdline_options;
|
|
|
|
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
|
|
|
|
|
|
|
|
boost::program_options::options_description config_file_options;
|
|
|
|
config_file_options.add(config_options).add(hidden_options);
|
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
boost::program_options::options_description visible_options(
|
|
|
|
boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
|
2013-08-10 07:29:24 -04:00
|
|
|
visible_options.add(generic_options).add(config_options);
|
|
|
|
|
|
|
|
// parse command line options
|
|
|
|
boost::program_options::variables_map option_variables;
|
2014-05-08 13:40:29 -04:00
|
|
|
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
|
|
|
.options(cmdline_options)
|
|
|
|
.positional(positional_options)
|
|
|
|
.run(),
|
|
|
|
option_variables);
|
2013-08-10 07:29:24 -04:00
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
if (option_variables.count("version"))
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2013-08-10 07:29:24 -04:00
|
|
|
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
|
|
|
return 0;
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2011-12-01 09:12:30 -05:00
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
if (option_variables.count("help"))
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2013-08-10 07:29:24 -04:00
|
|
|
SimpleLogger().Write() << visible_options;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-22 13:24:34 -05:00
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
boost::program_options::notify(option_variables);
|
2013-08-14 05:59:46 -04:00
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
// parse config file
|
2014-05-08 13:40:29 -04:00
|
|
|
if (boost::filesystem::is_regular_file(config_file_path))
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2014-04-28 07:19:26 -04:00
|
|
|
SimpleLogger().Write() << "Reading options from: " << config_file_path.string();
|
2014-05-13 07:30:52 -04:00
|
|
|
std::string ini_file_contents = ReadIniFileAndLowerContents(config_file_path);
|
|
|
|
std::stringstream config_stream(ini_file_contents);
|
2014-05-08 13:40:29 -04:00
|
|
|
boost::program_options::store(parse_config_file(config_stream, config_file_options),
|
|
|
|
option_variables);
|
2013-08-10 07:29:24 -04:00
|
|
|
boost::program_options::notify(option_variables);
|
2013-06-26 20:05:03 -04:00
|
|
|
}
|
2013-06-27 11:44:32 -04:00
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
if (!option_variables.count("input"))
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2014-03-14 06:14:19 -04:00
|
|
|
SimpleLogger().Write() << visible_options;
|
2014-04-21 11:20:15 -04:00
|
|
|
return 0;
|
2013-08-10 07:29:24 -04:00
|
|
|
}
|
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
if (1 > requested_num_threads)
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2013-08-10 07:29:24 -04:00
|
|
|
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
2014-04-21 11:20:15 -04:00
|
|
|
return 1;
|
2013-08-10 07:29:24 -04:00
|
|
|
}
|
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
if (!boost::filesystem::is_regular_file(input_path))
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2014-05-08 13:40:29 -04:00
|
|
|
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string()
|
|
|
|
<< " not found!";
|
2014-04-21 11:20:15 -04:00
|
|
|
return 1;
|
2014-04-19 07:19:48 -04:00
|
|
|
}
|
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
if (!boost::filesystem::is_regular_file(profile_path))
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2014-05-08 13:40:29 -04:00
|
|
|
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string()
|
|
|
|
<< " not found!";
|
2014-04-21 11:20:15 -04:00
|
|
|
return 1;
|
2014-04-19 07:19:48 -04:00
|
|
|
}
|
|
|
|
|
2014-05-20 18:09:57 -04:00
|
|
|
unsigned int hardware_threads = std::max((unsigned int) 1, std::thread::hardware_concurrency());
|
|
|
|
unsigned int real_num_threads = std::min(hardware_threads, requested_num_threads);
|
2014-05-01 12:32:01 -04:00
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
SimpleLogger().Write() << "Input file: " << input_path.filename().string();
|
|
|
|
SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
|
2014-05-08 13:40:29 -04:00
|
|
|
SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested "
|
|
|
|
<< requested_num_threads << ")";
|
2013-08-10 07:29:24 -04:00
|
|
|
|
2014-05-20 18:09:57 -04:00
|
|
|
tbb::task_scheduler_init init(real_num_threads);
|
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
/*** Setup Scripting Environment ***/
|
2014-05-08 13:40:29 -04:00
|
|
|
ScriptingEnvironment scripting_environment(profile_path.c_str());
|
2013-08-10 07:29:24 -04:00
|
|
|
|
2013-06-27 11:44:32 -04:00
|
|
|
bool file_has_pbf_format(false);
|
2014-04-28 07:08:25 -04:00
|
|
|
std::string output_file_name = input_path.string();
|
2014-05-08 13:40:29 -04:00
|
|
|
std::string restriction_fileName = input_path.string();
|
2013-06-27 11:44:32 -04:00
|
|
|
std::string::size_type pos = output_file_name.find(".osm.bz2");
|
2014-05-08 13:40:29 -04:00
|
|
|
if (pos == std::string::npos)
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2013-06-27 11:44:32 -04:00
|
|
|
pos = output_file_name.find(".osm.pbf");
|
2014-05-08 13:40:29 -04:00
|
|
|
if (pos != std::string::npos)
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2013-06-27 11:44:32 -04:00
|
|
|
file_has_pbf_format = true;
|
2013-07-17 07:20:48 -04:00
|
|
|
}
|
|
|
|
}
|
2014-05-08 13:40:29 -04:00
|
|
|
if (pos == std::string::npos)
|
2014-04-28 07:03:20 -04:00
|
|
|
{
|
2013-07-17 07:20:48 -04:00
|
|
|
pos = output_file_name.find(".pbf");
|
2014-05-08 13:40:29 -04:00
|
|
|
if (pos != std::string::npos)
|
2014-04-28 07:03:20 -04:00
|
|
|
{
|
2013-07-17 07:20:48 -04:00
|
|
|
file_has_pbf_format = true;
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2011-01-12 13:08:10 -05:00
|
|
|
}
|
2014-04-28 07:03:20 -04:00
|
|
|
if (pos == std::string::npos)
|
|
|
|
{
|
|
|
|
pos = output_file_name.find(".osm");
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
{
|
2013-06-27 11:44:32 -04:00
|
|
|
output_file_name.append(".osrm");
|
2014-05-08 13:40:29 -04:00
|
|
|
restriction_fileName.append(".osrm.restrictions");
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2014-04-28 07:03:20 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
output_file_name.replace(pos, 5, ".osrm");
|
2014-05-08 13:40:29 -04:00
|
|
|
restriction_fileName.replace(pos, 5, ".osrm.restrictions");
|
2014-04-28 07:03:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output_file_name.replace(pos, 8, ".osrm");
|
2014-05-08 13:40:29 -04:00
|
|
|
restriction_fileName.replace(pos, 8, ".osrm.restrictions");
|
2011-01-12 13:08:10 -05:00
|
|
|
}
|
2011-03-24 11:06:49 -04:00
|
|
|
|
2014-05-09 12:40:07 -04:00
|
|
|
std::unordered_map<std::string, NodeID> string_map;
|
2014-05-08 13:40:29 -04:00
|
|
|
ExtractionContainers extraction_containers;
|
2011-01-12 13:08:10 -05:00
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
string_map[""] = 0;
|
2014-05-09 10:17:31 -04:00
|
|
|
extractor_callbacks = new ExtractorCallbacks(extraction_containers, string_map);
|
2014-05-08 13:40:29 -04:00
|
|
|
BaseParser *parser;
|
|
|
|
if (file_has_pbf_format)
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2014-05-08 13:40:29 -04:00
|
|
|
parser = new PBFParser(input_path.c_str(), extractor_callbacks, scripting_environment);
|
2014-04-28 07:08:25 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-08 13:40:29 -04:00
|
|
|
parser = new XMLParser(input_path.c_str(), extractor_callbacks, scripting_environment);
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2013-06-24 16:47:35 -04:00
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
if (!parser->ReadHeader())
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2013-08-05 11:28:57 -04:00
|
|
|
throw OSRMException("Parser not initialized!");
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "Parsing in progress..";
|
2014-05-08 13:40:29 -04:00
|
|
|
std::chrono::time_point<std::chrono::steady_clock> parsing_start_time =
|
|
|
|
std::chrono::steady_clock::now();
|
2014-05-06 12:16:10 -04:00
|
|
|
|
2013-06-27 11:44:32 -04:00
|
|
|
parser->Parse();
|
2014-05-09 10:17:31 -04:00
|
|
|
delete parser;
|
|
|
|
delete extractor_callbacks;
|
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
std::chrono::duration<double> parsing_duration =
|
|
|
|
std::chrono::steady_clock::now() - parsing_start_time;
|
|
|
|
SimpleLogger().Write() << "Parsing finished after " << parsing_duration.count()
|
|
|
|
<< " seconds";
|
2013-06-27 11:44:32 -04:00
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
if (extraction_containers.all_edges_list.empty())
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2014-03-19 13:03:38 -04:00
|
|
|
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
|
2014-04-21 11:20:15 -04:00
|
|
|
return 1;
|
2014-03-19 13:03:38 -04:00
|
|
|
}
|
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
extraction_containers.PrepareData(output_file_name, restriction_fileName);
|
2013-06-27 11:44:32 -04:00
|
|
|
|
2014-05-08 13:40:29 -04:00
|
|
|
std::chrono::duration<double> extraction_duration =
|
|
|
|
std::chrono::steady_clock::now() - startup_time;
|
|
|
|
SimpleLogger().Write() << "extraction finished after " << extraction_duration.count()
|
|
|
|
<< "s";
|
|
|
|
SimpleLogger().Write() << "To prepare the data for routing, run: "
|
|
|
|
<< "./osrm-prepare " << output_file_name << std::endl;
|
2014-04-28 07:08:25 -04:00
|
|
|
}
|
2014-05-08 13:40:29 -04:00
|
|
|
catch (boost::program_options::too_many_positional_options_error &e)
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2013-08-10 07:29:24 -04:00
|
|
|
SimpleLogger().Write(logWARNING) << "Only one input file can be specified";
|
2014-04-21 11:20:15 -04:00
|
|
|
return 1;
|
2014-04-28 07:08:25 -04:00
|
|
|
}
|
2014-05-08 13:40:29 -04:00
|
|
|
catch (std::exception &e)
|
2014-04-28 07:08:25 -04:00
|
|
|
{
|
2014-04-28 05:55:46 -04:00
|
|
|
SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what();
|
2014-04-21 11:20:15 -04:00
|
|
|
return 1;
|
2013-02-10 12:28:04 -05:00
|
|
|
}
|
2013-08-05 11:28:57 -04:00
|
|
|
return 0;
|
2010-07-15 10:45:43 -04:00
|
|
|
}
|