Remove weight and duration from customizer::EdgeBasedGraphEdgeData
This commit is contained in:
parent
fd9bebbfa7
commit
9695fa7941
@ -16,8 +16,10 @@ namespace osrm
|
|||||||
namespace customizer
|
namespace customizer
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO: Change to turn_id only
|
struct EdgeBasedGraphEdgeData
|
||||||
using EdgeBasedGraphEdgeData = partitioner::EdgeBasedGraphEdgeData;
|
{
|
||||||
|
NodeID turn_id; // ID of the edge based node (node based edge)
|
||||||
|
};
|
||||||
|
|
||||||
template <typename EdgeDataT, storage::Ownership Ownership> class MultiLevelGraph;
|
template <typename EdgeDataT, storage::Ownership Ownership> class MultiLevelGraph;
|
||||||
|
|
||||||
@ -39,8 +41,8 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
using SuperT = partitioner::MultiLevelGraph<EdgeDataT, Ownership>;
|
using SuperT = partitioner::MultiLevelGraph<EdgeDataT, Ownership>;
|
||||||
using SuperC = partitioner::MultiLevelGraph<partitioner::EdgeBasedGraphEdgeData,
|
using PartitionerGraphT = partitioner::MultiLevelGraph<partitioner::EdgeBasedGraphEdgeData,
|
||||||
storage::Ownership::Container>;
|
storage::Ownership::Container>;
|
||||||
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
|
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -50,34 +52,49 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership
|
|||||||
MultiLevelGraph &operator=(MultiLevelGraph &&) = default;
|
MultiLevelGraph &operator=(MultiLevelGraph &&) = default;
|
||||||
MultiLevelGraph &operator=(const MultiLevelGraph &) = default;
|
MultiLevelGraph &operator=(const MultiLevelGraph &) = default;
|
||||||
|
|
||||||
// TODO: add constructor for EdgeBasedGraphEdgeData
|
MultiLevelGraph(PartitionerGraphT &&graph,
|
||||||
MultiLevelGraph(SuperC &&graph,
|
|
||||||
Vector<EdgeWeight> node_weights_,
|
Vector<EdgeWeight> node_weights_,
|
||||||
Vector<EdgeDuration> node_durations_)
|
Vector<EdgeDuration> node_durations_)
|
||||||
: node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_))
|
: node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_))
|
||||||
{
|
{
|
||||||
|
util::ViewOrVector<PartitionerGraphT::EdgeArrayEntry, storage::Ownership::Container>
|
||||||
|
original_edge_array;
|
||||||
|
|
||||||
std::tie(SuperT::node_array,
|
std::tie(SuperT::node_array,
|
||||||
SuperT::edge_array,
|
original_edge_array,
|
||||||
SuperT::node_to_edge_offset,
|
SuperT::node_to_edge_offset,
|
||||||
SuperT::connectivity_checksum) = std::move(graph).data();
|
SuperT::connectivity_checksum) = std::move(graph).data();
|
||||||
// TODO: add EdgeArrayEntry shaving
|
|
||||||
|
SuperT::edge_array.reserve(original_edge_array.size());
|
||||||
|
for (const auto &edge : original_edge_array)
|
||||||
|
{
|
||||||
|
SuperT::edge_array.push_back({edge.target, {edge.data.turn_id}});
|
||||||
|
is_forward_edge.push_back(edge.data.forward);
|
||||||
|
is_backward_edge.push_back(edge.data.backward);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLevelGraph(Vector<typename SuperT::NodeArrayEntry> node_array_,
|
MultiLevelGraph(Vector<typename SuperT::NodeArrayEntry> node_array_,
|
||||||
Vector<typename SuperT::EdgeArrayEntry> edge_array_,
|
Vector<typename SuperT::EdgeArrayEntry> edge_array_,
|
||||||
Vector<typename SuperT::EdgeOffset> node_to_edge_offset_,
|
Vector<typename SuperT::EdgeOffset> node_to_edge_offset_,
|
||||||
Vector<EdgeWeight> node_weights_,
|
Vector<EdgeWeight> node_weights_,
|
||||||
Vector<EdgeDuration> node_durations_)
|
Vector<EdgeDuration> node_durations_,
|
||||||
|
Vector<bool> is_forward_edge_,
|
||||||
|
Vector<bool> is_backward_edge_)
|
||||||
: SuperT(std::move(node_array_), std::move(edge_array_), std::move(node_to_edge_offset_)),
|
: SuperT(std::move(node_array_), std::move(edge_array_), std::move(node_to_edge_offset_)),
|
||||||
node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_))
|
node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_)),
|
||||||
|
is_forward_edge(is_forward_edge_), is_backward_edge(is_backward_edge_)
|
||||||
{
|
{
|
||||||
// TODO: add EdgeArrayEntry shaving
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeWeight GetNodeWeight(NodeID node) const { return node_weights[node]; }
|
EdgeWeight GetNodeWeight(NodeID node) const { return node_weights[node]; }
|
||||||
|
|
||||||
EdgeWeight GetNodeDuration(NodeID node) const { return node_durations[node]; }
|
EdgeWeight GetNodeDuration(NodeID node) const { return node_durations[node]; }
|
||||||
|
|
||||||
|
bool IsForwardEdge(EdgeID edge) const { return is_forward_edge[edge]; }
|
||||||
|
|
||||||
|
bool IsBackwardEdge(EdgeID edge) const { return is_backward_edge[edge]; }
|
||||||
|
|
||||||
friend void
|
friend void
|
||||||
serialization::read<EdgeDataT, Ownership>(storage::tar::FileReader &reader,
|
serialization::read<EdgeDataT, Ownership>(storage::tar::FileReader &reader,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
@ -90,6 +107,8 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership
|
|||||||
protected:
|
protected:
|
||||||
Vector<EdgeWeight> node_weights;
|
Vector<EdgeWeight> node_weights;
|
||||||
Vector<EdgeDuration> node_durations;
|
Vector<EdgeDuration> node_durations;
|
||||||
|
Vector<bool> is_forward_edge;
|
||||||
|
Vector<bool> is_backward_edge;
|
||||||
};
|
};
|
||||||
|
|
||||||
using MultiLevelEdgeBasedGraph =
|
using MultiLevelEdgeBasedGraph =
|
||||||
|
@ -43,6 +43,8 @@ inline void read(storage::tar::FileReader &reader,
|
|||||||
storage::serialization::read(reader, name + "/node_weights", graph.node_weights);
|
storage::serialization::read(reader, name + "/node_weights", graph.node_weights);
|
||||||
storage::serialization::read(reader, name + "/node_durations", graph.node_durations);
|
storage::serialization::read(reader, name + "/node_durations", graph.node_durations);
|
||||||
storage::serialization::read(reader, name + "/edge_array", graph.edge_array);
|
storage::serialization::read(reader, name + "/edge_array", graph.edge_array);
|
||||||
|
storage::serialization::read(reader, name + "/is_forward_edge", graph.is_forward_edge);
|
||||||
|
storage::serialization::read(reader, name + "/is_backward_edge", graph.is_backward_edge);
|
||||||
storage::serialization::read(reader, name + "/node_to_edge_offset", graph.node_to_edge_offset);
|
storage::serialization::read(reader, name + "/node_to_edge_offset", graph.node_to_edge_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +57,8 @@ inline void write(storage::tar::FileWriter &writer,
|
|||||||
storage::serialization::write(writer, name + "/node_weights", graph.node_weights);
|
storage::serialization::write(writer, name + "/node_weights", graph.node_weights);
|
||||||
storage::serialization::write(writer, name + "/node_durations", graph.node_durations);
|
storage::serialization::write(writer, name + "/node_durations", graph.node_durations);
|
||||||
storage::serialization::write(writer, name + "/edge_array", graph.edge_array);
|
storage::serialization::write(writer, name + "/edge_array", graph.edge_array);
|
||||||
|
storage::serialization::write(writer, name + "/is_forward_edge", graph.is_forward_edge);
|
||||||
|
storage::serialization::write(writer, name + "/is_backward_edge", graph.is_backward_edge);
|
||||||
storage::serialization::write(writer, name + "/node_to_edge_offset", graph.node_to_edge_offset);
|
storage::serialization::write(writer, name + "/node_to_edge_offset", graph.node_to_edge_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define OSRM_ENGINE_DATAFACADE_ALGORITHM_DATAFACADE_HPP
|
#define OSRM_ENGINE_DATAFACADE_ALGORITHM_DATAFACADE_HPP
|
||||||
|
|
||||||
#include "contractor/query_edge.hpp"
|
#include "contractor/query_edge.hpp"
|
||||||
|
#include "customizer/edge_based_graph.hpp"
|
||||||
#include "extractor/edge_based_edge.hpp"
|
#include "extractor/edge_based_edge.hpp"
|
||||||
#include "engine/algorithm.hpp"
|
#include "engine/algorithm.hpp"
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ template <> class AlgorithmDataFacade<CH>
|
|||||||
template <> class AlgorithmDataFacade<MLD>
|
template <> class AlgorithmDataFacade<MLD>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using EdgeData = extractor::EdgeBasedEdge::EdgeData;
|
using EdgeData = customizer::EdgeBasedGraphEdgeData;
|
||||||
using EdgeRange = util::range<EdgeID>;
|
using EdgeRange = util::range<EdgeID>;
|
||||||
|
|
||||||
// search graph access
|
// search graph access
|
||||||
@ -77,6 +78,10 @@ template <> class AlgorithmDataFacade<MLD>
|
|||||||
|
|
||||||
virtual EdgeWeight GetNodeDuration(const NodeID node) const = 0; // TODO: to be removed
|
virtual EdgeWeight GetNodeDuration(const NodeID node) const = 0; // TODO: to be removed
|
||||||
|
|
||||||
|
virtual bool IsForwardEdge(EdgeID edge) const = 0;
|
||||||
|
|
||||||
|
virtual bool IsBackwardEdge(EdgeID edge) const = 0;
|
||||||
|
|
||||||
virtual NodeID GetTarget(const EdgeID e) const = 0;
|
virtual NodeID GetTarget(const EdgeID e) const = 0;
|
||||||
|
|
||||||
virtual const EdgeData &GetEdgeData(const EdgeID e) const = 0;
|
virtual const EdgeData &GetEdgeData(const EdgeID e) const = 0;
|
||||||
|
@ -697,6 +697,16 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
|
|||||||
return query_graph.GetNodeDuration(node);
|
return query_graph.GetNodeDuration(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsForwardEdge(const NodeID node) const override final
|
||||||
|
{
|
||||||
|
return query_graph.IsForwardEdge(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsBackwardEdge(const NodeID node) const override final
|
||||||
|
{
|
||||||
|
return query_graph.IsBackwardEdge(node);
|
||||||
|
}
|
||||||
|
|
||||||
NodeID GetTarget(const EdgeID e) const override final { return query_graph.GetTarget(e); }
|
NodeID GetTarget(const EdgeID e) const override final { return query_graph.GetTarget(e); }
|
||||||
|
|
||||||
const EdgeData &GetEdgeData(const EdgeID e) const override final
|
const EdgeData &GetEdgeData(const EdgeID e) const override final
|
||||||
|
@ -207,7 +207,8 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
|||||||
{
|
{
|
||||||
const auto &edge_data = facade.GetEdgeData(edge);
|
const auto &edge_data = facade.GetEdgeData(edge);
|
||||||
|
|
||||||
if (DIRECTION == FORWARD_DIRECTION ? edge_data.forward : edge_data.backward)
|
if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge)
|
||||||
|
: facade.IsBackwardEdge(edge))
|
||||||
{
|
{
|
||||||
const NodeID to = facade.GetTarget(edge);
|
const NodeID to = facade.GetTarget(edge);
|
||||||
|
|
||||||
@ -218,7 +219,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
|||||||
facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? node : to);
|
facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? node : to);
|
||||||
const auto turn_penalty = facade.GetWeightPenaltyForEdgeID(edge_data.turn_id);
|
const auto turn_penalty = facade.GetWeightPenaltyForEdgeID(edge_data.turn_id);
|
||||||
|
|
||||||
BOOST_ASSERT(edge_data.weight == node_weight + turn_penalty);
|
// TODO: BOOST_ASSERT(edge_data.weight == node_weight + turn_penalty);
|
||||||
|
|
||||||
const EdgeWeight to_weight = weight + node_weight + turn_penalty;
|
const EdgeWeight to_weight = weight + node_weight + turn_penalty;
|
||||||
|
|
||||||
|
@ -332,12 +332,16 @@ inline auto make_multi_level_graph_view(const SharedDataIndex &index, const std:
|
|||||||
index, name + "/node_to_edge_offset");
|
index, name + "/node_to_edge_offset");
|
||||||
auto node_weights = make_vector_view<EdgeWeight>(index, name + "/node_weights");
|
auto node_weights = make_vector_view<EdgeWeight>(index, name + "/node_weights");
|
||||||
auto node_durations = make_vector_view<EdgeDuration>(index, name + "/node_durations");
|
auto node_durations = make_vector_view<EdgeDuration>(index, name + "/node_durations");
|
||||||
|
auto is_forward_edge = make_vector_view<bool>(index, name + "/is_forward_edge");
|
||||||
|
auto is_backward_edge = make_vector_view<bool>(index, name + "/is_backward_edge");
|
||||||
|
|
||||||
return customizer::MultiLevelEdgeBasedGraphView(std::move(node_list),
|
return customizer::MultiLevelEdgeBasedGraphView(std::move(node_list),
|
||||||
std::move(edge_list),
|
std::move(edge_list),
|
||||||
std::move(node_to_offset),
|
std::move(node_to_offset),
|
||||||
std::move(node_weights),
|
std::move(node_weights),
|
||||||
std::move(node_durations));
|
std::move(node_durations),
|
||||||
|
std::move(is_forward_edge),
|
||||||
|
std::move(is_backward_edge));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto make_maneuver_overrides_views(const SharedDataIndex &index, const std::string &name)
|
inline auto make_maneuver_overrides_views(const SharedDataIndex &index, const std::string &name)
|
||||||
|
@ -172,7 +172,8 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
|
|||||||
for (const auto edge : facade.GetBorderEdgeRange(level, node))
|
for (const auto edge : facade.GetBorderEdgeRange(level, node))
|
||||||
{
|
{
|
||||||
const auto &data = facade.GetEdgeData(edge);
|
const auto &data = facade.GetEdgeData(edge);
|
||||||
if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward)
|
if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge)
|
||||||
|
: facade.IsBackwardEdge(edge))
|
||||||
{
|
{
|
||||||
const NodeID to = facade.GetTarget(edge);
|
const NodeID to = facade.GetTarget(edge);
|
||||||
if (facade.ExcludeNode(to))
|
if (facade.ExcludeNode(to))
|
||||||
@ -310,7 +311,8 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
|
|||||||
for (auto edge : facade.GetAdjacentEdgeRange(node))
|
for (auto edge : facade.GetAdjacentEdgeRange(node))
|
||||||
{
|
{
|
||||||
const auto &data = facade.GetEdgeData(edge);
|
const auto &data = facade.GetEdgeData(edge);
|
||||||
if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward)
|
if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge)
|
||||||
|
: facade.IsBackwardEdge(edge))
|
||||||
{
|
{
|
||||||
const auto turn_id = data.turn_id;
|
const auto turn_id = data.turn_id;
|
||||||
const auto edge_weight =
|
const auto edge_weight =
|
||||||
|
@ -145,42 +145,8 @@ std::vector<TurnData> generateTurns(const datafacade &facade,
|
|||||||
const auto &data = facade.GetEdgeData(edge_based_edge_id);
|
const auto &data = facade.GetEdgeData(edge_based_edge_id);
|
||||||
|
|
||||||
// Now, calculate the sum of the weight of all the segments.
|
// Now, calculate the sum of the weight of all the segments.
|
||||||
const auto &geometry =
|
const auto turn_weight = facade.GetWeightPenaltyForEdgeID(data.turn_id);
|
||||||
edge_based_node_info.find(approachedge.edge_based_node_id)->second;
|
const auto turn_duration = facade.GetDurationPenaltyForEdgeID(data.turn_id);
|
||||||
EdgeWeight sum_node_weight = 0;
|
|
||||||
EdgeDuration sum_node_duration = 0;
|
|
||||||
if (geometry.is_geometry_forward)
|
|
||||||
{
|
|
||||||
const auto approach_weight =
|
|
||||||
facade.GetUncompressedForwardWeights(geometry.packed_geometry_id);
|
|
||||||
const auto approach_duration =
|
|
||||||
facade.GetUncompressedForwardDurations(geometry.packed_geometry_id);
|
|
||||||
sum_node_weight = std::accumulate(
|
|
||||||
approach_weight.begin(), approach_weight.end(), EdgeWeight{0});
|
|
||||||
sum_node_duration = std::accumulate(
|
|
||||||
approach_duration.begin(), approach_duration.end(), EdgeDuration{0});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const auto approach_weight =
|
|
||||||
facade.GetUncompressedReverseWeights(geometry.packed_geometry_id);
|
|
||||||
const auto approach_duration =
|
|
||||||
facade.GetUncompressedReverseDurations(geometry.packed_geometry_id);
|
|
||||||
sum_node_weight = std::accumulate(
|
|
||||||
approach_weight.begin(), approach_weight.end(), EdgeWeight{0});
|
|
||||||
sum_node_duration = std::accumulate(
|
|
||||||
approach_duration.begin(), approach_duration.end(), EdgeDuration{0});
|
|
||||||
}
|
|
||||||
|
|
||||||
// The edge.weight is the whole edge weight, which includes the turn
|
|
||||||
// cost.
|
|
||||||
// The turn cost is the edge.weight minus the sum of the individual road
|
|
||||||
// segment weights. This might not be 100% accurate, because some
|
|
||||||
// intersections include stop signs, traffic signals and other
|
|
||||||
// penalties, but at this stage, we can't divide those out, so we just
|
|
||||||
// treat the whole lot as the "turn cost" that we'll stick on the map.
|
|
||||||
const auto turn_weight = data.weight - sum_node_weight;
|
|
||||||
const auto turn_duration = data.duration - sum_node_duration;
|
|
||||||
const auto turn_instruction = facade.GetTurnInstructionForEdgeID(data.turn_id);
|
const auto turn_instruction = facade.GetTurnInstructionForEdgeID(data.turn_id);
|
||||||
|
|
||||||
// Find the three nodes that make up the turn movement)
|
// Find the three nodes that make up the turn movement)
|
||||||
|
@ -325,10 +325,11 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeWeight GetNodeWeight(const NodeID /*node*/) const
|
EdgeWeight GetNodeWeight(const NodeID /*node*/) const { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
bool IsForwardEdge(const NodeID /*edge*/) const { return true; }
|
||||||
}
|
|
||||||
|
bool IsBackwardEdge(const NodeID /*edge*/) const { return true; }
|
||||||
|
|
||||||
bool HasLaneData(const EdgeID /*id*/) const override { return false; }
|
bool HasLaneData(const EdgeID /*id*/) const override { return false; }
|
||||||
NameID GetNameIndex(const NodeID /*nodeID*/) const override { return EMPTY_NAMEID; }
|
NameID GetNameIndex(const NodeID /*nodeID*/) const override { return EMPTY_NAMEID; }
|
||||||
|
Loading…
Reference in New Issue
Block a user