2016-01-02 11:13:44 -05:00
|
|
|
#include "contractor/contractor.hpp"
|
2016-03-09 07:18:09 -05:00
|
|
|
#include "contractor/crc32_processor.hpp"
|
2017-04-04 18:00:17 -04:00
|
|
|
#include "contractor/files.hpp"
|
2016-01-07 13:19:55 -05:00
|
|
|
#include "contractor/graph_contractor.hpp"
|
2017-01-13 02:32:17 -05:00
|
|
|
#include "contractor/graph_contractor_adaptors.hpp"
|
2015-11-09 15:14:39 -05:00
|
|
|
|
2016-01-29 20:52:20 -05:00
|
|
|
#include "extractor/compressed_edge_container.hpp"
|
2016-06-24 01:01:37 -04:00
|
|
|
#include "extractor/edge_based_graph_factory.hpp"
|
2016-05-16 17:11:01 -04:00
|
|
|
#include "extractor/node_based_edge.hpp"
|
2016-01-29 20:52:20 -05:00
|
|
|
|
2016-11-18 06:14:38 -05:00
|
|
|
#include "storage/io.hpp"
|
2017-03-07 18:30:49 -05:00
|
|
|
|
|
|
|
#include "updater/updater.hpp"
|
|
|
|
|
2016-05-16 17:11:01 -04:00
|
|
|
#include "util/exception.hpp"
|
2016-12-06 15:30:46 -05:00
|
|
|
#include "util/exception_utils.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/graph_loader.hpp"
|
|
|
|
#include "util/integer_range.hpp"
|
2016-12-06 15:30:46 -05:00
|
|
|
#include "util/log.hpp"
|
2016-05-16 17:11:01 -04:00
|
|
|
#include "util/static_graph.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/string_util.hpp"
|
|
|
|
#include "util/timing_util.hpp"
|
|
|
|
#include "util/typedefs.hpp"
|
2014-07-03 07:29:15 -04:00
|
|
|
|
2016-05-20 13:20:12 -04:00
|
|
|
#include <algorithm>
|
2016-01-07 04:33:47 -05:00
|
|
|
#include <bitset>
|
2016-05-16 17:11:01 -04:00
|
|
|
#include <cstdint>
|
2016-05-18 10:59:52 -04:00
|
|
|
#include <fstream>
|
2016-05-16 17:11:01 -04:00
|
|
|
#include <iterator>
|
2014-07-03 07:29:15 -04:00
|
|
|
#include <memory>
|
2016-05-18 10:59:52 -04:00
|
|
|
#include <vector>
|
2014-07-03 07:29:15 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace contractor
|
|
|
|
{
|
2016-09-12 12:16:56 -04:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
int Contractor::Run()
|
2014-07-03 07:29:15 -04:00
|
|
|
{
|
2016-01-05 06:04:04 -05:00
|
|
|
if (config.core_factor > 1.0 || config.core_factor < 0)
|
2015-10-14 18:08:22 -04:00
|
|
|
{
|
2016-12-06 15:30:46 -05:00
|
|
|
throw util::exception("Core factor must be between 0.0 to 1.0 (inclusive)" + SOURCE_REF);
|
2015-10-14 18:08:22 -04:00
|
|
|
}
|
|
|
|
|
2014-07-03 07:29:15 -04:00
|
|
|
TIMER_START(preparing);
|
|
|
|
|
2016-12-08 17:35:34 -05:00
|
|
|
util::Log() << "Reading node weights.";
|
|
|
|
std::vector<EdgeWeight> node_weights;
|
|
|
|
{
|
2017-04-04 18:00:17 -04:00
|
|
|
storage::io::FileReader reader(config.node_file_path,
|
2017-04-04 19:01:00 -04:00
|
|
|
storage::io::FileReader::VerifyFingerprint);
|
2017-04-04 18:00:17 -04:00
|
|
|
storage::serialization::read(reader, node_weights);
|
2016-12-08 17:35:34 -05:00
|
|
|
}
|
|
|
|
util::Log() << "Done reading node weights.";
|
|
|
|
|
2016-12-06 15:30:46 -05:00
|
|
|
util::Log() << "Loading edge-expanded graph representation";
|
2014-07-03 07:29:15 -04:00
|
|
|
|
2017-01-13 02:32:17 -05:00
|
|
|
std::vector<extractor::EdgeBasedEdge> edge_based_edge_list;
|
2015-07-04 11:37:24 -04:00
|
|
|
|
2017-03-07 18:30:49 -05:00
|
|
|
updater::Updater updater(config.updater_config);
|
|
|
|
EdgeID max_edge_id = updater.LoadAndUpdateEdgeExpandedGraph(edge_based_edge_list, node_weights);
|
2017-02-10 05:41:31 -05:00
|
|
|
|
2015-04-23 11:48:41 -04:00
|
|
|
// Contracting the edge-expanded graph
|
2014-07-03 07:29:15 -04:00
|
|
|
|
|
|
|
TIMER_START(contraction);
|
2015-08-08 09:28:05 -04:00
|
|
|
std::vector<bool> is_core_node;
|
2015-11-09 15:14:39 -05:00
|
|
|
std::vector<float> node_levels;
|
|
|
|
if (config.use_cached_priority)
|
|
|
|
{
|
|
|
|
ReadNodeLevels(node_levels);
|
|
|
|
}
|
2016-01-07 04:33:47 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
util::DeallocatingVector<QueryEdge> contracted_edge_list;
|
2017-01-13 02:32:17 -05:00
|
|
|
{ // own scope to not keep the contractor around
|
|
|
|
GraphContractor graph_contractor(max_edge_id + 1,
|
|
|
|
adaptToContractorInput(std::move(edge_based_edge_list)),
|
|
|
|
std::move(node_levels),
|
|
|
|
std::move(node_weights));
|
|
|
|
graph_contractor.Run(config.core_factor);
|
|
|
|
graph_contractor.GetEdges(contracted_edge_list);
|
|
|
|
graph_contractor.GetCoreMarker(is_core_node);
|
|
|
|
graph_contractor.GetNodeLevels(node_levels);
|
|
|
|
}
|
2014-07-03 07:29:15 -04:00
|
|
|
TIMER_STOP(contraction);
|
|
|
|
|
2016-12-06 15:30:46 -05:00
|
|
|
util::Log() << "Contraction took " << TIMER_SEC(contraction) << " sec";
|
2014-07-03 07:29:15 -04:00
|
|
|
|
2017-04-02 19:02:57 -04:00
|
|
|
WriteContractedGraph(max_edge_id, std::move(contracted_edge_list));
|
2015-08-08 09:28:05 -04:00
|
|
|
WriteCoreNodeMarker(std::move(is_core_node));
|
2015-11-09 15:14:39 -05:00
|
|
|
if (!config.use_cached_priority)
|
|
|
|
{
|
|
|
|
WriteNodeLevels(std::move(node_levels));
|
|
|
|
}
|
2015-04-23 12:53:36 -04:00
|
|
|
|
|
|
|
TIMER_STOP(preparing);
|
|
|
|
|
2016-12-06 15:30:46 -05:00
|
|
|
util::Log() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds";
|
2015-04-23 12:53:36 -04:00
|
|
|
|
2016-12-06 15:30:46 -05:00
|
|
|
util::Log() << "finished preprocessing";
|
2015-04-23 12:53:36 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
void Contractor::ReadNodeLevels(std::vector<float> &node_levels) const
|
2015-11-09 15:14:39 -05:00
|
|
|
{
|
2017-04-07 05:02:02 -04:00
|
|
|
files::readLevels(config.level_output_path, node_levels);
|
2015-11-09 15:14:39 -05:00
|
|
|
}
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
void Contractor::WriteNodeLevels(std::vector<float> &&in_node_levels) const
|
2015-11-09 15:14:39 -05:00
|
|
|
{
|
|
|
|
std::vector<float> node_levels(std::move(in_node_levels));
|
|
|
|
|
2017-04-07 05:02:02 -04:00
|
|
|
files::writeLevels(config.level_output_path, node_levels);
|
2015-11-09 15:14:39 -05:00
|
|
|
}
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
void Contractor::WriteCoreNodeMarker(std::vector<bool> &&in_is_core_node) const
|
2015-08-08 09:28:05 -04:00
|
|
|
{
|
2015-11-09 15:14:39 -05:00
|
|
|
std::vector<bool> is_core_node(std::move(in_is_core_node));
|
|
|
|
std::vector<char> unpacked_bool_flags(std::move(is_core_node.size()));
|
2015-08-08 09:28:05 -04:00
|
|
|
for (auto i = 0u; i < is_core_node.size(); ++i)
|
|
|
|
{
|
|
|
|
unpacked_bool_flags[i] = is_core_node[i] ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2017-03-04 05:52:40 -05:00
|
|
|
storage::io::FileWriter core_marker_output_file(config.core_output_path,
|
2017-04-07 12:43:43 -04:00
|
|
|
storage::io::FileWriter::GenerateFingerprint);
|
2017-03-04 05:52:40 -05:00
|
|
|
|
|
|
|
const std::size_t count = unpacked_bool_flags.size();
|
2017-04-07 12:43:43 -04:00
|
|
|
core_marker_output_file.WriteElementCount64(count);
|
2017-03-04 05:52:40 -05:00
|
|
|
core_marker_output_file.WriteFrom(unpacked_bool_flags.data(), count);
|
2015-08-08 09:28:05 -04:00
|
|
|
}
|
|
|
|
|
2017-04-04 18:00:17 -04:00
|
|
|
void Contractor::WriteContractedGraph(unsigned max_node_id,
|
|
|
|
util::DeallocatingVector<QueryEdge> contracted_edge_list)
|
2015-04-23 12:53:36 -04:00
|
|
|
{
|
|
|
|
// Sorting contracted edges in a way that the static query graph can read some in in-place.
|
2015-09-10 05:04:50 -04:00
|
|
|
tbb::parallel_sort(contracted_edge_list.begin(), contracted_edge_list.end());
|
2017-04-02 19:02:57 -04:00
|
|
|
auto new_end = std::unique(contracted_edge_list.begin(), contracted_edge_list.end());
|
|
|
|
contracted_edge_list.resize(new_end - contracted_edge_list.begin());
|
2014-07-03 07:29:15 -04:00
|
|
|
|
2015-10-01 15:47:29 -04:00
|
|
|
RangebasedCRC32 crc32_calculator;
|
2017-04-02 19:02:57 -04:00
|
|
|
const unsigned checksum = crc32_calculator(contracted_edge_list);
|
2014-07-03 07:29:15 -04:00
|
|
|
|
2017-04-04 18:00:17 -04:00
|
|
|
QueryGraph query_graph{max_node_id + 1, contracted_edge_list};
|
2014-07-03 07:29:15 -04:00
|
|
|
|
2017-04-02 19:02:57 -04:00
|
|
|
files::writeGraph(config.graph_output_path, checksum, query_graph);
|
2014-07-03 07:29:15 -04:00
|
|
|
}
|
|
|
|
|
2017-01-13 02:32:17 -05:00
|
|
|
} // namespace contractor
|
|
|
|
} // namespace osrm
|