reformat source files
This commit is contained in:
@@ -83,32 +83,25 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
TIMER_STOP(erasing_dups);
|
||||
std::cout << "ok, after " << TIMER_SEC(erasing_dups) << "s" << std::endl;
|
||||
|
||||
|
||||
std::cout << "[extractor] Sorting all nodes ... " << std::flush;
|
||||
TIMER_START(sorting_nodes);
|
||||
stxxl::sort(all_nodes_list.begin(),
|
||||
all_nodes_list.end(),
|
||||
ExternalMemoryNodeSTXXLCompare(),
|
||||
stxxl::sort(all_nodes_list.begin(), all_nodes_list.end(), ExternalMemoryNodeSTXXLCompare(),
|
||||
stxxl_memory);
|
||||
TIMER_STOP(sorting_nodes);
|
||||
std::cout << "ok, after " << TIMER_SEC(sorting_nodes) << "s" << std::endl;
|
||||
|
||||
|
||||
std::cout << "[extractor] Sorting used ways ... " << std::flush;
|
||||
TIMER_START(sort_ways);
|
||||
stxxl::sort(way_start_end_id_list.begin(),
|
||||
way_start_end_id_list.end(),
|
||||
FirstAndLastSegmentOfWayStxxlCompare(),
|
||||
stxxl_memory);
|
||||
stxxl::sort(way_start_end_id_list.begin(), way_start_end_id_list.end(),
|
||||
FirstAndLastSegmentOfWayStxxlCompare(), stxxl_memory);
|
||||
TIMER_STOP(sort_ways);
|
||||
std::cout << "ok, after " << TIMER_SEC(sort_ways) << "s" << std::endl;
|
||||
|
||||
std::cout << "[extractor] Sorting " << restrictions_list.size() << " restrictions. by from... " << std::flush;
|
||||
std::cout << "[extractor] Sorting " << restrictions_list.size()
|
||||
<< " restrictions. by from... " << std::flush;
|
||||
TIMER_START(sort_restrictions);
|
||||
stxxl::sort(restrictions_list.begin(),
|
||||
restrictions_list.end(),
|
||||
CmpRestrictionContainerByFrom(),
|
||||
stxxl_memory);
|
||||
stxxl::sort(restrictions_list.begin(), restrictions_list.end(),
|
||||
CmpRestrictionContainerByFrom(), stxxl_memory);
|
||||
TIMER_STOP(sort_restrictions);
|
||||
std::cout << "ok, after " << TIMER_SEC(sort_restrictions) << "s" << std::endl;
|
||||
|
||||
@@ -132,7 +125,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
continue;
|
||||
}
|
||||
|
||||
BOOST_ASSERT(way_start_and_end_iterator->way_id == restrictions_iterator->restriction.from.way);
|
||||
BOOST_ASSERT(way_start_and_end_iterator->way_id ==
|
||||
restrictions_iterator->restriction.from.way);
|
||||
const NodeID via_node_id = restrictions_iterator->restriction.via.node;
|
||||
|
||||
if (way_start_and_end_iterator->first_segment_source_id == via_node_id)
|
||||
@@ -153,10 +147,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
|
||||
std::cout << "[extractor] Sorting restrictions. by to ... " << std::flush;
|
||||
TIMER_START(sort_restrictions_to);
|
||||
stxxl::sort(restrictions_list.begin(),
|
||||
restrictions_list.end(),
|
||||
CmpRestrictionContainerByTo(),
|
||||
stxxl_memory);
|
||||
stxxl::sort(restrictions_list.begin(), restrictions_list.end(),
|
||||
CmpRestrictionContainerByTo(), stxxl_memory);
|
||||
TIMER_STOP(sort_restrictions_to);
|
||||
std::cout << "ok, after " << TIMER_SEC(sort_restrictions_to) << "s" << std::endl;
|
||||
|
||||
@@ -177,7 +169,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
++restrictions_iterator;
|
||||
continue;
|
||||
}
|
||||
BOOST_ASSERT(way_start_and_end_iterator->way_id == restrictions_iterator->restriction.to.way);
|
||||
BOOST_ASSERT(way_start_and_end_iterator->way_id ==
|
||||
restrictions_iterator->restriction.to.way);
|
||||
const NodeID via_node_id = restrictions_iterator->restriction.via.node;
|
||||
|
||||
if (way_start_and_end_iterator->first_segment_source_id == via_node_id)
|
||||
@@ -203,7 +196,7 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
const auto count_position = restrictions_out_stream.tellp();
|
||||
restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned));
|
||||
|
||||
for(const auto & restriction_container : restrictions_list)
|
||||
for (const auto &restriction_container : restrictions_list)
|
||||
{
|
||||
if (SPECIAL_NODEID != restriction_container.restriction.from.node &&
|
||||
SPECIAL_NODEID != restriction_container.restriction.to.node)
|
||||
@@ -267,7 +260,6 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
TIMER_STOP(sort_edges_by_start);
|
||||
std::cout << "ok, after " << TIMER_SEC(sort_edges_by_start) << "s" << std::endl;
|
||||
|
||||
|
||||
std::cout << "[extractor] Setting start coords ... " << std::flush;
|
||||
TIMER_START(set_start_coords);
|
||||
file_out_stream.write((char *)&number_of_used_edges, sizeof(unsigned));
|
||||
@@ -298,7 +290,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
// Sort Edges by target
|
||||
std::cout << "[extractor] Sorting edges by target ... " << std::flush;
|
||||
TIMER_START(sort_edges_by_target);
|
||||
stxxl::sort(all_edges_list.begin(), all_edges_list.end(), CmpEdgeByTargetID(), stxxl_memory);
|
||||
stxxl::sort(all_edges_list.begin(), all_edges_list.end(), CmpEdgeByTargetID(),
|
||||
stxxl_memory);
|
||||
TIMER_STOP(sort_edges_by_target);
|
||||
std::cout << "ok, after " << TIMER_SEC(sort_edges_by_target) << "s" << std::endl;
|
||||
|
||||
@@ -329,16 +322,13 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
edge_iterator->target_coordinate.lon = node_iterator->lon;
|
||||
|
||||
const double distance = coordinate_calculation::approx_euclidean_distance(
|
||||
edge_iterator->source_coordinate.lat,
|
||||
edge_iterator->source_coordinate.lon,
|
||||
node_iterator->lat,
|
||||
node_iterator->lon);
|
||||
edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lon,
|
||||
node_iterator->lat, node_iterator->lon);
|
||||
|
||||
const double weight = (distance * 10.) / (edge_iterator->speed / 3.6);
|
||||
int integer_weight = std::max(
|
||||
1,
|
||||
(int)std::floor(
|
||||
(edge_iterator->is_duration_set ? edge_iterator->speed : weight) + .5));
|
||||
1, (int)std::floor(
|
||||
(edge_iterator->is_duration_set ? edge_iterator->speed : weight) + .5));
|
||||
const int integer_distance = std::max(1, (int)distance);
|
||||
const short zero = 0;
|
||||
const short one = 1;
|
||||
@@ -371,30 +361,38 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
if (edge_iterator->is_roundabout)
|
||||
{
|
||||
file_out_stream.write((char *)&yes, sizeof(bool));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
file_out_stream.write((char *)&no, sizeof(bool));
|
||||
}
|
||||
if (edge_iterator->is_in_tiny_cc)
|
||||
{
|
||||
file_out_stream.write((char *)&yes, sizeof(bool));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
file_out_stream.write((char *)&no, sizeof(bool));
|
||||
}
|
||||
if (edge_iterator->is_access_restricted)
|
||||
{
|
||||
file_out_stream.write((char *)&yes, sizeof(bool));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
file_out_stream.write((char *)&no, sizeof(bool));
|
||||
}
|
||||
|
||||
// cannot take adress of bit field, so use local
|
||||
const TravelMode travel_mode = edge_iterator->travel_mode;
|
||||
const TravelMode travel_mode = edge_iterator->travel_mode;
|
||||
file_out_stream.write((char *)&travel_mode, sizeof(TravelMode));
|
||||
|
||||
if (edge_iterator->is_split)
|
||||
{
|
||||
file_out_stream.write((char *)&yes, sizeof(bool));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
file_out_stream.write((char *)&no, sizeof(bool));
|
||||
}
|
||||
++number_of_used_edges;
|
||||
@@ -420,7 +418,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
std::vector<unsigned> name_lengths;
|
||||
for (const std::string &temp_string : name_list)
|
||||
{
|
||||
const unsigned string_length = std::min(static_cast<unsigned>(temp_string.length()), 255u);
|
||||
const unsigned string_length =
|
||||
std::min(static_cast<unsigned>(temp_string.length()), 255u);
|
||||
name_lengths.push_back(string_length);
|
||||
total_length += string_length;
|
||||
}
|
||||
@@ -428,11 +427,12 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
RangeTable<> table(name_lengths);
|
||||
name_file_stream << table;
|
||||
|
||||
name_file_stream.write((char*) &total_length, sizeof(unsigned));
|
||||
name_file_stream.write((char *)&total_length, sizeof(unsigned));
|
||||
// write all chars consecutively
|
||||
for (const std::string &temp_string : name_list)
|
||||
{
|
||||
const unsigned string_length = std::min(static_cast<unsigned>(temp_string.length()), 255u);
|
||||
const unsigned string_length =
|
||||
std::min(static_cast<unsigned>(temp_string.length()), 255u);
|
||||
name_file_stream.write(temp_string.c_str(), string_length);
|
||||
}
|
||||
|
||||
@@ -443,5 +443,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
SimpleLogger().Write() << "Processed " << number_of_used_nodes << " nodes and "
|
||||
<< number_of_used_edges << " edges";
|
||||
}
|
||||
catch (const std::exception &e) { std::cerr << "Caught Execption:" << e.what() << std::endl; }
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << "Caught Execption:" << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,17 +39,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
class ExtractionContainers
|
||||
{
|
||||
#ifndef _MSC_VER
|
||||
constexpr static unsigned stxxl_memory = ((sizeof(std::size_t) == 4) ? std::numeric_limits<int>::max() : std::numeric_limits<unsigned>::max());
|
||||
constexpr static unsigned stxxl_memory =
|
||||
((sizeof(std::size_t) == 4) ? std::numeric_limits<int>::max()
|
||||
: std::numeric_limits<unsigned>::max());
|
||||
#else
|
||||
const static unsigned stxxl_memory = ((sizeof(std::size_t) == 4) ? INT_MAX : UINT_MAX);
|
||||
#endif
|
||||
public:
|
||||
using STXXLNodeIDVector = stxxl::vector<NodeID>;
|
||||
using STXXLNodeVector = stxxl::vector<ExternalMemoryNode>;
|
||||
using STXXLEdgeVector = stxxl::vector<InternalExtractorEdge>;
|
||||
using STXXLStringVector = stxxl::vector<std::string>;
|
||||
using STXXLRestrictionsVector = stxxl::vector<InputRestrictionContainer>;
|
||||
using STXXLWayIDStartEndVector = stxxl::vector<FirstAndLastSegmentOfWay>;
|
||||
using STXXLNodeIDVector = stxxl::vector<NodeID>;
|
||||
using STXXLNodeVector = stxxl::vector<ExternalMemoryNode>;
|
||||
using STXXLEdgeVector = stxxl::vector<InternalExtractorEdge>;
|
||||
using STXXLStringVector = stxxl::vector<std::string>;
|
||||
using STXXLRestrictionsVector = stxxl::vector<InputRestrictionContainer>;
|
||||
using STXXLWayIDStartEndVector = stxxl::vector<FirstAndLastSegmentOfWay>;
|
||||
|
||||
STXXLNodeIDVector used_node_id_list;
|
||||
STXXLNodeVector all_nodes_list;
|
||||
|
||||
@@ -30,11 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
struct ExtractionNode
|
||||
{
|
||||
ExtractionNode() : traffic_lights(false), barrier(false) { }
|
||||
void clear()
|
||||
{
|
||||
traffic_lights = barrier = false;
|
||||
}
|
||||
ExtractionNode() : traffic_lights(false), barrier(false) {}
|
||||
void clear() { traffic_lights = barrier = false; }
|
||||
bool traffic_lights;
|
||||
bool barrier;
|
||||
};
|
||||
|
||||
@@ -52,10 +52,12 @@ struct ExtractionWay
|
||||
}
|
||||
|
||||
enum Directions
|
||||
{ notSure = 0,
|
||||
oneway,
|
||||
bidirectional,
|
||||
opposite };
|
||||
{
|
||||
notSure = 0,
|
||||
oneway,
|
||||
bidirectional,
|
||||
opposite
|
||||
};
|
||||
|
||||
// These accessor methods exists to support the depreciated "way.direction" access
|
||||
// in LUA. Since the direction attribute was removed from ExtractionWay, the
|
||||
@@ -69,19 +71,20 @@ struct ExtractionWay
|
||||
}
|
||||
else if (Directions::opposite == m)
|
||||
{
|
||||
forward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
|
||||
backward_travel_mode = TRAVEL_MODE_DEFAULT;
|
||||
forward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
|
||||
backward_travel_mode = TRAVEL_MODE_DEFAULT;
|
||||
}
|
||||
else if (Directions::bidirectional == m)
|
||||
{
|
||||
forward_travel_mode = TRAVEL_MODE_DEFAULT;
|
||||
backward_travel_mode = TRAVEL_MODE_DEFAULT;
|
||||
forward_travel_mode = TRAVEL_MODE_DEFAULT;
|
||||
backward_travel_mode = TRAVEL_MODE_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
Directions get_direction() const
|
||||
{
|
||||
if (TRAVEL_MODE_INACCESSIBLE != forward_travel_mode && TRAVEL_MODE_INACCESSIBLE != backward_travel_mode)
|
||||
if (TRAVEL_MODE_INACCESSIBLE != forward_travel_mode &&
|
||||
TRAVEL_MODE_INACCESSIBLE != backward_travel_mode)
|
||||
{
|
||||
return Directions::bidirectional;
|
||||
}
|
||||
|
||||
+51
-52
@@ -99,7 +99,8 @@ int Extractor::Run(int argc, char *argv[])
|
||||
}
|
||||
|
||||
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
|
||||
const auto number_of_threads = std::min(recommended_num_threads, extractor_config.requested_num_threads);
|
||||
const auto number_of_threads =
|
||||
std::min(recommended_num_threads, extractor_config.requested_num_threads);
|
||||
tbb::task_scheduler_init init(number_of_threads);
|
||||
|
||||
SimpleLogger().Write() << "Input file: " << extractor_config.input_path.filename().string();
|
||||
@@ -120,10 +121,10 @@ int Extractor::Run(int argc, char *argv[])
|
||||
osmium::io::Reader reader(input_file);
|
||||
const osmium::io::Header header = reader.header();
|
||||
|
||||
std::atomic<unsigned> number_of_nodes {0};
|
||||
std::atomic<unsigned> number_of_ways {0};
|
||||
std::atomic<unsigned> number_of_relations {0};
|
||||
std::atomic<unsigned> number_of_others {0};
|
||||
std::atomic<unsigned> number_of_nodes{0};
|
||||
std::atomic<unsigned> number_of_ways{0};
|
||||
std::atomic<unsigned> number_of_relations{0};
|
||||
std::atomic<unsigned> number_of_others{0};
|
||||
|
||||
SimpleLogger().Write() << "Parsing in progress..";
|
||||
TIMER_START(parsing);
|
||||
@@ -160,7 +161,8 @@ int Extractor::Run(int argc, char *argv[])
|
||||
{
|
||||
// create a vector of iterators into the buffer
|
||||
std::vector<osmium::memory::Buffer::const_iterator> osm_elements;
|
||||
for (auto iter = std::begin(buffer); iter != std::end(buffer); ++iter) {
|
||||
for (auto iter = std::begin(buffer); iter != std::end(buffer); ++iter)
|
||||
{
|
||||
osm_elements.push_back(iter);
|
||||
}
|
||||
|
||||
@@ -170,56 +172,56 @@ int Extractor::Run(int argc, char *argv[])
|
||||
resulting_restrictions.clear();
|
||||
|
||||
// parse OSM entities in parallel, store in resulting vectors
|
||||
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, osm_elements.size()),
|
||||
[&](const tbb::blocked_range<std::size_t> &range)
|
||||
{
|
||||
ExtractionNode result_node;
|
||||
ExtractionWay result_way;
|
||||
lua_State * local_state = scripting_environment.get_lua_state();
|
||||
|
||||
for (auto x = range.begin(); x != range.end(); ++x)
|
||||
tbb::parallel_for(
|
||||
tbb::blocked_range<std::size_t>(0, osm_elements.size()),
|
||||
[&](const tbb::blocked_range<std::size_t> &range)
|
||||
{
|
||||
const auto entity = osm_elements[x];
|
||||
ExtractionNode result_node;
|
||||
ExtractionWay result_way;
|
||||
lua_State *local_state = scripting_environment.get_lua_state();
|
||||
|
||||
switch (entity->type())
|
||||
for (auto x = range.begin(); x != range.end(); ++x)
|
||||
{
|
||||
case osmium::item_type::node:
|
||||
result_node.clear();
|
||||
++number_of_nodes;
|
||||
luabind::call_function<void>(
|
||||
local_state,
|
||||
"node_function",
|
||||
boost::cref(static_cast<const osmium::Node &>(*entity)),
|
||||
boost::ref(result_node));
|
||||
resulting_nodes.push_back(std::make_pair(x, result_node));
|
||||
break;
|
||||
case osmium::item_type::way:
|
||||
result_way.clear();
|
||||
++number_of_ways;
|
||||
luabind::call_function<void>(
|
||||
local_state,
|
||||
"way_function",
|
||||
boost::cref(static_cast<const osmium::Way &>(*entity)),
|
||||
boost::ref(result_way));
|
||||
resulting_ways.push_back(std::make_pair(x, result_way));
|
||||
break;
|
||||
case osmium::item_type::relation:
|
||||
++number_of_relations;
|
||||
resulting_restrictions.push_back(
|
||||
restriction_parser.TryParse(static_cast<const osmium::Relation &>(*entity)));
|
||||
break;
|
||||
default:
|
||||
++number_of_others;
|
||||
break;
|
||||
const auto entity = osm_elements[x];
|
||||
|
||||
switch (entity->type())
|
||||
{
|
||||
case osmium::item_type::node:
|
||||
result_node.clear();
|
||||
++number_of_nodes;
|
||||
luabind::call_function<void>(
|
||||
local_state, "node_function",
|
||||
boost::cref(static_cast<const osmium::Node &>(*entity)),
|
||||
boost::ref(result_node));
|
||||
resulting_nodes.push_back(std::make_pair(x, result_node));
|
||||
break;
|
||||
case osmium::item_type::way:
|
||||
result_way.clear();
|
||||
++number_of_ways;
|
||||
luabind::call_function<void>(
|
||||
local_state, "way_function",
|
||||
boost::cref(static_cast<const osmium::Way &>(*entity)),
|
||||
boost::ref(result_way));
|
||||
resulting_ways.push_back(std::make_pair(x, result_way));
|
||||
break;
|
||||
case osmium::item_type::relation:
|
||||
++number_of_relations;
|
||||
resulting_restrictions.push_back(restriction_parser.TryParse(
|
||||
static_cast<const osmium::Relation &>(*entity)));
|
||||
break;
|
||||
default:
|
||||
++number_of_others;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// put parsed objects thru extractor callbacks
|
||||
for (const auto &result : resulting_nodes)
|
||||
{
|
||||
extractor_callbacks->ProcessNode(
|
||||
static_cast<const osmium::Node &>(*(osm_elements[result.first])), result.second);
|
||||
static_cast<const osmium::Node &>(*(osm_elements[result.first])),
|
||||
result.second);
|
||||
}
|
||||
for (const auto &result : resulting_ways)
|
||||
{
|
||||
@@ -238,11 +240,8 @@ int Extractor::Run(int argc, char *argv[])
|
||||
unsigned nw = number_of_ways;
|
||||
unsigned nr = number_of_relations;
|
||||
unsigned no = number_of_others;
|
||||
SimpleLogger().Write() << "Raw input contains "
|
||||
<< nn << " nodes, "
|
||||
<< nw << " ways, and "
|
||||
<< nr << " relations, and "
|
||||
<< no << " unknown entities";
|
||||
SimpleLogger().Write() << "Raw input contains " << nn << " nodes, " << nw << " ways, and "
|
||||
<< nr << " relations, and " << no << " unknown entities";
|
||||
|
||||
extractor_callbacks.reset();
|
||||
|
||||
|
||||
@@ -51,13 +51,12 @@ ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers &extraction_containe
|
||||
void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node,
|
||||
const ExtractionNode &result_node)
|
||||
{
|
||||
external_memory.all_nodes_list.push_back({
|
||||
static_cast<int>(input_node.location().lat() * COORDINATE_PRECISION),
|
||||
static_cast<int>(input_node.location().lon() * COORDINATE_PRECISION),
|
||||
static_cast<NodeID>(input_node.id()),
|
||||
result_node.barrier,
|
||||
result_node.traffic_lights
|
||||
});
|
||||
external_memory.all_nodes_list.push_back(
|
||||
{static_cast<int>(input_node.location().lat() * COORDINATE_PRECISION),
|
||||
static_cast<int>(input_node.location().lon() * COORDINATE_PRECISION),
|
||||
static_cast<NodeID>(input_node.id()),
|
||||
result_node.barrier,
|
||||
result_node.traffic_lights});
|
||||
}
|
||||
|
||||
void ExtractorCallbacks::ProcessRestriction(
|
||||
@@ -69,7 +68,8 @@ void ExtractorCallbacks::ProcessRestriction(
|
||||
// SimpleLogger().Write() << "from: " << restriction.get().restriction.from.node <<
|
||||
// ",via: " << restriction.get().restriction.via.node <<
|
||||
// ", to: " << restriction.get().restriction.to.node <<
|
||||
// ", only: " << (restriction.get().restriction.flags.is_only ? "y" : "n");
|
||||
// ", only: " << (restriction.get().restriction.flags.is_only ?
|
||||
// "y" : "n");
|
||||
}
|
||||
}
|
||||
/** warning: caller needs to take care of synchronization! */
|
||||
@@ -99,8 +99,10 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
{
|
||||
// TODO: iterate all way segments and set duration corresponding to the length of each
|
||||
// segment
|
||||
const_cast<ExtractionWay&>(parsed_way).forward_speed = parsed_way.duration / (input_way.nodes().size() - 1);
|
||||
const_cast<ExtractionWay&>(parsed_way).backward_speed = parsed_way.duration / (input_way.nodes().size() - 1);
|
||||
const_cast<ExtractionWay &>(parsed_way).forward_speed =
|
||||
parsed_way.duration / (input_way.nodes().size() - 1);
|
||||
const_cast<ExtractionWay &>(parsed_way).backward_speed =
|
||||
parsed_way.duration / (input_way.nodes().size() - 1);
|
||||
}
|
||||
|
||||
if (std::numeric_limits<double>::epsilon() >= std::abs(-1. - parsed_way.forward_speed))
|
||||
@@ -129,41 +131,36 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
((parsed_way.forward_speed != parsed_way.backward_speed) ||
|
||||
(parsed_way.forward_travel_mode != parsed_way.backward_travel_mode));
|
||||
|
||||
auto pair_wise_segment_split = [&](const osmium::NodeRef &first_node,
|
||||
const osmium::NodeRef &last_node)
|
||||
auto pair_wise_segment_split =
|
||||
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
|
||||
{
|
||||
// SimpleLogger().Write() << "adding edge (" << first_node.ref() << "," <<
|
||||
// last_node.ref() << "), fwd speed: " << parsed_way.forward_speed;
|
||||
external_memory.all_edges_list.push_back(InternalExtractorEdge(
|
||||
first_node.ref(),
|
||||
last_node.ref(),
|
||||
first_node.ref(), last_node.ref(),
|
||||
((split_edge || TRAVEL_MODE_INACCESSIBLE == parsed_way.backward_travel_mode)
|
||||
? ExtractionWay::oneway
|
||||
: ExtractionWay::bidirectional),
|
||||
parsed_way.forward_speed,
|
||||
name_id,
|
||||
parsed_way.roundabout,
|
||||
parsed_way.ignore_in_grid,
|
||||
(0 < parsed_way.duration),
|
||||
parsed_way.is_access_restricted,
|
||||
parsed_way.forward_travel_mode,
|
||||
split_edge));
|
||||
parsed_way.forward_speed, name_id, parsed_way.roundabout, parsed_way.ignore_in_grid,
|
||||
(0 < parsed_way.duration), parsed_way.is_access_restricted,
|
||||
parsed_way.forward_travel_mode, split_edge));
|
||||
external_memory.used_node_id_list.push_back(first_node.ref());
|
||||
};
|
||||
|
||||
const bool is_opposite_way = TRAVEL_MODE_INACCESSIBLE == parsed_way.forward_travel_mode;
|
||||
if (is_opposite_way)
|
||||
{
|
||||
const_cast<ExtractionWay&>(parsed_way).forward_travel_mode = parsed_way.backward_travel_mode;
|
||||
const_cast<ExtractionWay&>(parsed_way).backward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
|
||||
osrm::for_each_pair(
|
||||
input_way.nodes().crbegin(), input_way.nodes().crend(), pair_wise_segment_split);
|
||||
const_cast<ExtractionWay &>(parsed_way).forward_travel_mode =
|
||||
parsed_way.backward_travel_mode;
|
||||
const_cast<ExtractionWay &>(parsed_way).backward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
|
||||
osrm::for_each_pair(input_way.nodes().crbegin(), input_way.nodes().crend(),
|
||||
pair_wise_segment_split);
|
||||
external_memory.used_node_id_list.push_back(input_way.nodes().front().ref());
|
||||
}
|
||||
else
|
||||
{
|
||||
osrm::for_each_pair(
|
||||
input_way.nodes().cbegin(), input_way.nodes().cend(), pair_wise_segment_split);
|
||||
osrm::for_each_pair(input_way.nodes().cbegin(), input_way.nodes().cend(),
|
||||
pair_wise_segment_split);
|
||||
external_memory.used_node_id_list.push_back(input_way.nodes().back().ref());
|
||||
}
|
||||
|
||||
@@ -177,39 +174,30 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
|
||||
if (split_edge)
|
||||
{ // Only true if the way should be split
|
||||
BOOST_ASSERT(parsed_way.backward_travel_mode>0);
|
||||
auto pair_wise_segment_split_2 = [&](const osmium::NodeRef &first_node,
|
||||
const osmium::NodeRef &last_node)
|
||||
BOOST_ASSERT(parsed_way.backward_travel_mode > 0);
|
||||
auto pair_wise_segment_split_2 =
|
||||
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
|
||||
{
|
||||
// SimpleLogger().Write() << "adding edge (" << last_node.ref() << "," <<
|
||||
// first_node.ref() << "), bwd speed: " << parsed_way.backward_speed;
|
||||
external_memory.all_edges_list.push_back(
|
||||
InternalExtractorEdge(last_node.ref(),
|
||||
first_node.ref(),
|
||||
ExtractionWay::oneway,
|
||||
parsed_way.backward_speed,
|
||||
name_id,
|
||||
parsed_way.roundabout,
|
||||
parsed_way.ignore_in_grid,
|
||||
(0 < parsed_way.duration),
|
||||
parsed_way.is_access_restricted,
|
||||
parsed_way.backward_travel_mode,
|
||||
split_edge));
|
||||
external_memory.all_edges_list.push_back(InternalExtractorEdge(
|
||||
last_node.ref(), first_node.ref(), ExtractionWay::oneway, parsed_way.backward_speed,
|
||||
name_id, parsed_way.roundabout, parsed_way.ignore_in_grid,
|
||||
(0 < parsed_way.duration), parsed_way.is_access_restricted,
|
||||
parsed_way.backward_travel_mode, split_edge));
|
||||
};
|
||||
|
||||
if (is_opposite_way)
|
||||
{
|
||||
// SimpleLogger().Write() << "opposite2";
|
||||
osrm::for_each_pair(input_way.nodes().crbegin(),
|
||||
input_way.nodes().crend(),
|
||||
pair_wise_segment_split_2);
|
||||
osrm::for_each_pair(input_way.nodes().crbegin(), input_way.nodes().crend(),
|
||||
pair_wise_segment_split_2);
|
||||
external_memory.used_node_id_list.push_back(input_way.nodes().front().ref());
|
||||
}
|
||||
else
|
||||
{
|
||||
osrm::for_each_pair(input_way.nodes().cbegin(),
|
||||
input_way.nodes().cend(),
|
||||
pair_wise_segment_split_2);
|
||||
osrm::for_each_pair(input_way.nodes().cbegin(), input_way.nodes().cend(),
|
||||
pair_wise_segment_split_2);
|
||||
external_memory.used_node_id_list.push_back(input_way.nodes().back().ref());
|
||||
}
|
||||
|
||||
|
||||
@@ -41,9 +41,8 @@ bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &e
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
|
||||
"config,c",
|
||||
boost::program_options::value<boost::filesystem::path>(&extractor_config.config_file_path)
|
||||
->default_value("extractor.ini"),
|
||||
"config,c", boost::program_options::value<boost::filesystem::path>(
|
||||
&extractor_config.config_file_path)->default_value("extractor.ini"),
|
||||
"Path to a configuration file.");
|
||||
|
||||
// declare a group of options that will be allowed both on command line and in config file
|
||||
@@ -60,10 +59,9 @@ bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &e
|
||||
// hidden options, will be allowed both on command line and in config file, but will not be
|
||||
// shown to the user
|
||||
boost::program_options::options_description hidden_options("Hidden options");
|
||||
hidden_options.add_options()(
|
||||
"input,i",
|
||||
boost::program_options::value<boost::filesystem::path>(&extractor_config.input_path),
|
||||
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
||||
hidden_options.add_options()("input,i", boost::program_options::value<boost::filesystem::path>(
|
||||
&extractor_config.input_path),
|
||||
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
||||
|
||||
// positional option
|
||||
boost::program_options::positional_options_description positional_options;
|
||||
|
||||
@@ -55,8 +55,8 @@ struct InternalExtractorEdge
|
||||
bool is_access_restricted,
|
||||
TravelMode travel_mode,
|
||||
bool is_split)
|
||||
: start(start), target(target), speed(speed), name_id(name_id),
|
||||
direction(direction), is_roundabout(is_roundabout), is_in_tiny_cc(is_in_tiny_cc),
|
||||
: start(start), target(target), speed(speed), name_id(name_id), direction(direction),
|
||||
is_roundabout(is_roundabout), is_in_tiny_cc(is_in_tiny_cc),
|
||||
is_duration_set(is_duration_set), is_access_restricted(is_access_restricted),
|
||||
is_split(is_split), travel_mode(travel_mode)
|
||||
{
|
||||
@@ -65,12 +65,13 @@ struct InternalExtractorEdge
|
||||
// necessary static util functions for stxxl's sorting
|
||||
static InternalExtractorEdge min_value()
|
||||
{
|
||||
return InternalExtractorEdge(0, 0, 0, 0, 0, false, false, false, false, TRAVEL_MODE_INACCESSIBLE, false);
|
||||
return InternalExtractorEdge(0, 0, 0, 0, 0, false, false, false, false,
|
||||
TRAVEL_MODE_INACCESSIBLE, false);
|
||||
}
|
||||
static InternalExtractorEdge max_value()
|
||||
{
|
||||
return InternalExtractorEdge(
|
||||
SPECIAL_NODEID, SPECIAL_NODEID, 0, 0, 0, false, false, false, false, TRAVEL_MODE_INACCESSIBLE, false);
|
||||
return InternalExtractorEdge(SPECIAL_NODEID, SPECIAL_NODEID, 0, 0, 0, false, false, false,
|
||||
false, TRAVEL_MODE_INACCESSIBLE, false);
|
||||
}
|
||||
|
||||
NodeID start;
|
||||
@@ -78,11 +79,11 @@ struct InternalExtractorEdge
|
||||
double speed;
|
||||
unsigned name_id;
|
||||
short direction;
|
||||
bool is_roundabout:1;
|
||||
bool is_in_tiny_cc:1;
|
||||
bool is_duration_set:1;
|
||||
bool is_access_restricted:1;
|
||||
bool is_split:1;
|
||||
bool is_roundabout : 1;
|
||||
bool is_in_tiny_cc : 1;
|
||||
bool is_duration_set : 1;
|
||||
bool is_access_restricted : 1;
|
||||
bool is_split : 1;
|
||||
TravelMode travel_mode : 4;
|
||||
|
||||
FixedPointCoordinate source_coordinate;
|
||||
|
||||
@@ -85,8 +85,8 @@ void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
|
||||
{
|
||||
luabind::set_pcall_callback(&lua_error_callback);
|
||||
// get list of turn restriction exceptions
|
||||
luabind::call_function<void>(
|
||||
lua_state, "get_exceptions", boost::ref(restriction_exceptions));
|
||||
luabind::call_function<void>(lua_state, "get_exceptions",
|
||||
boost::ref(restriction_exceptions));
|
||||
const unsigned exception_count = restriction_exceptions.size();
|
||||
SimpleLogger().Write() << "Found " << exception_count
|
||||
<< " exceptions to turn restrictions:";
|
||||
|
||||
@@ -46,7 +46,8 @@ class RestrictionParser
|
||||
public:
|
||||
// RestrictionParser(ScriptingEnvironment &scripting_environment);
|
||||
RestrictionParser(lua_State *lua_state);
|
||||
mapbox::util::optional<InputRestrictionContainer> TryParse(const osmium::Relation &relation) const;
|
||||
mapbox::util::optional<InputRestrictionContainer>
|
||||
TryParse(const osmium::Relation &relation) const;
|
||||
|
||||
private:
|
||||
void ReadUseRestrictionsSetting(lua_State *lua_state);
|
||||
|
||||
@@ -41,10 +41,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
#include <sstream>
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
// wrapper method as luabind doesn't automatically overload funcs w/ default parameters
|
||||
template<class T>
|
||||
auto get_value_by_key(T const& object, const char *key) -> decltype(object.get_value_by_key(key))
|
||||
template <class T>
|
||||
auto get_value_by_key(T const &object, const char *key) -> decltype(object.get_value_by_key(key))
|
||||
{
|
||||
return object.get_value_by_key(key, "");
|
||||
}
|
||||
@@ -59,16 +60,14 @@ int lua_error_callback(lua_State *L) // This is so I can use my own function as
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name)
|
||||
: file_name(file_name)
|
||||
ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name) : file_name(file_name)
|
||||
{
|
||||
SimpleLogger().Write() << "Using script " << file_name;
|
||||
}
|
||||
|
||||
void ScriptingEnvironment::init_lua_state(lua_State* lua_state)
|
||||
void ScriptingEnvironment::init_lua_state(lua_State *lua_state)
|
||||
{
|
||||
typedef double (osmium::Location::* location_member_ptr_type)() const;
|
||||
typedef double (osmium::Location::*location_member_ptr_type)() const;
|
||||
|
||||
luabind::open(lua_state);
|
||||
// open utility libraries string library;
|
||||
@@ -83,41 +82,44 @@ void ScriptingEnvironment::init_lua_state(lua_State* lua_state)
|
||||
luabind::def("parseDuration", parseDuration),
|
||||
|
||||
luabind::class_<std::vector<std::string>>("vector")
|
||||
.def("Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>(&std::vector<std::string>::push_back)),
|
||||
.def("Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>(
|
||||
&std::vector<std::string>::push_back)),
|
||||
|
||||
luabind::class_<osmium::Location>("Location")
|
||||
.def<location_member_ptr_type>("lat", &osmium::Location::lat)
|
||||
.def<location_member_ptr_type>("lon", &osmium::Location::lon),
|
||||
.def<location_member_ptr_type>("lat", &osmium::Location::lat)
|
||||
.def<location_member_ptr_type>("lon", &osmium::Location::lon),
|
||||
|
||||
luabind::class_<osmium::Node>("Node")
|
||||
// .def<node_member_ptr_type>("tags", &osmium::Node::tags)
|
||||
.def("get_value_by_key", &osmium::Node::get_value_by_key)
|
||||
.def("get_value_by_key", &get_value_by_key<osmium::Node>),
|
||||
// .def<node_member_ptr_type>("tags", &osmium::Node::tags)
|
||||
.def("get_value_by_key", &osmium::Node::get_value_by_key)
|
||||
.def("get_value_by_key", &get_value_by_key<osmium::Node>),
|
||||
|
||||
luabind::class_<ExtractionNode>("ResultNode")
|
||||
.def_readwrite("traffic_lights", &ExtractionNode::traffic_lights)
|
||||
.def_readwrite("barrier", &ExtractionNode::barrier),
|
||||
.def_readwrite("traffic_lights", &ExtractionNode::traffic_lights)
|
||||
.def_readwrite("barrier", &ExtractionNode::barrier),
|
||||
|
||||
luabind::class_<ExtractionWay>("ResultWay")
|
||||
// .def(luabind::constructor<>())
|
||||
.def_readwrite("forward_speed", &ExtractionWay::forward_speed)
|
||||
.def_readwrite("backward_speed", &ExtractionWay::backward_speed)
|
||||
.def_readwrite("name", &ExtractionWay::name)
|
||||
.def_readwrite("roundabout", &ExtractionWay::roundabout)
|
||||
.def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted)
|
||||
.def_readwrite("ignore_in_index", &ExtractionWay::ignore_in_grid)
|
||||
.def_readwrite("duration", &ExtractionWay::duration)
|
||||
.property("forward_mode", &ExtractionWay::get_forward_mode, &ExtractionWay::set_forward_mode)
|
||||
.property("backward_mode", &ExtractionWay::get_backward_mode, &ExtractionWay::set_backward_mode)
|
||||
.enum_("constants")[
|
||||
luabind::value("notSure", 0),
|
||||
luabind::value("oneway", 1),
|
||||
luabind::value("bidirectional", 2),
|
||||
luabind::value("opposite", 3)
|
||||
],
|
||||
// .def(luabind::constructor<>())
|
||||
.def_readwrite("forward_speed", &ExtractionWay::forward_speed)
|
||||
.def_readwrite("backward_speed", &ExtractionWay::backward_speed)
|
||||
.def_readwrite("name", &ExtractionWay::name)
|
||||
.def_readwrite("roundabout", &ExtractionWay::roundabout)
|
||||
.def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted)
|
||||
.def_readwrite("ignore_in_index", &ExtractionWay::ignore_in_grid)
|
||||
.def_readwrite("duration", &ExtractionWay::duration)
|
||||
.property("forward_mode", &ExtractionWay::get_forward_mode,
|
||||
&ExtractionWay::set_forward_mode)
|
||||
.property("backward_mode", &ExtractionWay::get_backward_mode,
|
||||
&ExtractionWay::set_backward_mode)
|
||||
.enum_("constants")[
|
||||
luabind::value("notSure", 0),
|
||||
luabind::value("oneway", 1),
|
||||
luabind::value("bidirectional", 2),
|
||||
luabind::value("opposite", 3)
|
||||
],
|
||||
luabind::class_<osmium::Way>("Way")
|
||||
.def("get_value_by_key", &osmium::Way::get_value_by_key)
|
||||
.def("get_value_by_key", &get_value_by_key<osmium::Way>)
|
||||
.def("get_value_by_key", &osmium::Way::get_value_by_key)
|
||||
.def("get_value_by_key", &get_value_by_key<osmium::Way>)
|
||||
];
|
||||
|
||||
if (0 != luaL_dofile(lua_state, file_name.c_str()))
|
||||
@@ -133,7 +135,7 @@ lua_State *ScriptingEnvironment::get_lua_state()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(init_mutex);
|
||||
bool initialized = false;
|
||||
auto& ref = script_contexts.local(initialized);
|
||||
auto &ref = script_contexts.local(initialized);
|
||||
if (!initialized)
|
||||
{
|
||||
std::shared_ptr<lua_State> state(luaL_newstate(), lua_close);
|
||||
|
||||
@@ -44,8 +44,8 @@ class ScriptingEnvironment
|
||||
lua_State *get_lua_state();
|
||||
|
||||
private:
|
||||
void init_lua_state(lua_State* lua_state);
|
||||
std::mutex init_mutex;
|
||||
void init_lua_state(lua_State *lua_state);
|
||||
std::mutex init_mutex;
|
||||
std::string file_name;
|
||||
tbb::enumerable_thread_specific<std::shared_ptr<lua_State>> script_contexts;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user