osrm-backend/src/contractor/contractor.cpp

113 lines
3.3 KiB
C++
Raw Normal View History

2016-01-02 11:13:44 -05:00
#include "contractor/contractor.hpp"
#include "contractor/crc32_processor.hpp"
#include "contractor/files.hpp"
#include "contractor/graph_contractor.hpp"
#include "contractor/graph_contractor_adaptors.hpp"
#include "extractor/compressed_edge_container.hpp"
#include "extractor/edge_based_graph_factory.hpp"
2016-05-16 17:11:01 -04:00
#include "extractor/node_based_edge.hpp"
#include "storage/io.hpp"
#include "updater/updater.hpp"
2016-05-16 17:11:01 -04:00
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
2016-01-02 11:13:44 -05:00
#include "util/graph_loader.hpp"
#include "util/integer_range.hpp"
#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
#include <algorithm>
#include <bitset>
2016-05-16 17:11:01 -04:00
#include <cstdint>
#include <fstream>
2016-05-16 17:11:01 -04:00
#include <iterator>
2014-07-03 07:29:15 -04:00
#include <memory>
#include <vector>
2014-07-03 07:29:15 -04:00
2016-01-05 10:51:13 -05:00
namespace osrm
{
namespace contractor
{
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)
{
throw util::exception("Core factor must be between 0.0 to 1.0 (inclusive)" + SOURCE_REF);
}
2014-07-03 07:29:15 -04:00
TIMER_START(preparing);
util::Log() << "Reading node weights.";
std::vector<EdgeWeight> node_weights;
{
storage::io::FileReader reader(config.GetPath(".osrm.enw"),
2017-04-04 19:01:00 -04:00
storage::io::FileReader::VerifyFingerprint);
storage::serialization::read(reader, node_weights);
}
util::Log() << "Done reading node weights.";
util::Log() << "Loading edge-expanded graph representation";
2014-07-03 07:29:15 -04:00
std::vector<extractor::EdgeBasedEdge> edge_based_edge_list;
2015-07-04 11:37:24 -04:00
updater::Updater updater(config.updater_config);
EdgeID max_edge_id = updater.LoadAndUpdateEdgeExpandedGraph(edge_based_edge_list, node_weights);
// Contracting the edge-expanded graph
2014-07-03 07:29:15 -04:00
TIMER_START(contraction);
std::vector<bool> is_core_node;
std::vector<float> node_levels;
if (config.use_cached_priority)
{
files::readLevels(config.GetPath(".osrm.level"), node_levels);
}
2016-01-05 10:51:13 -05:00
util::DeallocatingVector<QueryEdge> contracted_edge_list;
{ // own scope to not keep the contractor around
auto contractor_graph = toContractorGraph(max_edge_id+1, std::move(edge_based_edge_list));
std::tie(node_levels, is_core_node) = contractGraph(contractor_graph,
std::move(node_levels),
std::move(node_weights),
config.core_factor);
2017-06-15 10:52:14 -04:00
contracted_edge_list = toEdges<QueryEdge>(std::move(contractor_graph));
}
2014-07-03 07:29:15 -04:00
TIMER_STOP(contraction);
util::Log() << "Contraction took " << TIMER_SEC(contraction) << " sec";
2014-07-03 07:29:15 -04:00
{
2017-06-15 10:52:14 -04:00
RangebasedCRC32 crc32_calculator;
const unsigned checksum = crc32_calculator(contracted_edge_list);
2017-04-13 05:45:35 -04:00
files::writeGraph(config.GetPath(".osrm.hsgr"),
2017-06-15 10:52:14 -04:00
checksum,
QueryGraph{max_edge_id + 1, std::move(contracted_edge_list)});
}
files::writeCoreMarker(config.GetPath(".osrm.core"), is_core_node);
2017-06-15 10:52:14 -04:00
if (!config.use_cached_priority)
{
files::writeLevels(config.GetPath(".osrm.level"), node_levels);
}
2015-04-23 12:53:36 -04:00
TIMER_STOP(preparing);
util::Log() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds";
2015-04-23 12:53:36 -04:00
util::Log() << "finished preprocessing";
2015-04-23 12:53:36 -04:00
return 0;
}
} // namespace contractor
} // namespace osrm