Skip to content

Commit 06660e7

Browse files
WIP
1 parent c06b46d commit 06660e7

4 files changed

Lines changed: 28 additions & 27 deletions

File tree

include/contractor/graph_contractor.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ namespace osrm::contractor
1414
using GraphAndFilter = std::tuple<QueryGraph, std::vector<std::vector<bool>>>;
1515

1616
GraphAndFilter contractFullGraph(ContractorGraph contractor_graph,
17-
std::vector<bool> one_way_streets);
17+
const std::vector<bool> &one_way_streets);
1818

1919
GraphAndFilter contractExcludableGraph(ContractorGraph contractor_graph_,
20-
std::vector<bool> one_way_streets,
20+
const std::vector<bool> &one_way_streets,
2121
const std::vector<std::vector<bool>> &filters);
2222

2323
std::vector<bool> contractGraph(ContractorGraph &graph,
2424
std::vector<bool> node_is_uncontracted,
2525
std::vector<bool> node_is_contractable,
26-
std::vector<bool> one_way_streets,
26+
const std::vector<bool> &one_way_streets,
2727
double core_factor = 1.0);
2828

2929
// Overload for contracting all nodes
30-
inline auto
31-
contractGraph(ContractorGraph &graph, std::vector<bool> one_way_streets, double core_factor = 1.0)
30+
inline auto contractGraph(ContractorGraph &graph,
31+
const std::vector<bool> &one_way_streets,
32+
double core_factor = 1.0)
3233
{
33-
return contractGraph(graph, {}, {}, std::move(one_way_streets), core_factor);
34+
return contractGraph(graph, {}, {}, one_way_streets, core_factor);
3435
}
3536

3637
// Overload no contracted nodes
3738
inline auto contractGraph(ContractorGraph &graph,
3839
std::vector<bool> node_is_contractable,
39-
std::vector<bool> one_way_streets,
40+
const std::vector<bool> &one_way_streets,
4041
double core_factor = 1.0)
4142
{
42-
return contractGraph(
43-
graph, {}, std::move(node_is_contractable), std::move(one_way_streets), core_factor);
43+
return contractGraph(graph, {}, std::move(node_is_contractable), one_way_streets, core_factor);
4444
}
4545

4646
} // namespace osrm::contractor

src/contractor/contractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int Contractor::Run()
8686
std::vector<std::vector<bool>> cores;
8787
std::tie(query_graph, edge_filters) =
8888
contractExcludableGraph(toContractorGraph(number_of_edge_based_nodes, edge_based_edge_list),
89-
std::move(one_way_streets),
89+
one_way_streets,
9090
node_filters);
9191
TIMER_STOP(contraction);
9292
util::Log() << "Contracted graph has " << query_graph.GetNumberOfEdges() << " edges.";

src/contractor/graph_contractor.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ struct ContractorNodeData
100100
ContractorNodeData(std::size_t number_of_nodes,
101101
std::vector<bool> uncontracted_nodes_,
102102
std::vector<bool> contractible_,
103-
std::vector<bool> one_way_streets)
103+
const std::vector<bool> &one_way_streets_)
104104
: is_core(std::move(uncontracted_nodes_)), is_contractible(std::move(contractible_)),
105-
one_way_streets(std::move(one_way_streets)), priorities(number_of_nodes),
106-
depths(number_of_nodes, 0)
105+
one_way_streets{one_way_streets_}, priorities(number_of_nodes), depths(number_of_nodes, 0)
107106
{
108107
if (is_contractible.empty())
109108
{
@@ -113,6 +112,10 @@ struct ContractorNodeData
113112
{
114113
is_core.resize(number_of_nodes, true);
115114
}
115+
if (one_way_streets.size() < number_of_nodes)
116+
{
117+
one_way_streets.resize(number_of_nodes, false);
118+
}
116119
}
117120

118121
/** All these are keyed by NodeID */
@@ -550,7 +553,7 @@ bool IsNodeIndependent(const ContractorGraph &graph,
550553
std::vector<bool> contractGraph(ContractorGraph &graph,
551554
std::vector<bool> node_is_uncontracted_,
552555
std::vector<bool> node_is_contractible_,
553-
std::vector<bool> one_way_streets,
556+
const std::vector<bool> &one_way_streets,
554557
double core_factor)
555558
{
556559
/** A heap kept in thread-local storage to avoid multiple recreations of it. */
@@ -563,12 +566,10 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
563566

564567
const unsigned int number_of_nodes = graph.GetNumberOfNodes();
565568

566-
BOOST_ASSERT(one_way_streets.size() >= number_of_nodes);
567-
568569
ContractorNodeData node_data{number_of_nodes,
569570
std::move(node_is_uncontracted_),
570571
std::move(node_is_contractible_),
571-
std::move(one_way_streets)};
572+
one_way_streets};
572573

573574
TIMER_DECLARE(init_priorities);
574575
TIMER_DECLARE(contract);
@@ -715,10 +716,10 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
715716
using GraphAndFilter = std::tuple<QueryGraph, std::vector<std::vector<bool>>>;
716717

717718
GraphAndFilter contractFullGraph(ContractorGraph contractor_graph,
718-
std::vector<bool> one_way_streets)
719+
const std::vector<bool> &one_way_streets)
719720
{
720721
auto num_nodes = contractor_graph.GetNumberOfNodes();
721-
contractGraph(contractor_graph, std::move(one_way_streets));
722+
contractGraph(contractor_graph, one_way_streets);
722723

723724
auto edges = toEdges<QueryEdge>(std::move(contractor_graph));
724725
std::vector<bool> edge_filter(edges.size(), true);
@@ -727,14 +728,14 @@ GraphAndFilter contractFullGraph(ContractorGraph contractor_graph,
727728
}
728729

729730
GraphAndFilter contractExcludableGraph(ContractorGraph contractor_graph_,
730-
std::vector<bool> one_way_streets,
731+
const std::vector<bool> &one_way_streets,
731732
const std::vector<std::vector<bool>> &filters)
732733
{
733734
if (filters.size() == 1)
734735
{
735736
if (std::all_of(filters.front().begin(), filters.front().end(), [](auto v) { return v; }))
736737
{
737-
return contractFullGraph(std::move(contractor_graph_), std::move(one_way_streets));
738+
return contractFullGraph(std::move(contractor_graph_), one_way_streets);
738739
}
739740
}
740741

unit_tests/contractor/graph_contractor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE(contract_graph)
2828
const ContractorGraph g = makeGraph({{0, 1, 1}}); // start, target, weight
2929

3030
auto query_graph = g;
31-
contractGraph(query_graph, {false});
31+
contractGraph(query_graph, {});
3232

3333
HAS(0, 1)
3434
NOT(1, 0)
@@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(contract_graph)
4545
{1, 2, 1}});
4646

4747
auto query_graph = g;
48-
contractGraph(query_graph, {false, false, false});
48+
contractGraph(query_graph, {});
4949

5050
HAS(0, 1)
5151
HAS(2, 1)
@@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(contract_graph)
7070
{0, 2, 1}});
7171

7272
auto query_graph = g;
73-
contractGraph(query_graph, {false, false, false});
73+
contractGraph(query_graph, {});
7474

7575
HAS(0, 1)
7676
HAS(1, 2)
@@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(contract_graph)
9999
{3, 0, 1}});
100100

101101
auto query_graph = g;
102-
contractGraph(query_graph, {false, false, false, false});
102+
contractGraph(query_graph, {});
103103

104104
HAS(0, 1)
105105
NOT(0, 2)
@@ -140,8 +140,8 @@ BOOST_AUTO_TEST_CASE(contract_excludable_graph)
140140
{2, 3, 1},
141141
{3, 0, 1}});
142142

143-
auto [query_graph, ignore] = contractExcludableGraph(
144-
g, {false, false, false, false}, {{true, true, true, true}, {false, true, true, true}});
143+
auto [query_graph, ignore] =
144+
contractExcludableGraph(g, {}, {{true, true, true, true}, {false, true, true, true}});
145145

146146
NOT(0, 1)
147147
NOT(0, 2)

0 commit comments

Comments
 (0)