Skip to content

Commit

Permalink
Project-OSRM#5325 Make osm_ids optional after the revew
Browse files Browse the repository at this point in the history
  • Loading branch information
nnseva committed Mar 17, 2021
1 parent 848e962 commit 129d954
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -ggdb")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb")
endif()


Expand Down
6 changes: 4 additions & 2 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ class RouteAPI : public BaseAPI
}
}
std::vector<int64_t> ways;
if (requested_annotations & RouteParameters::AnnotationsType::Ways)
if (requested_annotations & RouteParameters::AnnotationsType::Ways &&
leg_geometry.osm_way_ids.size())
{
ways.reserve(leg_geometry.osm_way_ids.size());
for (const auto way_id : leg_geometry.osm_way_ids)
Expand Down Expand Up @@ -843,7 +844,8 @@ class RouteAPI : public BaseAPI
}
annotation.values["nodes"] = std::move(nodes);
}
if (requested_annotations & RouteParameters::AnnotationsType::Ways)
if (requested_annotations & RouteParameters::AnnotationsType::Ways &&
leg_geometry.osm_way_ids.size())
{
util::json::Array ways;
ways.values.reserve(leg_geometry.osm_way_ids.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
{
return segment_data.GetReverseOSMWayIDs(id);
}
bool GetUncompressedWayIDsSkipped() const override final
{
return segment_data.GetOSMWaysSkipped();
}

DurationForwardRange GetUncompressedForwardDurations(const EdgeID id) const override final
{
Expand Down
1 change: 1 addition & 0 deletions include/engine/datafacade/datafacade_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class BaseDataFacade

virtual OSMWayForwardRange GetUncompressedForwardWayIDs(const EdgeID id) const = 0;
virtual OSMWayReverseRange GetUncompressedReverseWayIDs(const EdgeID id) const = 0;
virtual bool GetUncompressedWayIDsSkipped() const = 0;

virtual NodeForwardRange GetUncompressedForwardGeometry(const EdgeID id) const = 0;
virtual NodeReverseRange GetUncompressedReverseGeometry(const EdgeID id) const = 0;
Expand Down
25 changes: 14 additions & 11 deletions include/engine/guidance/assemble_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
path_point.datasource_id});
geometry.locations.push_back(std::move(coordinate));
geometry.osm_node_ids.push_back(osm_node_id);
geometry.osm_way_ids.push_back(path_point.osm_way_id);
if (!facade.GetUncompressedWayIDsSkipped())
geometry.osm_way_ids.push_back(path_point.osm_way_id);
}
}
current_distance =
Expand Down Expand Up @@ -161,18 +162,20 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
const auto target_geometry = facade.GetUncompressedForwardGeometry(target_geometry_id);
geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(target_geometry(target_segment_end_coordinate)));
if (reversed_target)
if (!facade.GetUncompressedWayIDsSkipped())
{
const auto target_osm_way_ids = facade.GetUncompressedReverseWayIDs(target_geometry_id);
geometry.osm_way_ids.push_back(
target_osm_way_ids(target_osm_way_ids.size() - target_node.fwd_segment_position - 1));
}
else
{
const auto target_osm_way_ids = facade.GetUncompressedForwardWayIDs(target_geometry_id);
geometry.osm_way_ids.push_back(target_osm_way_ids(target_node.fwd_segment_position));
if (reversed_target)
{
const auto target_osm_way_ids = facade.GetUncompressedReverseWayIDs(target_geometry_id);
geometry.osm_way_ids.push_back(target_osm_way_ids(
target_osm_way_ids.size() - target_node.fwd_segment_position - 1));
}
else
{
const auto target_osm_way_ids = facade.GetUncompressedForwardWayIDs(target_geometry_id);
geometry.osm_way_ids.push_back(target_osm_way_ids(target_node.fwd_segment_position));
}
}

BOOST_ASSERT(geometry.segment_distances.size() == geometry.segment_offsets.size() - 1);
BOOST_ASSERT(geometry.locations.size() > geometry.segment_distances.size());
BOOST_ASSERT(geometry.annotations.size() == geometry.locations.size() - 1);
Expand Down
6 changes: 3 additions & 3 deletions include/engine/routing_algorithms/routing_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void annotatePath(const FacadeT &facade,
BOOST_ASSERT(datasource_vector.size() > 0);
BOOST_ASSERT(weight_vector.size() + 1 == id_vector.size());
BOOST_ASSERT(duration_vector.size() + 1 == id_vector.size());
BOOST_ASSERT(osm_way_id_vector.size() + 1 == id_vector.size());
BOOST_ASSERT(!osm_way_id_vector.size() || osm_way_id_vector.size() + 1 == id_vector.size());

const bool is_first_segment = unpacked_path.empty();

Expand All @@ -219,7 +219,7 @@ void annotatePath(const FacadeT &facade,
{
unpacked_path.push_back(
PathData{*node_from,
osm_way_id_vector[segment_idx],
osm_way_id_vector.size() ? osm_way_id_vector[segment_idx] : 0,
id_vector[segment_idx + 1],
name_index,
is_segregated,
Expand Down Expand Up @@ -295,7 +295,7 @@ void annotatePath(const FacadeT &facade,
BOOST_ASSERT(facade.GetTravelMode(target_node_id) > 0);
unpacked_path.push_back(
PathData{target_node_id,
osm_way_id_vector[segment_idx],
osm_way_id_vector.size() ? osm_way_id_vector[segment_idx] : 0,
id_vector[start_index < end_index ? segment_idx + 1 : segment_idx - 1],
facade.GetNameIndex(target_node_id),
facade.IsSegregated(target_node_id),
Expand Down
4 changes: 3 additions & 1 deletion include/extractor/extractor_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ struct ExtractorConfig final : storage::IOConfig
".osrm.cnbg",
".osrm.cnbg_to_ebg",
".osrm.maneuver_overrides"}),
requested_num_threads(0), parse_conditionals(false), use_locations_cache(true)
requested_num_threads(0), parse_conditionals(false), use_locations_cache(true),
skip_osm_ways(false)
{
}

Expand All @@ -92,6 +93,7 @@ struct ExtractorConfig final : storage::IOConfig
bool use_metadata;
bool parse_conditionals;
bool use_locations_cache;
bool skip_osm_ways;
};
} // namespace extractor
} // namespace osrm
Expand Down
6 changes: 4 additions & 2 deletions include/extractor/files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,17 @@ inline void readSegmentData(const boost::filesystem::path &path, SegmentDataT &s

// writes .osrm.geometry
template <typename SegmentDataT>
inline void writeSegmentData(const boost::filesystem::path &path, const SegmentDataT &segment_data)
inline void writeSegmentData(const boost::filesystem::path &path,
bool skip_osm_ways,
const SegmentDataT &segment_data)
{
static_assert(std::is_same<SegmentDataContainer, SegmentDataT>::value ||
std::is_same<SegmentDataView, SegmentDataT>::value,
"");
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
storage::tar::FileWriter writer{path, fingerprint};

serialization::write(writer, "/common/segment_data", segment_data);
serialization::write(writer, "/common/segment_data", skip_osm_ways, segment_data);
}

// reads .osrm.ebg_nodes
Expand Down
5 changes: 5 additions & 0 deletions include/extractor/segment_data_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ inline void read(storage::tar::FileReader &reader,
template <storage::Ownership Ownership>
inline void write(storage::tar::FileWriter &writer,
const std::string &name,
const bool skip_osm_ways,
const detail::SegmentDataContainerImpl<Ownership> &segment_data);
} // namespace serialization

Expand Down Expand Up @@ -171,6 +172,8 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl

auto GetForwardOSMWayIDs(const DirectionalGeometryID id) const
{
if (GetOSMWaysSkipped())
return boost::make_iterator_range(osm_ways.cend(), osm_ways.cend());
const auto begin = osm_ways.cbegin() + index[id];
const auto end = osm_ways.cbegin() + index[id + 1] - 1;

Expand Down Expand Up @@ -233,6 +236,7 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl

auto GetNumberOfGeometries() const { return index.size() - 1; }
auto GetNumberOfSegments() const { return fwd_weights.size(); }
auto GetOSMWaysSkipped() const { return osm_ways.size() == 0; }

friend void
serialization::read<Ownership>(storage::tar::FileReader &reader,
Expand All @@ -241,6 +245,7 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
friend void serialization::write<Ownership>(
storage::tar::FileWriter &writer,
const std::string &name,
const bool skip_osm_ways,
const detail::SegmentDataContainerImpl<Ownership> &segment_data);

private:
Expand Down
9 changes: 8 additions & 1 deletion include/extractor/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ inline void read(storage::tar::FileReader &reader,
template <storage::Ownership Ownership>
inline void write(storage::tar::FileWriter &writer,
const std::string &name,
const bool skip_osm_ways,
const detail::SegmentDataContainerImpl<Ownership> &segment_data)
{
storage::serialization::write(writer, name + "/index", segment_data.index);
storage::serialization::write(writer, name + "/nodes", segment_data.nodes);
storage::serialization::write(writer, name + "/osm_ways", segment_data.osm_ways);
if (!skip_osm_ways)
storage::serialization::write(writer, name + "/osm_ways", segment_data.osm_ways);
else
storage::serialization::write(
writer,
name + "/osm_ways",
osrm::util::ViewOrVector<OSMWayIDDir, osrm::storage::Ownership::Container>());
util::serialization::write(writer, name + "/forward_weights", segment_data.fwd_weights);
util::serialization::write(writer, name + "/reverse_weights", segment_data.rev_weights);
util::serialization::write(writer, name + "/forward_durations", segment_data.fwd_durations);
Expand Down
1 change: 1 addition & 0 deletions src/extractor/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
// output the geometry of the node-based graph, needs to be done after the last usage, since it
// destroys internal containers
files::writeSegmentData(config.GetPath(".osrm.geometry"),
config.skip_osm_ways,
*node_based_graph_factory.GetCompressedEdges().ToSegmentData());

util::Log() << "Saving edge-based node weights to file.";
Expand Down
7 changes: 6 additions & 1 deletion src/tools/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ return_code parseArguments(int argc,
boost::program_options::bool_switch(&extractor_config.use_locations_cache)
->implicit_value(false)
->default_value(true),
"Use internal nodes locations cache for location-dependent data lookups");
"Use internal nodes locations cache for location-dependent data lookups")(
"skip-osm-ways",
boost::program_options::bool_switch(&extractor_config.skip_osm_ways)
->implicit_value(true)
->default_value(false),
"Skip OSM Way IDs in annotations");

bool dummy;
// hidden options, will be allowed on command line, but will not be
Expand Down
3 changes: 2 additions & 1 deletion src/updater/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &e
coordinates,
osm_node_ids);
// Now save out the updated compressed geometries
extractor::files::writeSegmentData(config.GetPath(".osrm.geometry"), segment_data);
extractor::files::writeSegmentData(
config.GetPath(".osrm.geometry"), segment_data.GetOSMWaysSkipped(), segment_data);
TIMER_STOP(segment);
util::Log() << "Updating segment data took " << TIMER_MSEC(segment) << "ms.";
}
Expand Down
1 change: 1 addition & 0 deletions unit_tests/engine/offline_facade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
{
return {};
}
bool GetUncompressedWayIDsSkipped() const override { return true; }

OSMWayReverseRange GetUncompressedReverseWayIDs(const EdgeID id) const override
{
Expand Down
1 change: 1 addition & 0 deletions unit_tests/mocks/mock_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
static extractor::SegmentDataView::SegmentOSMWayVector ways(data, 4);
return boost::make_iterator_range(ways.cbegin(), ways.cend());
}
bool GetUncompressedWayIDsSkipped() const override { return false; }
OSMWayReverseRange GetUncompressedReverseWayIDs(const EdgeID id) const override
{
return boost::adaptors::reverse(boost::adaptors::transform(GetUncompressedForwardWayIDs(id),
Expand Down

0 comments on commit 129d954

Please sign in to comment.