Extract avoidable combinations from profiles into ProfileProperties
This commit is contained in:
parent
f347efb006
commit
9c11197768
@ -12,6 +12,7 @@ namespace extractor
|
|||||||
|
|
||||||
using ClassData = std::uint8_t;
|
using ClassData = std::uint8_t;
|
||||||
static const std::uint8_t MAX_CLASS_INDEX = 8 - 1;
|
static const std::uint8_t MAX_CLASS_INDEX = 8 - 1;
|
||||||
|
static const std::uint8_t MAX_AVOIDABLE_CLASSES = 8;
|
||||||
|
|
||||||
inline bool isSubset(const ClassData lhs, const ClassData rhs) { return (lhs & rhs) == lhs; }
|
inline bool isSubset(const ClassData lhs, const ClassData rhs) { return (lhs & rhs) == lhs; }
|
||||||
|
|
||||||
|
@ -5,9 +5,11 @@
|
|||||||
|
|
||||||
#include "util/typedefs.hpp"
|
#include "util/typedefs.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <boost/numeric/conversion/cast.hpp>
|
#include <boost/numeric/conversion/cast.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
@ -70,6 +72,24 @@ struct ProfileProperties
|
|||||||
return std::string(weight_name);
|
return std::string(weight_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark this combination of classes as avoidable
|
||||||
|
void SetAvoidableClasses(std::size_t index, ClassData classes)
|
||||||
|
{
|
||||||
|
avoidable_classes[index] = classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this classes are avoidable
|
||||||
|
boost::optional<std::size_t> ClassesAreAvoidable(ClassData classes)
|
||||||
|
{
|
||||||
|
auto iter = std::find(avoidable_classes.begin(), avoidable_classes.end(), classes);
|
||||||
|
if (iter != avoidable_classes.end())
|
||||||
|
{
|
||||||
|
return std::distance(avoidable_classes.begin(), iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
void SetClassName(std::size_t index, const std::string &name)
|
void SetClassName(std::size_t index, const std::string &name)
|
||||||
{
|
{
|
||||||
char *name_ptr = class_names[index];
|
char *name_ptr = class_names[index];
|
||||||
@ -109,6 +129,8 @@ struct ProfileProperties
|
|||||||
char weight_name[MAX_WEIGHT_NAME_LENGTH + 1];
|
char weight_name[MAX_WEIGHT_NAME_LENGTH + 1];
|
||||||
//! stores the names of each class
|
//! stores the names of each class
|
||||||
std::array<char[MAX_CLASS_NAME_LENGTH + 1], MAX_CLASS_INDEX + 1> class_names;
|
std::array<char[MAX_CLASS_NAME_LENGTH + 1], MAX_CLASS_INDEX + 1> class_names;
|
||||||
|
//! stores the masks of avoidable class combinations
|
||||||
|
std::array<ClassData, MAX_AVOIDABLE_CLASSES> avoidable_classes;
|
||||||
unsigned weight_precision = 1;
|
unsigned weight_precision = 1;
|
||||||
bool force_split_edges = false;
|
bool force_split_edges = false;
|
||||||
bool call_tagless_node_function = true;
|
bool call_tagless_node_function = true;
|
||||||
|
@ -52,6 +52,7 @@ class ScriptingEnvironment
|
|||||||
|
|
||||||
virtual const ProfileProperties &GetProfileProperties() = 0;
|
virtual const ProfileProperties &GetProfileProperties() = 0;
|
||||||
|
|
||||||
|
virtual std::vector<std::vector<std::string>> GetAvoidableClasses() = 0;
|
||||||
virtual std::vector<std::string> GetNameSuffixList() = 0;
|
virtual std::vector<std::string> GetNameSuffixList() = 0;
|
||||||
virtual std::vector<std::string> GetRestrictions() = 0;
|
virtual std::vector<std::string> GetRestrictions() = 0;
|
||||||
virtual void ProcessTurn(ExtractionTurn &turn) = 0;
|
virtual void ProcessTurn(ExtractionTurn &turn) = 0;
|
||||||
|
@ -58,10 +58,7 @@ class Sol2ScriptingEnvironment final : public ScriptingEnvironment
|
|||||||
|
|
||||||
const ProfileProperties &GetProfileProperties() override;
|
const ProfileProperties &GetProfileProperties() override;
|
||||||
|
|
||||||
LuaScriptingContext &GetSol2Context();
|
std::vector<std::vector<std::string>> GetAvoidableClasses() override;
|
||||||
|
|
||||||
std::vector<std::string> GetStringListFromTable(const std::string &table_name);
|
|
||||||
std::vector<std::string> GetStringListFromFunction(const std::string &function_name);
|
|
||||||
std::vector<std::string> GetNameSuffixList() override;
|
std::vector<std::string> GetNameSuffixList() override;
|
||||||
std::vector<std::string> GetRestrictions() override;
|
std::vector<std::string> GetRestrictions() override;
|
||||||
void ProcessTurn(ExtractionTurn &turn) override;
|
void ProcessTurn(ExtractionTurn &turn) override;
|
||||||
@ -75,6 +72,12 @@ class Sol2ScriptingEnvironment final : public ScriptingEnvironment
|
|||||||
std::vector<InputConditionalTurnRestriction> &resulting_restrictions) override;
|
std::vector<InputConditionalTurnRestriction> &resulting_restrictions) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
LuaScriptingContext &GetSol2Context();
|
||||||
|
|
||||||
|
std::vector<std::string> GetStringListFromTable(const std::string &table_name);
|
||||||
|
std::vector<std::vector<std::string>> GetStringListsFromTable(const std::string &table_name);
|
||||||
|
std::vector<std::string> GetStringListFromFunction(const std::string &function_name);
|
||||||
|
|
||||||
void InitContext(LuaScriptingContext &context);
|
void InitContext(LuaScriptingContext &context);
|
||||||
std::mutex init_mutex;
|
std::mutex init_mutex;
|
||||||
std::string file_name;
|
std::string file_name;
|
||||||
|
@ -100,6 +100,13 @@ function setup()
|
|||||||
'vehicle'
|
'vehicle'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- classes to support for avoid flags
|
||||||
|
avoidable = Sequence {
|
||||||
|
Set {"toll"},
|
||||||
|
Set {"motorway"},
|
||||||
|
Set {"ferry"}
|
||||||
|
},
|
||||||
|
|
||||||
avoid = Set {
|
avoid = Set {
|
||||||
'area',
|
'area',
|
||||||
-- 'toll', -- uncomment this to avoid tolls
|
-- 'toll', -- uncomment this to avoid tolls
|
||||||
|
@ -78,6 +78,41 @@ void SetClassNames(const ExtractorCallbacks::ClassesMap &classes_map,
|
|||||||
profile_properties.SetClassName(range.front(), pair.first);
|
profile_properties.SetClassName(range.front(), pair.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converts the class name list to a mask list
|
||||||
|
void SetAvoidableClasses(const ExtractorCallbacks::ClassesMap &classes_map,
|
||||||
|
const std::vector<std::vector<std::string>> &avoidable_classes,
|
||||||
|
ProfileProperties &profile_properties)
|
||||||
|
{
|
||||||
|
if (avoidable_classes.size() > MAX_AVOIDABLE_CLASSES)
|
||||||
|
{
|
||||||
|
throw util::exception("Only " + std::to_string(MAX_AVOIDABLE_CLASSES) + " avoidable combinations allowed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t combination_index = 0;
|
||||||
|
for (const auto &combination : avoidable_classes)
|
||||||
|
{
|
||||||
|
ClassData mask = 0;
|
||||||
|
for (const auto &name : combination)
|
||||||
|
{
|
||||||
|
auto iter = classes_map.find(name);
|
||||||
|
if (iter == classes_map.end())
|
||||||
|
{
|
||||||
|
util::Log(logWARNING)
|
||||||
|
<< "Unknown class name " + name + " in avoidable combination. Ignoring.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mask |= iter->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mask > 0)
|
||||||
|
{
|
||||||
|
profile_properties.SetAvoidableClasses(combination_index++, mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -341,6 +376,8 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment,
|
|||||||
|
|
||||||
auto profile_properties = scripting_environment.GetProfileProperties();
|
auto profile_properties = scripting_environment.GetProfileProperties();
|
||||||
SetClassNames(classes_map, profile_properties);
|
SetClassNames(classes_map, profile_properties);
|
||||||
|
auto avoidable_classes = scripting_environment.GetAvoidableClasses();
|
||||||
|
SetAvoidableClasses(classes_map, avoidable_classes, profile_properties);
|
||||||
files::writeProfileProperties(config.GetPath(".osrm.properties").string(), profile_properties);
|
files::writeProfileProperties(config.GetPath(".osrm.properties").string(), profile_properties);
|
||||||
|
|
||||||
TIMER_STOP(extracting);
|
TIMER_STOP(extracting);
|
||||||
|
@ -689,11 +689,55 @@ Sol2ScriptingEnvironment::GetStringListFromTable(const std::string &table_name)
|
|||||||
for (auto &&pair : table)
|
for (auto &&pair : table)
|
||||||
{
|
{
|
||||||
strings.push_back(pair.second.as<std::string>());
|
strings.push_back(pair.second.as<std::string>());
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::vector<std::string>>
|
||||||
|
Sol2ScriptingEnvironment::GetStringListsFromTable(const std::string &table_name)
|
||||||
|
{
|
||||||
|
std::vector<std::vector<std::string>> string_lists;
|
||||||
|
|
||||||
|
auto &context = GetSol2Context();
|
||||||
|
BOOST_ASSERT(context.state.lua_state() != nullptr);
|
||||||
|
sol::table table = context.profile_table[table_name];
|
||||||
|
if (!table.valid())
|
||||||
|
{
|
||||||
|
return string_lists;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &pair : table)
|
||||||
|
{
|
||||||
|
sol::table inner_table = pair.second;
|
||||||
|
if (!inner_table.valid())
|
||||||
|
{
|
||||||
|
throw util::exception("Expected a sub-table at " + table_name + "[" + pair.first.as<std::string>() + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> inner_vector;
|
||||||
|
for (const auto &inner_pair : inner_table)
|
||||||
|
{
|
||||||
|
inner_vector.push_back(inner_pair.first.as<std::string>());
|
||||||
|
}
|
||||||
|
string_lists.push_back(std::move(inner_vector));
|
||||||
|
}
|
||||||
|
|
||||||
|
return string_lists;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::vector<std::string>> Sol2ScriptingEnvironment::GetAvoidableClasses()
|
||||||
|
{
|
||||||
|
auto &context = GetSol2Context();
|
||||||
|
switch (context.api_version)
|
||||||
|
{
|
||||||
|
case 2:
|
||||||
|
return Sol2ScriptingEnvironment::GetStringListsFromTable("avoidable");
|
||||||
|
default:
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> Sol2ScriptingEnvironment::GetNameSuffixList()
|
std::vector<std::string> Sol2ScriptingEnvironment::GetNameSuffixList()
|
||||||
{
|
{
|
||||||
auto &context = GetSol2Context();
|
auto &context = GetSol2Context();
|
||||||
|
Loading…
Reference in New Issue
Block a user