Replace optional<EdgeWeight> with constant value

This commit is contained in:
Patrick Niklaus 2018-02-06 00:47:00 +00:00 committed by Patrick Niklaus
parent f65958fc14
commit 84845ffaa6
3 changed files with 13 additions and 15 deletions

View File

@ -10,8 +10,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <boost/optional.hpp>
namespace osrm namespace osrm
{ {
namespace extractor namespace extractor
@ -41,8 +39,8 @@ class CompressedEdgeContainer
const EdgeDuration duration2, const EdgeDuration duration2,
// node-penalties can be added before/or after the traversal of an edge which // node-penalties can be added before/or after the traversal of an edge which
// depends on whether we traverse the link forwards or backwards. // depends on whether we traverse the link forwards or backwards.
const boost::optional<EdgeWeight> node_weight_penalty = boost::none, const EdgeWeight node_weight_penalty = INVALID_EDGE_WEIGHT,
const boost::optional<EdgeDuration> node_duration_penalty = boost::none); const EdgeDuration node_duration_penalty = MAXIMAL_EDGE_DURATION);
void AddUncompressedEdge(const EdgeID edge_id, void AddUncompressedEdge(const EdgeID edge_id,
const NodeID target_node, const NodeID target_node,

View File

@ -112,8 +112,8 @@ void CompressedEdgeContainer::CompressEdge(
const EdgeWeight weight2, const EdgeWeight weight2,
const EdgeDuration duration1, const EdgeDuration duration1,
const EdgeDuration duration2, const EdgeDuration duration2,
const boost::optional<EdgeWeight> node_weight_penalty, const EdgeWeight node_weight_penalty,
const boost::optional<EdgeDuration> node_duration_penalty) const EdgeDuration node_duration_penalty)
{ {
// remove super-trivial geometries // remove super-trivial geometries
BOOST_ASSERT(SPECIAL_EDGEID != edge_id_1); BOOST_ASSERT(SPECIAL_EDGEID != edge_id_1);
@ -169,10 +169,10 @@ void CompressedEdgeContainer::CompressEdge(
// if the via-node offers a penalty, we add the weight of the penalty as an artificial // if the via-node offers a penalty, we add the weight of the penalty as an artificial
// segment that references SPECIAL_NODEID // segment that references SPECIAL_NODEID
if (node_weight_penalty && node_duration_penalty) if (node_weight_penalty != INVALID_EDGE_WEIGHT && node_duration_penalty != MAXIMAL_EDGE_DURATION)
{ {
edge_bucket_list1.emplace_back(OnewayCompressedEdge{ edge_bucket_list1.emplace_back(OnewayCompressedEdge{
via_node_id, ClipWeight(*node_weight_penalty), ClipDuration(*node_duration_penalty)}); via_node_id, ClipWeight(node_weight_penalty), ClipDuration(node_duration_penalty)});
} }
if (HasEntryForID(edge_id_2)) if (HasEntryForID(edge_id_2))

View File

@ -211,8 +211,8 @@ void GraphCompressor::Compress(
// doesn't have access to. // doesn't have access to.
*/ */
const bool has_node_penalty = traffic_signals.find(node_v) != traffic_signals.end(); const bool has_node_penalty = traffic_signals.find(node_v) != traffic_signals.end();
boost::optional<EdgeDuration> node_duration_penalty = boost::none; EdgeDuration node_duration_penalty = MAXIMAL_EDGE_DURATION;
boost::optional<EdgeWeight> node_weight_penalty = boost::none; EdgeWeight node_weight_penalty = INVALID_EDGE_WEIGHT;
if (has_node_penalty) if (has_node_penalty)
{ {
// we cannot handle this as node penalty, if it depends on turn direction // we cannot handle this as node penalty, if it depends on turn direction
@ -277,12 +277,12 @@ void GraphCompressor::Compress(
graph.GetEdgeData(forward_e1).duration += forward_duration2; graph.GetEdgeData(forward_e1).duration += forward_duration2;
graph.GetEdgeData(reverse_e1).duration += reverse_duration2; graph.GetEdgeData(reverse_e1).duration += reverse_duration2;
if (node_weight_penalty && node_duration_penalty) if (node_weight_penalty != INVALID_EDGE_WEIGHT && node_duration_penalty != MAXIMAL_EDGE_DURATION)
{ {
graph.GetEdgeData(forward_e1).weight += *node_weight_penalty; graph.GetEdgeData(forward_e1).weight += node_weight_penalty;
graph.GetEdgeData(reverse_e1).weight += *node_weight_penalty; graph.GetEdgeData(reverse_e1).weight += node_weight_penalty;
graph.GetEdgeData(forward_e1).duration += *node_duration_penalty; graph.GetEdgeData(forward_e1).duration += node_duration_penalty;
graph.GetEdgeData(reverse_e1).duration += *node_duration_penalty; graph.GetEdgeData(reverse_e1).duration += node_duration_penalty;
} }
// extend e1's to targets of e2's // extend e1's to targets of e2's