Extract avoidable combinations from profiles into ProfileProperties

This commit is contained in:
Patrick Niklaus
2017-07-18 21:05:37 +00:00
committed by Patrick Niklaus
parent f347efb006
commit 9c11197768
7 changed files with 121 additions and 6 deletions
+37
View File
@@ -78,6 +78,41 @@ void SetClassNames(const ExtractorCallbacks::ClassesMap &classes_map,
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();
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);
TIMER_STOP(extracting);
+45 -1
View File
@@ -689,11 +689,55 @@ Sol2ScriptingEnvironment::GetStringListFromTable(const std::string &table_name)
for (auto &&pair : table)
{
strings.push_back(pair.second.as<std::string>());
};
}
}
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()
{
auto &context = GetSol2Context();