Remove duration fallback for turn penalties to simplify logic

This commit is contained in:
Patrick Niklaus 2017-03-14 23:08:01 +00:00 committed by Patrick Niklaus
parent 5ab882759d
commit 809d8a7d03
4 changed files with 20 additions and 101 deletions

View File

@ -417,20 +417,11 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
m_turn_weight_penalties = util::ShM<TurnPenalty, true>::vector(
turn_weight_penalties_ptr,
data_layout.num_entries[storage::DataLayout::TURN_WEIGHT_PENALTIES]);
if (data_layout.num_entries[storage::DataLayout::TURN_DURATION_PENALTIES] == 0)
{ // Fallback to turn weight penalties that are turn duration penalties in deciseconds
m_turn_duration_penalties = util::ShM<TurnPenalty, true>::vector(
turn_weight_penalties_ptr,
data_layout.num_entries[storage::DataLayout::TURN_WEIGHT_PENALTIES]);
}
else
{
auto turn_duration_penalties_ptr = data_layout.GetBlockPtr<TurnPenalty>(
memory_block, storage::DataLayout::TURN_DURATION_PENALTIES);
m_turn_duration_penalties = util::ShM<TurnPenalty, true>::vector(
turn_duration_penalties_ptr,
data_layout.num_entries[storage::DataLayout::TURN_DURATION_PENALTIES]);
}
auto turn_duration_penalties_ptr = data_layout.GetBlockPtr<TurnPenalty>(
memory_block, storage::DataLayout::TURN_DURATION_PENALTIES);
m_turn_duration_penalties = util::ShM<TurnPenalty, true>::vector(
turn_duration_penalties_ptr,
data_layout.num_entries[storage::DataLayout::TURN_DURATION_PENALTIES]);
}
void InitializeGeometryPointers(storage::DataLayout &data_layout, char *memory_block)

View File

@ -46,37 +46,6 @@ class ScriptingEnvironment;
namespace lookup
{
// Set to 1 byte alignment
#pragma pack(push, 1)
struct SegmentHeaderBlock
{
std::uint32_t num_osm_nodes;
OSMNodeID previous_osm_node_id;
};
#pragma pack(pop)
static_assert(sizeof(SegmentHeaderBlock) == 12, "SegmentHeaderBlock is not packed correctly");
#pragma pack(push, 1)
struct SegmentBlock
{
OSMNodeID this_osm_node_id;
double segment_length;
EdgeWeight segment_weight;
EdgeWeight segment_duration;
};
#pragma pack(pop)
static_assert(sizeof(SegmentBlock) == 24, "SegmentBlock is not packed correctly");
#pragma pack(push, 1)
struct TurnPenaltiesHeader
{
//! the number of penalties in each block
std::uint64_t number_of_penalties;
};
#pragma pack(pop)
static_assert(std::is_trivial<TurnPenaltiesHeader>::value, "TurnPenaltiesHeader is not trivial");
static_assert(sizeof(TurnPenaltiesHeader) == 8, "TurnPenaltiesHeader is not packed correctly");
#pragma pack(push, 1)
struct TurnIndexBlock
{

View File

@ -570,13 +570,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
BOOST_ASSERT(turn_weight_penalties.size() == turn_id);
turn_weight_penalties.push_back(weight_penalty);
// the weight and the duration are not the same thing
if (!profile_properties.fallback_to_duration)
{
BOOST_ASSERT(turn_duration_penalties.size() == turn_id);
turn_duration_penalties.push_back(duration_penalty);
}
BOOST_ASSERT(turn_duration_penalties.size() == turn_id);
turn_duration_penalties.push_back(duration_penalty);
// We write out the mapping between the edge-expanded edges and the
// original nodes. Since each edge represents a possible maneuver, external
@ -616,27 +611,17 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
}
// write weight penalties per turn
storage::io::FileWriter turn_weight_penalties_file(turn_weight_penalties_filename,
storage::io::FileWriter::HasNoFingerprint);
lookup::TurnPenaltiesHeader turn_weight_penalties_header{turn_weight_penalties.size()};
turn_weight_penalties_file.WriteOne(turn_weight_penalties_header);
turn_weight_penalties_file.WriteFrom(turn_weight_penalties.data(),
turn_weight_penalties.size());
// write duration penalties per turn if we need them
BOOST_ASSERT(!profile_properties.fallback_to_duration || turn_duration_penalties.size() == 0);
storage::io::FileWriter turn_duration_penalties_file(turn_duration_penalties_filename,
storage::io::FileWriter::HasNoFingerprint);
lookup::TurnPenaltiesHeader turn_duration_penalties_header{turn_duration_penalties.size()};
turn_duration_penalties_file.WriteOne(turn_duration_penalties_header);
if (!profile_properties.fallback_to_duration)
BOOST_ASSERT(turn_weight_penalties.size() == turn_duration_penalties.size());
{
BOOST_ASSERT(turn_weight_penalties.size() == turn_duration_penalties.size());
turn_duration_penalties_file.WriteFrom(turn_duration_penalties.data(),
turn_duration_penalties.size());
storage::io::FileWriter turn_weight_penalties_file(
turn_weight_penalties_filename, storage::io::FileWriter::HasNoFingerprint);
turn_weight_penalties_file.SerializeVector(turn_weight_penalties);
}
{
storage::io::FileWriter turn_duration_penalties_file(
turn_duration_penalties_filename, storage::io::FileWriter::HasNoFingerprint);
turn_duration_penalties_file.SerializeVector(turn_duration_penalties);
}
util::Log() << "Created " << entry_class_hash.size() << " entry classes and "

View File

@ -380,7 +380,7 @@ void saveDatasourcesNames(const UpdaterConfig &config)
extractor::io::write(config.datasource_names_path, sources);
}
using TurnWeightAndDuration = std::tuple<std::vector<TurnPenalty>, std::vector<TurnPenalty>, bool>;
using TurnWeightAndDuration = std::tuple<std::vector<TurnPenalty>, std::vector<TurnPenalty>>;
TurnWeightAndDuration
loadAndUpdateTurnPenalties(const UpdaterConfig &config,
const extractor::ProfileProperties &profile_properties,
@ -407,13 +407,6 @@ loadAndUpdateTurnPenalties(const UpdaterConfig &config,
tbb::parallel_invoke(load_turn_weight_penalties, load_turn_duration_penalties);
bool fallback_to_duration = false;
if (turn_duration_penalties.empty())
{ // Copy-on-write for duration penalties as turn weight penalties
turn_duration_penalties = turn_weight_penalties;
fallback_to_duration = true;
}
// Mapped file pointer for turn indices
const extractor::lookup::TurnIndexBlock *turn_index_blocks =
reinterpret_cast<const extractor::lookup::TurnIndexBlock *>(
@ -436,9 +429,6 @@ loadAndUpdateTurnPenalties(const UpdaterConfig &config,
turn_duration_penalties[edge_index] = turn_duration_penalty;
turn_weight_penalties[edge_index] = turn_weight_penalty;
// Is fallback of duration to weight values allowed
fallback_to_duration &= (turn_duration_penalty == turn_weight_penalty);
}
if (turn_weight_penalty < 0)
@ -449,7 +439,7 @@ loadAndUpdateTurnPenalties(const UpdaterConfig &config,
}
}
return std::make_tuple(std::move(turn_weight_penalties), std::move(turn_duration_penalties), fallback_to_duration);
return std::make_tuple(std::move(turn_weight_penalties), std::move(turn_duration_penalties));
}
}
@ -551,11 +541,10 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &e
std::vector<TurnPenalty> turn_weight_penalties;
std::vector<TurnPenalty> turn_duration_penalties;
bool fallback_to_duration = true;
if (update_turn_penalties)
{
auto turn_penalty_lookup = csv::readTurnValues(config.turn_penalty_lookup_paths);
std::tie(turn_weight_penalties, turn_duration_penalties, fallback_to_duration) =
std::tie(turn_weight_penalties, turn_duration_penalties) =
loadAndUpdateTurnPenalties(config, profile_properties, turn_penalty_lookup);
}
else if (update_edge_weights)
@ -573,12 +562,6 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &e
};
tbb::parallel_invoke(load_turn_weight_penalties, load_turn_duration_penalties);
if (turn_duration_penalties.empty())
{ // Copy-on-write for duration penalties as turn weight penalties
turn_duration_penalties = turn_weight_penalties;
fallback_to_duration = true;
}
}
// Mapped file pointers for edge-based graph edges
@ -680,9 +663,6 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &e
turn_weight_penalties[edge_index] = turn_weight_penalty;
// Is fallback of duration to weight values allowed
fallback_to_duration &= (turn_duration_penalty == turn_weight_penalty);
// Update edge weight
inbuffer.data.weight = new_weight + turn_weight_penalty;
inbuffer.data.duration = new_duration + turn_duration_penalty;
@ -693,12 +673,6 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &e
if (update_turn_penalties)
{
if (fallback_to_duration)
{ // Turn duration penalties are identical to turn weight penalties
// Save empty data vector, so turn weight penalties will be used by data facade.
turn_duration_penalties.clear();
}
const auto save_penalties = [](const auto &filename, const auto &data) -> void {
storage::io::FileWriter file(filename, storage::io::FileWriter::HasNoFingerprint);
file.SerializeVector(data);