2016-01-07 13:19:55 -05:00
|
|
|
#include "contractor/contractor.hpp"
|
|
|
|
#include "contractor/contractor_config.hpp"
|
2015-02-09 11:38:40 -05:00
|
|
|
#include "util/simple_logger.hpp"
|
2016-01-07 13:19:55 -05:00
|
|
|
#include "util/version.hpp"
|
2014-05-06 12:15:45 -04:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/program_options.hpp>
|
2015-02-09 11:38:40 -05:00
|
|
|
#include <boost/program_options/errors.hpp>
|
|
|
|
|
2015-04-24 08:51:25 -04:00
|
|
|
#include <tbb/task_scheduler_init.h>
|
|
|
|
|
2015-10-18 06:19:06 -04:00
|
|
|
#include <cstdlib>
|
2015-02-09 11:38:40 -05:00
|
|
|
#include <exception>
|
2015-10-18 06:34:42 -04:00
|
|
|
#include <new>
|
2016-01-03 12:55:42 -05:00
|
|
|
#include <ostream>
|
2014-05-08 13:40:29 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
using namespace osrm;
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
enum class return_code : unsigned
|
|
|
|
{
|
|
|
|
ok,
|
|
|
|
fail,
|
|
|
|
exit
|
|
|
|
};
|
|
|
|
|
|
|
|
return_code
|
|
|
|
parseArguments(int argc, char *argv[], contractor::ContractorConfig &contractor_config)
|
|
|
|
{
|
|
|
|
// declare a group of options that will be allowed only on command line
|
|
|
|
boost::program_options::options_description generic_options("Options");
|
2016-02-12 20:11:35 -05:00
|
|
|
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message");
|
2016-01-07 13:19:55 -05:00
|
|
|
|
2016-02-12 20:11:35 -05:00
|
|
|
// declare a group of options that will be allowed on command line
|
2016-01-07 13:19:55 -05:00
|
|
|
boost::program_options::options_description config_options("Configuration");
|
|
|
|
config_options.add_options()(
|
|
|
|
"profile,p",
|
|
|
|
boost::program_options::value<boost::filesystem::path>(&contractor_config.profile_path)
|
|
|
|
->default_value("profile.lua"),
|
|
|
|
"Path to LUA routing profile")(
|
|
|
|
"threads,t",
|
|
|
|
boost::program_options::value<unsigned int>(&contractor_config.requested_num_threads)
|
|
|
|
->default_value(tbb::task_scheduler_init::default_num_threads()),
|
|
|
|
"Number of threads to use")(
|
|
|
|
"core,k",
|
|
|
|
boost::program_options::value<double>(&contractor_config.core_factor)->default_value(1.0),
|
|
|
|
"Percentage of the graph (in vertices) to contract [0..1]")(
|
|
|
|
"segment-speed-file",
|
|
|
|
boost::program_options::value<std::string>(&contractor_config.segment_speed_lookup_path),
|
|
|
|
"Lookup file containing nodeA,nodeB,speed data to adjust edge weights")(
|
|
|
|
"level-cache,o", boost::program_options::value<bool>(&contractor_config.use_cached_priority)
|
|
|
|
->default_value(false),
|
|
|
|
"Use .level file to retain the contaction level for each node from the last run.");
|
|
|
|
|
|
|
|
#ifdef DEBUG_GEOMETRY
|
|
|
|
config_options.add_options()(
|
|
|
|
"debug-geometry",
|
|
|
|
boost::program_options::value<std::string>(&contractor_config.debug_geometry_path),
|
|
|
|
"Write out edge-weight debugging geometry data in GeoJSON format to this file");
|
|
|
|
#endif
|
|
|
|
|
2016-02-12 20:11:35 -05:00
|
|
|
// hidden options, will be allowed on command line, but will not be shown to the user
|
2016-01-07 13:19:55 -05:00
|
|
|
boost::program_options::options_description hidden_options("Hidden options");
|
|
|
|
hidden_options.add_options()("input,i", boost::program_options::value<boost::filesystem::path>(
|
|
|
|
&contractor_config.osrm_input_path),
|
|
|
|
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
|
|
|
|
|
|
|
// 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 visible_options(
|
|
|
|
"Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]");
|
|
|
|
visible_options.add(generic_options).add(config_options);
|
|
|
|
|
|
|
|
// parse command line options
|
|
|
|
boost::program_options::variables_map option_variables;
|
|
|
|
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
|
|
|
.options(cmdline_options)
|
|
|
|
.positional(positional_options)
|
|
|
|
.run(),
|
|
|
|
option_variables);
|
|
|
|
|
|
|
|
if (option_variables.count("version"))
|
|
|
|
{
|
|
|
|
util::SimpleLogger().Write() << OSRM_VERSION;
|
|
|
|
return return_code::exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option_variables.count("help"))
|
|
|
|
{
|
|
|
|
util::SimpleLogger().Write() << "\n" << visible_options;
|
|
|
|
return return_code::exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::program_options::notify(option_variables);
|
|
|
|
|
|
|
|
if (!option_variables.count("input"))
|
|
|
|
{
|
|
|
|
util::SimpleLogger().Write() << "\n" << visible_options;
|
|
|
|
return return_code::fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_code::ok;
|
|
|
|
}
|
|
|
|
|
2015-10-18 06:19:06 -04:00
|
|
|
int main(int argc, char *argv[]) try
|
2014-05-08 13:40:29 -04:00
|
|
|
{
|
2016-01-05 10:51:13 -05:00
|
|
|
util::LogPolicy::GetInstance().Unmute();
|
|
|
|
contractor::ContractorConfig contractor_config;
|
2015-10-18 06:19:06 -04:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
const return_code result = parseArguments(argc, argv, contractor_config);
|
2015-10-18 06:19:06 -04:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
if (return_code::fail == result)
|
2014-05-08 13:40:29 -04:00
|
|
|
{
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_FAILURE;
|
2014-05-08 13:40:29 -04:00
|
|
|
}
|
2015-10-18 06:19:06 -04:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
if (return_code::exit == result)
|
2014-05-08 13:40:29 -04:00
|
|
|
{
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_SUCCESS;
|
2015-10-18 06:19:06 -04:00
|
|
|
}
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
contractor_config.UseDefaultOutputNames();
|
2015-10-18 06:19:06 -04:00
|
|
|
|
|
|
|
if (1 > contractor_config.requested_num_threads)
|
|
|
|
{
|
2016-01-05 10:51:13 -05:00
|
|
|
util::SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_FAILURE;
|
2013-10-14 11:03:46 -04:00
|
|
|
}
|
2015-10-18 06:19:06 -04:00
|
|
|
|
|
|
|
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
|
|
|
|
|
|
|
|
if (recommended_num_threads != contractor_config.requested_num_threads)
|
|
|
|
{
|
2016-01-07 19:31:57 -05:00
|
|
|
util::SimpleLogger().Write(logWARNING)
|
|
|
|
<< "The recommended number of threads is " << recommended_num_threads
|
|
|
|
<< "! This setting may have performance side-effects.";
|
2015-10-18 06:19:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!boost::filesystem::is_regular_file(contractor_config.osrm_input_path))
|
|
|
|
{
|
2016-01-05 10:51:13 -05:00
|
|
|
util::SimpleLogger().Write(logWARNING)
|
2015-10-18 06:19:06 -04:00
|
|
|
<< "Input file " << contractor_config.osrm_input_path.string() << " not found!";
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_FAILURE;
|
2015-10-18 06:19:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!boost::filesystem::is_regular_file(contractor_config.profile_path))
|
|
|
|
{
|
2016-01-07 19:31:57 -05:00
|
|
|
util::SimpleLogger().Write(logWARNING)
|
|
|
|
<< "Profile " << contractor_config.profile_path.string() << " not found!";
|
2015-10-18 06:34:42 -04:00
|
|
|
return EXIT_FAILURE;
|
2015-10-18 06:19:06 -04:00
|
|
|
}
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
util::SimpleLogger().Write() << "Input file: "
|
2016-01-07 19:31:57 -05:00
|
|
|
<< contractor_config.osrm_input_path.filename().string();
|
|
|
|
util::SimpleLogger().Write() << "Profile: "
|
|
|
|
<< contractor_config.profile_path.filename().string();
|
2016-01-05 10:51:13 -05:00
|
|
|
util::SimpleLogger().Write() << "Threads: " << contractor_config.requested_num_threads;
|
2015-10-18 06:19:06 -04:00
|
|
|
|
|
|
|
tbb::task_scheduler_init init(contractor_config.requested_num_threads);
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
return contractor::Contractor(contractor_config).Run();
|
2015-10-18 06:19:06 -04:00
|
|
|
}
|
2015-10-18 06:34:42 -04:00
|
|
|
catch (const std::bad_alloc &e)
|
|
|
|
{
|
2016-01-05 10:51:13 -05:00
|
|
|
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
|
|
|
util::SimpleLogger().Write(logWARNING)
|
2015-10-18 06:34:42 -04:00
|
|
|
<< "Please provide more memory or consider using a larger swapfile";
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2015-10-18 06:19:06 -04:00
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
2016-01-05 10:51:13 -05:00
|
|
|
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
2015-10-18 06:19:06 -04:00
|
|
|
return EXIT_FAILURE;
|
2013-10-14 11:03:46 -04:00
|
|
|
}
|