-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
contractor.cpp
125 lines (96 loc) · 3.98 KB
/
contractor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "contractor/contractor.hpp"
#include "contractor/contract_excludable_graph.hpp"
#include "contractor/contracted_edge_container.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"
#include "extractor/files.hpp"
#include "extractor/node_based_edge.hpp"
#include "storage/io.hpp"
#include "updater/updater.hpp"
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
#include "util/exclude_flag.hpp"
#include "util/filtered_graph.hpp"
#include "util/integer_range.hpp"
#include "util/log.hpp"
#include "util/static_graph.hpp"
#include "util/string_util.hpp"
#include "util/timing_util.hpp"
#include "util/typedefs.hpp"
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <fstream>
#include <iterator>
#include <memory>
#include <vector>
#include <boost/assert.hpp>
#include <tbb/global_control.h>
namespace osrm::contractor
{
int Contractor::Run()
{
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
config.requested_num_threads);
if (config.core_factor != 1.0)
{
util::Log(logWARNING)
<< "Using core factor is deprecated and will be ignored. Falling back to CH.";
config.core_factor = 1.0;
}
if (config.use_cached_priority)
{
util::Log(logWARNING) << "Using cached priorities is deprecated and they will be ignored.";
}
TIMER_START(preparing);
util::Log() << "Reading node weights.";
std::vector<EdgeWeight> node_weights;
extractor::files::readEdgeBasedNodeWeights(config.GetPath(".osrm.enw"), node_weights);
util::Log() << "Done reading node weights.";
util::Log() << "Loading edge-expanded graph representation";
std::vector<extractor::EdgeBasedEdge> edge_based_edge_list;
updater::Updater updater(config.updater_config);
std::uint32_t connectivity_checksum = 0;
EdgeID number_of_edge_based_nodes = updater.LoadAndUpdateEdgeExpandedGraph(
edge_based_edge_list, node_weights, connectivity_checksum);
// Convert node weights for oneway streets to INVALID_EDGE_WEIGHT
for (auto &weight : node_weights)
{
weight = (from_alias<EdgeWeight::value_type>(weight) & 0x80000000) ? INVALID_EDGE_WEIGHT
: weight;
}
// Contracting the edge-expanded graph
TIMER_START(contraction);
std::string metric_name;
std::vector<std::vector<bool>> node_filters;
{
extractor::EdgeBasedNodeDataContainer node_data;
extractor::files::readNodeData(config.GetPath(".osrm.ebg_nodes"), node_data);
extractor::ProfileProperties properties;
extractor::files::readProfileProperties(config.GetPath(".osrm.properties"), properties);
metric_name = properties.GetWeightName();
node_filters =
util::excludeFlagsToNodeFilter(number_of_edge_based_nodes, node_data, properties);
}
QueryGraph query_graph;
std::vector<std::vector<bool>> edge_filters;
std::vector<std::vector<bool>> cores;
std::tie(query_graph, edge_filters) = contractExcludableGraph(
toContractorGraph(number_of_edge_based_nodes, std::move(edge_based_edge_list)),
std::move(node_weights),
node_filters);
TIMER_STOP(contraction);
util::Log() << "Contracted graph has " << query_graph.GetNumberOfEdges() << " edges.";
util::Log() << "Contraction took " << TIMER_SEC(contraction) << " sec";
std::unordered_map<std::string, ContractedMetric> metrics = {
{metric_name, {std::move(query_graph), std::move(edge_filters)}}};
files::writeGraph(config.GetPath(".osrm.hsgr"), metrics, connectivity_checksum);
TIMER_STOP(preparing);
util::Log() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds";
util::Log() << "finished preprocessing";
return 0;
}
} // namespace osrm::contractor