2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/graph_compressor.hpp"
|
|
|
|
#include "extractor/compressed_edge_container.hpp"
|
2018-02-09 13:32:09 -05:00
|
|
|
#include "extractor/maneuver_override.hpp"
|
2017-07-06 11:09:24 -04:00
|
|
|
#include "extractor/restriction.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/node_based_graph.hpp"
|
|
|
|
#include "util/typedefs.hpp"
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2017-07-20 08:03:39 -04:00
|
|
|
#include "../unit_tests/mocks/mock_scripting_environment.hpp"
|
|
|
|
|
2016-05-27 15:05:04 -04:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2017-07-06 11:09:24 -04:00
|
|
|
#include <unordered_set>
|
|
|
|
#include <vector>
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(graph_compressor)
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
using namespace osrm;
|
|
|
|
using namespace osrm::extractor;
|
|
|
|
using InputEdge = util::NodeBasedDynamicGraph::InputEdge;
|
|
|
|
using Graph = util::NodeBasedDynamicGraph;
|
|
|
|
|
2016-11-24 07:29:17 -05:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
// creates a default edge of unit weight
|
|
|
|
inline InputEdge MakeUnitEdge(const NodeID from, const NodeID to)
|
|
|
|
{
|
2017-11-21 14:23:35 -05:00
|
|
|
return {from, // source
|
|
|
|
to, // target
|
2022-10-28 10:16:12 -04:00
|
|
|
EdgeWeight{1}, // weight
|
|
|
|
EdgeDuration{1}, // duration
|
|
|
|
EdgeDistance{1}, // distance
|
2017-09-25 09:37:11 -04:00
|
|
|
GeometryID{0, false}, // geometry_id
|
|
|
|
false, // reversed
|
|
|
|
NodeBasedEdgeClassification(), // default flags
|
|
|
|
0}; // AnnotationID
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compatible(Graph const &graph,
|
|
|
|
const std::vector<NodeBasedEdgeAnnotation> &node_data_container,
|
|
|
|
EdgeID const first,
|
|
|
|
EdgeID second)
|
|
|
|
{
|
|
|
|
auto const &first_flags = graph.GetEdgeData(first).flags;
|
|
|
|
auto const &second_flags = graph.GetEdgeData(second).flags;
|
|
|
|
if (!(first_flags == second_flags))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (graph.GetEdgeData(first).reversed != graph.GetEdgeData(second).reversed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto const &first_annotation = node_data_container[graph.GetEdgeData(first).annotation_data];
|
|
|
|
auto const &second_annotation = node_data_container[graph.GetEdgeData(second).annotation_data];
|
|
|
|
|
|
|
|
return first_annotation.CanCombineWith(second_annotation);
|
2016-11-24 07:29:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-06-28 09:30:40 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(long_road_test)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// 0---1---2---3---4
|
|
|
|
//
|
2016-03-23 11:46:05 -04:00
|
|
|
GraphCompressor compressor;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
std::unordered_set<NodeID> barrier_nodes;
|
2022-08-30 05:36:49 -04:00
|
|
|
TrafficSignals traffic_lights;
|
2017-07-06 11:09:24 -04:00
|
|
|
std::vector<TurnRestriction> restrictions;
|
2017-09-25 09:37:11 -04:00
|
|
|
std::vector<NodeBasedEdgeAnnotation> annotations(1);
|
2015-06-28 09:30:40 -04:00
|
|
|
CompressedEdgeContainer container;
|
2017-07-20 08:03:39 -04:00
|
|
|
test::MockScriptingEnvironment scripting_environment;
|
2018-02-09 13:32:09 -05:00
|
|
|
std::vector<UnresolvedManeuverOverride> maneuver_overrides;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2016-11-24 07:29:17 -05:00
|
|
|
std::vector<InputEdge> edges = {MakeUnitEdge(0, 1),
|
|
|
|
MakeUnitEdge(1, 0),
|
|
|
|
MakeUnitEdge(1, 2),
|
|
|
|
MakeUnitEdge(2, 1),
|
|
|
|
MakeUnitEdge(2, 3),
|
|
|
|
MakeUnitEdge(3, 2),
|
|
|
|
MakeUnitEdge(3, 4),
|
|
|
|
MakeUnitEdge(4, 3)};
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
Graph graph(5, edges);
|
2018-02-01 10:54:12 -05:00
|
|
|
BOOST_CHECK(compatible(graph, annotations, 0, 2));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 2, 4));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 4, 6));
|
2017-09-25 09:37:11 -04:00
|
|
|
|
2017-08-01 11:18:12 -04:00
|
|
|
compressor.Compress(barrier_nodes,
|
|
|
|
traffic_lights,
|
|
|
|
scripting_environment,
|
|
|
|
restrictions,
|
2018-02-09 13:32:09 -05:00
|
|
|
maneuver_overrides,
|
2017-08-01 11:18:12 -04:00
|
|
|
graph,
|
2017-09-25 09:37:11 -04:00
|
|
|
annotations,
|
2017-08-01 11:18:12 -04:00
|
|
|
container);
|
2015-06-28 09:30:40 -04:00
|
|
|
BOOST_CHECK_EQUAL(graph.FindEdge(0, 1), SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK_EQUAL(graph.FindEdge(1, 2), SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK_EQUAL(graph.FindEdge(2, 3), SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK_EQUAL(graph.FindEdge(3, 4), SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK(graph.FindEdge(0, 4) != SPECIAL_EDGEID);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(loop_test)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// 0---1---2
|
|
|
|
// | |
|
|
|
|
// 5---4---3
|
|
|
|
//
|
2016-03-23 11:46:05 -04:00
|
|
|
GraphCompressor compressor;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
std::unordered_set<NodeID> barrier_nodes;
|
2022-08-30 05:36:49 -04:00
|
|
|
TrafficSignals traffic_lights;
|
2017-07-06 11:09:24 -04:00
|
|
|
std::vector<TurnRestriction> restrictions;
|
2015-06-28 09:30:40 -04:00
|
|
|
CompressedEdgeContainer container;
|
2017-09-25 09:37:11 -04:00
|
|
|
std::vector<NodeBasedEdgeAnnotation> annotations(1);
|
2017-07-20 08:03:39 -04:00
|
|
|
test::MockScriptingEnvironment scripting_environment;
|
2018-02-09 13:32:09 -05:00
|
|
|
std::vector<UnresolvedManeuverOverride> maneuver_overrides;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2016-11-24 07:29:17 -05:00
|
|
|
std::vector<InputEdge> edges = {MakeUnitEdge(0, 1),
|
|
|
|
MakeUnitEdge(0, 5),
|
|
|
|
MakeUnitEdge(1, 0),
|
|
|
|
MakeUnitEdge(1, 2),
|
|
|
|
MakeUnitEdge(2, 1),
|
|
|
|
MakeUnitEdge(2, 3),
|
|
|
|
MakeUnitEdge(3, 2),
|
|
|
|
MakeUnitEdge(3, 4),
|
|
|
|
MakeUnitEdge(4, 3),
|
|
|
|
MakeUnitEdge(4, 5),
|
|
|
|
MakeUnitEdge(5, 0),
|
|
|
|
MakeUnitEdge(5, 4)};
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2017-09-25 09:37:11 -04:00
|
|
|
Graph graph(6, edges);
|
2018-02-01 10:54:12 -05:00
|
|
|
BOOST_CHECK(edges.size() == 12);
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 0, 1));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 1, 2));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 2, 3));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 3, 4));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 4, 5));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 5, 6));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 6, 7));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 7, 8));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 8, 9));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 9, 10));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 10, 11));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 11, 0));
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2017-08-01 11:18:12 -04:00
|
|
|
compressor.Compress(barrier_nodes,
|
|
|
|
traffic_lights,
|
|
|
|
scripting_environment,
|
|
|
|
restrictions,
|
2018-02-09 13:32:09 -05:00
|
|
|
maneuver_overrides,
|
2017-08-01 11:18:12 -04:00
|
|
|
graph,
|
2017-09-25 09:37:11 -04:00
|
|
|
annotations,
|
2017-08-01 11:18:12 -04:00
|
|
|
container);
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(graph.FindEdge(5, 0), SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK_EQUAL(graph.FindEdge(0, 1), SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK_EQUAL(graph.FindEdge(1, 2), SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK_EQUAL(graph.FindEdge(2, 3), SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK(graph.FindEdge(5, 3) != SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK(graph.FindEdge(3, 4) != SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK(graph.FindEdge(4, 5) != SPECIAL_EDGEID);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(t_intersection)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// 0---1---2
|
|
|
|
// |
|
|
|
|
// 3
|
|
|
|
//
|
2016-03-23 11:46:05 -04:00
|
|
|
GraphCompressor compressor;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
std::unordered_set<NodeID> barrier_nodes;
|
2022-08-30 05:36:49 -04:00
|
|
|
TrafficSignals traffic_lights;
|
2017-09-25 09:37:11 -04:00
|
|
|
std::vector<NodeBasedEdgeAnnotation> annotations(1);
|
2017-07-06 11:09:24 -04:00
|
|
|
std::vector<TurnRestriction> restrictions;
|
2015-06-28 09:30:40 -04:00
|
|
|
CompressedEdgeContainer container;
|
2017-07-20 08:03:39 -04:00
|
|
|
test::MockScriptingEnvironment scripting_environment;
|
2018-02-09 13:32:09 -05:00
|
|
|
std::vector<UnresolvedManeuverOverride> maneuver_overrides;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2016-11-24 07:29:17 -05:00
|
|
|
std::vector<InputEdge> edges = {MakeUnitEdge(0, 1),
|
|
|
|
MakeUnitEdge(1, 0),
|
|
|
|
MakeUnitEdge(1, 2),
|
|
|
|
MakeUnitEdge(1, 3),
|
|
|
|
MakeUnitEdge(2, 1),
|
|
|
|
MakeUnitEdge(3, 1)};
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
Graph graph(4, edges);
|
2018-02-01 10:54:12 -05:00
|
|
|
BOOST_CHECK(compatible(graph, annotations, 0, 1));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 1, 2));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 2, 3));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 3, 4));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 4, 5));
|
2017-09-25 09:37:11 -04:00
|
|
|
|
2017-08-01 11:18:12 -04:00
|
|
|
compressor.Compress(barrier_nodes,
|
|
|
|
traffic_lights,
|
|
|
|
scripting_environment,
|
|
|
|
restrictions,
|
2018-02-09 13:32:09 -05:00
|
|
|
maneuver_overrides,
|
2017-08-01 11:18:12 -04:00
|
|
|
graph,
|
2017-09-25 09:37:11 -04:00
|
|
|
annotations,
|
2017-08-01 11:18:12 -04:00
|
|
|
container);
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
BOOST_CHECK(graph.FindEdge(0, 1) != SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK(graph.FindEdge(1, 2) != SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK(graph.FindEdge(1, 3) != SPECIAL_EDGEID);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(street_name_changes)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// 0---1---2
|
|
|
|
//
|
2016-03-23 11:46:05 -04:00
|
|
|
GraphCompressor compressor;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
std::unordered_set<NodeID> barrier_nodes;
|
2022-08-30 05:36:49 -04:00
|
|
|
TrafficSignals traffic_lights;
|
2017-09-25 09:37:11 -04:00
|
|
|
std::vector<NodeBasedEdgeAnnotation> annotations(2);
|
2017-07-06 11:09:24 -04:00
|
|
|
std::vector<TurnRestriction> restrictions;
|
2015-06-28 09:30:40 -04:00
|
|
|
CompressedEdgeContainer container;
|
2017-07-20 08:03:39 -04:00
|
|
|
test::MockScriptingEnvironment scripting_environment;
|
2018-02-09 13:32:09 -05:00
|
|
|
std::vector<UnresolvedManeuverOverride> maneuver_overrides;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
std::vector<InputEdge> edges = {
|
2016-11-24 07:29:17 -05:00
|
|
|
MakeUnitEdge(0, 1), MakeUnitEdge(1, 0), MakeUnitEdge(1, 2), MakeUnitEdge(2, 1)};
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2017-09-25 09:37:11 -04:00
|
|
|
annotations[1].name_id = 1;
|
|
|
|
edges[2].data.annotation_data = edges[3].data.annotation_data = 1;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
Graph graph(5, edges);
|
2018-02-01 10:54:12 -05:00
|
|
|
BOOST_CHECK(compatible(graph, annotations, 0, 1));
|
|
|
|
BOOST_CHECK(compatible(graph, annotations, 2, 3));
|
2017-09-25 09:37:11 -04:00
|
|
|
|
2017-08-01 11:18:12 -04:00
|
|
|
compressor.Compress(barrier_nodes,
|
|
|
|
traffic_lights,
|
|
|
|
scripting_environment,
|
|
|
|
restrictions,
|
2018-02-09 13:32:09 -05:00
|
|
|
maneuver_overrides,
|
2017-08-01 11:18:12 -04:00
|
|
|
graph,
|
2017-09-25 09:37:11 -04:00
|
|
|
annotations,
|
2017-08-01 11:18:12 -04:00
|
|
|
container);
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
BOOST_CHECK(graph.FindEdge(0, 1) != SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK(graph.FindEdge(1, 2) != SPECIAL_EDGEID);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(direction_changes)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// 0-->1---2
|
|
|
|
//
|
2016-03-23 11:46:05 -04:00
|
|
|
GraphCompressor compressor;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
std::unordered_set<NodeID> barrier_nodes;
|
2022-08-30 05:36:49 -04:00
|
|
|
TrafficSignals traffic_lights;
|
2017-09-25 09:37:11 -04:00
|
|
|
std::vector<NodeBasedEdgeAnnotation> annotations(1);
|
2017-07-06 11:09:24 -04:00
|
|
|
std::vector<TurnRestriction> restrictions;
|
2015-06-28 09:30:40 -04:00
|
|
|
CompressedEdgeContainer container;
|
2017-07-20 08:03:39 -04:00
|
|
|
test::MockScriptingEnvironment scripting_environment;
|
2018-02-09 13:32:09 -05:00
|
|
|
std::vector<UnresolvedManeuverOverride> maneuver_overrides;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
std::vector<InputEdge> edges = {
|
2016-11-24 07:29:17 -05:00
|
|
|
MakeUnitEdge(0, 1), MakeUnitEdge(1, 0), MakeUnitEdge(1, 2), MakeUnitEdge(2, 1)};
|
|
|
|
// make first edge point forward
|
|
|
|
edges[1].data.reversed = true;
|
2015-06-28 09:30:40 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
Graph graph(5, edges);
|
2017-08-01 11:18:12 -04:00
|
|
|
compressor.Compress(barrier_nodes,
|
|
|
|
traffic_lights,
|
|
|
|
scripting_environment,
|
|
|
|
restrictions,
|
2018-02-09 13:32:09 -05:00
|
|
|
maneuver_overrides,
|
2017-08-01 11:18:12 -04:00
|
|
|
graph,
|
2017-09-25 09:37:11 -04:00
|
|
|
annotations,
|
2017-08-01 11:18:12 -04:00
|
|
|
container);
|
2015-06-28 09:30:40 -04:00
|
|
|
|
|
|
|
BOOST_CHECK(graph.FindEdge(0, 1) != SPECIAL_EDGEID);
|
|
|
|
BOOST_CHECK(graph.FindEdge(1, 2) != SPECIAL_EDGEID);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|