Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor nodes file #4036

Merged
merged 9 commits into from
May 17, 2017
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- Changes from 5.7
- Features
- Added conditional restriction support with `parse-conditional-restrictions=true|false` to osrm-extract. This option saves conditional turn restrictions to the .restrictions file for parsing by contract later. Added `parse-conditionals-from-now=utc time stamp` and `--time-zone-file=/path/to/file` to osrm-contract
- Files
- .osrm.nodes file was renamed to .nbg_nodes and .ebg_nodes was added

# 5.7.0
- Changes from 5.6
Expand Down
5 changes: 1 addition & 4 deletions include/contractor/contractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "contractor/contractor_config.hpp"
#include "contractor/query_edge.hpp"
#include "extractor/edge_based_edge.hpp"
#include "extractor/edge_based_node.hpp"
#include "extractor/edge_based_node_segment.hpp"
#include "util/deallocating_vector.hpp"
#include "util/typedefs.hpp"

Expand Down Expand Up @@ -68,9 +68,6 @@ class Contractor
void WriteCoreNodeMarker(std::vector<bool> &&is_core_node) const;
void WriteContractedGraph(unsigned number_of_edge_based_nodes,
util::DeallocatingVector<QueryEdge> contracted_edge_list);
void FindComponents(unsigned max_edge_id,
const util::DeallocatingVector<extractor::EdgeBasedEdge> &edges,
std::vector<extractor::EdgeBasedNode> &nodes) const;

private:
ContractorConfig config;
Expand Down
15 changes: 10 additions & 5 deletions include/engine/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ class BaseAPI
{
if (parameters.generate_hints)
{
return json::makeWaypoint(phantom.location,
facade.GetNameForID(phantom.name_id).to_string(),
Hint{phantom, facade.GetCheckSum()});
// TODO: check forward/reverse
return json::makeWaypoint(
phantom.location,
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string(),
Hint{phantom, facade.GetCheckSum()});
}
else
{
return json::makeWaypoint(phantom.location,
facade.GetNameForID(phantom.name_id).to_string());
// TODO: check forward/reverse
return json::makeWaypoint(
phantom.location,
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
.to_string());
}
}

Expand Down
16 changes: 14 additions & 2 deletions include/engine/datafacade/contiguous_internalmem_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,20 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
util::vector_view<NameID> name_ids(name_id_list_ptr,
layout.num_entries[storage::DataLayout::NAME_ID_LIST]);

const auto component_id_list_ptr =
layout.GetBlockPtr<ComponentID>(memory_ptr, storage::DataLayout::COMPONENT_ID_LIST);
util::vector_view<ComponentID> component_ids(
component_id_list_ptr, layout.num_entries[storage::DataLayout::COMPONENT_ID_LIST]);

const auto travel_mode_list_ptr = layout.GetBlockPtr<extractor::TravelMode>(
memory_ptr, storage::DataLayout::TRAVEL_MODE_LIST);
util::vector_view<extractor::TravelMode> travel_modes(
travel_mode_list_ptr, layout.num_entries[storage::DataLayout::TRAVEL_MODE_LIST]);

edge_based_node_data = extractor::EdgeBasedNodeDataView(
std::move(geometry_ids), std::move(name_ids), std::move(travel_modes));
edge_based_node_data = extractor::EdgeBasedNodeDataView(std::move(geometry_ids),
std::move(name_ids),
std::move(component_ids),
std::move(travel_modes));
}

void InitializeEdgeInformationPointers(storage::DataLayout &layout, char *memory_ptr)
Expand Down Expand Up @@ -742,6 +749,11 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
return edge_based_node_data.GetGeometryID(id);
}

ComponentID GetComponentID(const NodeID id) const
{
return edge_based_node_data.GetComponentID(id);
}

extractor::TravelMode GetTravelMode(const NodeID id) const override final
{
return edge_based_node_data.GetTravelMode(id);
Expand Down
6 changes: 4 additions & 2 deletions include/engine/datafacade/datafacade_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Exposes all data access interfaces to the algorithms via base class ptr

#include "contractor/query_edge.hpp"
#include "extractor/edge_based_node.hpp"
#include "extractor/edge_based_node_segment.hpp"
#include "extractor/external_memory_node.hpp"
#include "extractor/guidance/turn_instruction.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
Expand Down Expand Up @@ -40,7 +40,7 @@ using StringView = util::StringView;
class BaseDataFacade
{
public:
using RTreeLeaf = extractor::EdgeBasedNode;
using RTreeLeaf = extractor::EdgeBasedNodeSegment;
BaseDataFacade() {}
virtual ~BaseDataFacade() {}

Expand All @@ -53,6 +53,8 @@ class BaseDataFacade

virtual GeometryID GetGeometryIndex(const NodeID id) const = 0;

virtual ComponentID GetComponentID(const NodeID id) const = 0;

virtual std::vector<NodeID> GetUncompressedForwardGeometry(const EdgeID id) const = 0;

virtual std::vector<NodeID> GetUncompressedReverseGeometry(const EdgeID id) const = 0;
Expand Down
75 changes: 48 additions & 27 deletions include/engine/geospatial_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto results = rtree.Nearest(
input_coordinate,
[this, &has_big_component, &has_small_component](const CandidateSegment &segment) {
auto use_segment = (!has_small_component ||
(!has_big_component && !segment.data.component.is_tiny));
auto use_segment =
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment);
const auto valid_edges = HasValidEdge(segment);

if (valid_edges.first || valid_edges.second)
{
has_big_component = has_big_component || !segment.data.component.is_tiny;
has_small_component = has_small_component || segment.data.component.is_tiny;
has_big_component = has_big_component || !IsTinyComponent(segment);
has_small_component = has_small_component || IsTinyComponent(segment);
}
use_directions = boolPairAnd(use_directions, valid_edges);
return use_directions;
Expand Down Expand Up @@ -215,8 +215,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto results = rtree.Nearest(
input_coordinate,
[this, &has_big_component, &has_small_component](const CandidateSegment &segment) {
auto use_segment = (!has_small_component ||
(!has_big_component && !segment.data.component.is_tiny));
auto use_segment =
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment);
if (!use_directions.first && !use_directions.second)
return use_directions;
Expand All @@ -225,8 +225,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
if (valid_edges.first || valid_edges.second)
{

has_big_component = has_big_component || !segment.data.component.is_tiny;
has_small_component = has_small_component || segment.data.component.is_tiny;
has_big_component = has_big_component || !IsTinyComponent(segment);
has_small_component = has_small_component || IsTinyComponent(segment);
}

use_directions = boolPairAnd(use_directions, valid_edges);
Expand Down Expand Up @@ -257,8 +257,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
input_coordinate,
[this, bearing, bearing_range, &has_big_component, &has_small_component](
const CandidateSegment &segment) {
auto use_segment = (!has_small_component ||
(!has_big_component && !segment.data.component.is_tiny));
auto use_segment =
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment);
use_directions = boolPairAnd(use_directions, HasValidEdge(segment));

Expand All @@ -269,8 +269,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
HasValidEdge(segment));
if (use_directions.first || use_directions.second)
{
has_big_component = has_big_component || !segment.data.component.is_tiny;
has_small_component = has_small_component || segment.data.component.is_tiny;
has_big_component = has_big_component || !IsTinyComponent(segment);
has_small_component = has_small_component || IsTinyComponent(segment);
}
}

Expand Down Expand Up @@ -304,8 +304,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
input_coordinate,
[this, bearing, bearing_range, &has_big_component, &has_small_component](
const CandidateSegment &segment) {
auto use_segment = (!has_small_component ||
(!has_big_component && !segment.data.component.is_tiny));
auto use_segment =
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment);
use_directions = boolPairAnd(use_directions, HasValidEdge(segment));

Expand All @@ -316,8 +316,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
HasValidEdge(segment));
if (use_directions.first || use_directions.second)
{
has_big_component = has_big_component || !segment.data.component.is_tiny;
has_small_component = has_small_component || segment.data.component.is_tiny;
has_big_component = has_big_component || !IsTinyComponent(segment);
has_small_component = has_small_component || IsTinyComponent(segment);
}
}

Expand Down Expand Up @@ -374,14 +374,21 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
EdgeDuration forward_duration_offset = 0, forward_duration = 0;
EdgeDuration reverse_duration_offset = 0, reverse_duration = 0;

BOOST_ASSERT(data.forward_segment_id.enabled || data.reverse_segment_id.enabled);
BOOST_ASSERT(!data.reverse_segment_id.enabled ||
datafacade.GetGeometryIndex(data.forward_segment_id.id).id ==
datafacade.GetGeometryIndex(data.reverse_segment_id.id).id);
const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id;
const auto component_id = datafacade.GetComponentID(data.forward_segment_id.id);

const std::vector<EdgeWeight> forward_weight_vector =
datafacade.GetUncompressedForwardWeights(data.packed_geometry_id);
datafacade.GetUncompressedForwardWeights(geometry_id);
const std::vector<EdgeWeight> reverse_weight_vector =
datafacade.GetUncompressedReverseWeights(data.packed_geometry_id);
datafacade.GetUncompressedReverseWeights(geometry_id);
const std::vector<EdgeWeight> forward_duration_vector =
datafacade.GetUncompressedForwardDurations(data.packed_geometry_id);
datafacade.GetUncompressedForwardDurations(geometry_id);
const std::vector<EdgeWeight> reverse_duration_vector =
datafacade.GetUncompressedReverseDurations(data.packed_geometry_id);
datafacade.GetUncompressedReverseDurations(geometry_id);

for (std::size_t i = 0; i < data.fwd_segment_position; i++)
{
Expand Down Expand Up @@ -431,6 +438,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
reverse_weight_vector.begin(), reverse_weight_vector.end() - data.fwd_segment_position);

auto transformed = PhantomNodeWithDistance{PhantomNode{data,
component_id,
forward_weight,
reverse_weight,
forward_weight_offset,
Expand Down Expand Up @@ -505,25 +513,38 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
bool forward_edge_valid = false;
bool reverse_edge_valid = false;

const auto &data = segment.data;
BOOST_ASSERT(data.forward_segment_id.enabled);
BOOST_ASSERT(data.forward_segment_id.id != SPECIAL_NODEID);
const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id;

const std::vector<EdgeWeight> forward_weight_vector =
datafacade.GetUncompressedForwardWeights(segment.data.packed_geometry_id);
datafacade.GetUncompressedForwardWeights(geometry_id);

if (forward_weight_vector[segment.data.fwd_segment_position] != INVALID_EDGE_WEIGHT)
if (forward_weight_vector[data.fwd_segment_position] != INVALID_EDGE_WEIGHT)
{
forward_edge_valid = segment.data.forward_segment_id.enabled;
forward_edge_valid = data.forward_segment_id.enabled;
}

const std::vector<EdgeWeight> reverse_weight_vector =
datafacade.GetUncompressedReverseWeights(segment.data.packed_geometry_id);
if (reverse_weight_vector[reverse_weight_vector.size() - segment.data.fwd_segment_position -
1] != INVALID_EDGE_WEIGHT)
datafacade.GetUncompressedReverseWeights(geometry_id);
if (reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1] !=
INVALID_EDGE_WEIGHT)
{
reverse_edge_valid = segment.data.reverse_segment_id.enabled;
reverse_edge_valid = data.reverse_segment_id.enabled;
}

return std::make_pair(forward_edge_valid, reverse_edge_valid);
}

bool IsTinyComponent(const CandidateSegment &segment) const
{
const auto &data = segment.data;
BOOST_ASSERT(data.forward_segment_id.enabled);
BOOST_ASSERT(data.forward_segment_id.id != SPECIAL_NODEID);
return datafacade.GetComponentID(data.forward_segment_id.id).is_tiny;
}

const RTreeT &rtree;
const CoordinateList &coordinates;
DataFacadeT &datafacade;
Expand Down
12 changes: 9 additions & 3 deletions include/engine/guidance/assemble_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
// source node rev: 2 0 <- 1 <- 2
const auto source_segment_start_coordinate =
source_node.fwd_segment_position + (reversed_source ? 1 : 0);
const auto source_node_id =
reversed_source ? source_node.reverse_segment_id.id : source_node.forward_segment_id.id;
const auto source_gemetry_id = facade.GetGeometryIndex(source_node_id).id;
const std::vector<NodeID> source_geometry =
facade.GetUncompressedForwardGeometry(source_node.packed_geometry_id);
facade.GetUncompressedForwardGeometry(source_gemetry_id);
geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(source_geometry[source_segment_start_coordinate]));

Expand Down Expand Up @@ -89,8 +92,11 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
// segment leading to the target node
geometry.segment_distances.push_back(cumulative_distance);

const auto target_node_id =
reversed_target ? target_node.reverse_segment_id.id : target_node.forward_segment_id.id;
const auto target_gemetry_id = facade.GetGeometryIndex(target_node_id).id;
const std::vector<DatasourceID> forward_datasources =
facade.GetUncompressedForwardDatasources(target_node.packed_geometry_id);
facade.GetUncompressedForwardDatasources(target_gemetry_id);

// FIXME if source and target phantoms are on the same segment then duration and weight
// will be from one projected point till end of segment
Expand All @@ -113,7 +119,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
const auto target_segment_end_coordinate =
target_node.fwd_segment_position + (reversed_target ? 0 : 1);
const std::vector<NodeID> target_geometry =
facade.GetUncompressedForwardGeometry(target_node.packed_geometry_id);
facade.GetUncompressedForwardGeometry(target_gemetry_id);
geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(target_geometry[target_segment_end_coordinate]));

Expand Down
9 changes: 6 additions & 3 deletions include/engine/guidance/assemble_leg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ struct NamedSegment

template <std::size_t SegmentNumber>

std::array<std::uint32_t, SegmentNumber> summarizeRoute(const std::vector<PathData> &route_data,
std::array<std::uint32_t, SegmentNumber> summarizeRoute(const datafacade::BaseDataFacade &facade,
const std::vector<PathData> &route_data,
const PhantomNode &target_node,
const bool target_traversed_in_reverse)
{
Expand Down Expand Up @@ -80,8 +81,10 @@ std::array<std::uint32_t, SegmentNumber> summarizeRoute(const std::vector<PathDa
});
const auto target_duration =
target_traversed_in_reverse ? target_node.reverse_duration : target_node.forward_duration;
const auto target_node_id = target_traversed_in_reverse ? target_node.reverse_segment_id.id
: target_node.forward_segment_id.id;
if (target_duration > 1)
segments.push_back({target_duration, index++, target_node.name_id});
segments.push_back({target_duration, index++, facade.GetNameIndex(target_node_id)});
// this makes sure that the segment with the lowest position comes first
std::sort(
segments.begin(), segments.end(), [](const NamedSegment &lhs, const NamedSegment &rhs) {
Expand Down Expand Up @@ -183,7 +186,7 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
if (needs_summary)
{
auto summary_array = detail::summarizeRoute<detail::MAX_USED_SEGMENTS>(
route_data, target_node, target_traversed_in_reverse);
facade, route_data, target_node, target_traversed_in_reverse);

BOOST_ASSERT(detail::MAX_USED_SEGMENTS > 0);
BOOST_ASSERT(summary_array.begin() != summary_array.end());
Expand Down
Loading