Incoperate PR comments

This commit is contained in:
Patrick Niklaus 2015-12-09 22:34:22 +01:00
parent 24090d4642
commit b41af5f580
14 changed files with 68 additions and 60 deletions

View File

@ -28,7 +28,7 @@ template <typename RTreeT> class GeospatialQuery
// Returns nearest PhantomNodes in the given bearing range within max_distance.
// Does not filter by small/big component!
std::vector<std::pair<double, PhantomNode>>
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate,
const float max_distance,
const int bearing = 0,
@ -50,7 +50,7 @@ template <typename RTreeT> class GeospatialQuery
// Returns max_results nearest PhantomNodes in the given bearing range.
// Does not filter by small/big component!
std::vector<std::pair<double, PhantomNode>>
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const FixedPointCoordinate &input_coordinate,
const unsigned max_results,
const int bearing = 0,
@ -84,7 +84,7 @@ template <typename RTreeT> class GeospatialQuery
&has_small_component](const EdgeData &data)
{
auto use_segment =
(!has_small_component || (!has_big_component && !data.component.is_tiny)) ;
(!has_small_component || (!has_big_component && !data.component.is_tiny));
auto use_directions = std::make_pair(use_segment, use_segment);
if (use_segment)
@ -104,22 +104,22 @@ template <typename RTreeT> class GeospatialQuery
return num_results > 0 && has_big_component;
});
if (results.size() == 0)
{
return std::make_pair(PhantomNode {}, PhantomNode {});
return std::make_pair(PhantomNode{}, PhantomNode{});
}
BOOST_ASSERT(results.size() > 0);
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).second, MakePhantomNode(input_coordinate, results.back()).second);
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
MakePhantomNode(input_coordinate, results.back()).phantom_node);
}
private:
inline std::vector<std::pair<double, PhantomNode>>
std::vector<PhantomNodeWithDistance>
MakePhantomNodes(const FixedPointCoordinate &input_coordinate,
const std::vector<EdgeData> &results) const
{
std::vector<std::pair<double, PhantomNode>> distance_and_phantoms(results.size());
std::vector<PhantomNodeWithDistance> distance_and_phantoms(results.size());
std::transform(results.begin(), results.end(), distance_and_phantoms.begin(),
[this, &input_coordinate](const EdgeData &data)
{
@ -128,8 +128,8 @@ template <typename RTreeT> class GeospatialQuery
return distance_and_phantoms;
}
inline std::pair<double, PhantomNode>
MakePhantomNode(const FixedPointCoordinate &input_coordinate, const EdgeData &data) const
PhantomNodeWithDistance MakePhantomNode(const FixedPointCoordinate &input_coordinate,
const EdgeData &data) const
{
FixedPointCoordinate point_on_segment;
float ratio;
@ -138,24 +138,24 @@ template <typename RTreeT> class GeospatialQuery
ratio);
auto transformed =
std::make_pair(current_perpendicular_distance, PhantomNode{data, point_on_segment});
PhantomNodeWithDistance { PhantomNode{data, point_on_segment}, current_perpendicular_distance };
ratio = std::min(1.f, std::max(0.f, ratio));
if (SPECIAL_NODEID != transformed.second.forward_node_id)
if (SPECIAL_NODEID != transformed.phantom_node.forward_node_id)
{
transformed.second.forward_weight *= ratio;
transformed.phantom_node.forward_weight *= ratio;
}
if (SPECIAL_NODEID != transformed.second.reverse_node_id)
if (SPECIAL_NODEID != transformed.phantom_node.reverse_node_id)
{
transformed.second.reverse_weight *= 1.f - ratio;
transformed.phantom_node.reverse_weight *= 1.f - ratio;
}
return transformed;
}
inline std::pair<bool, bool> checkSegmentBearing(const EdgeData &segment,
const float filter_bearing,
const float filter_bearing_range)
std::pair<bool, bool> checkSegmentBearing(const EdgeData &segment,
const float filter_bearing,
const float filter_bearing_range)
{
const float forward_edge_bearing =
coordinate_calculation::bearing(coordinates->at(segment.u), coordinates->at(segment.v));

View File

@ -69,7 +69,7 @@ FixedPointCoordinateListPtr LoadCoordinates(const boost::filesystem::path &nodes
template <typename QueryT>
void BenchmarkQuery(const std::vector<FixedPointCoordinate> &queries,
std::string name,
const std::string& name,
QueryT query)
{
std::cout << "Running " << name << " with " << queries.size() << " coordinates: " << std::flush;
@ -96,7 +96,7 @@ void Benchmark(BenchStaticRTree &rtree, BenchQuery &geo_query, unsigned num_quer
std::vector<FixedPointCoordinate> queries;
for (unsigned i = 0; i < num_queries; i++)
{
queries.emplace_back(FixedPointCoordinate(lat_udist(mt_rand), lon_udist(mt_rand)));
queries.emplace_back(lat_udist(mt_rand), lon_udist(mt_rand));
}
BenchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const FixedPointCoordinate &q)

View File

@ -140,7 +140,7 @@ template <class CandidateLists> struct HiddenMarkovModel
for (const auto s : osrm::irange<std::size_t>(0u, viterbi[initial_timestamp].size()))
{
viterbi[initial_timestamp][s] =
emission_log_probability(candidates_list[initial_timestamp][s].first);
emission_log_probability(candidates_list[initial_timestamp][s].distance);
parents[initial_timestamp][s] = std::make_pair(initial_timestamp, s);
pruned[initial_timestamp][s] =
viterbi[initial_timestamp][s] < osrm::matching::MINIMAL_LOG_PROB;

View File

@ -124,6 +124,12 @@ static_assert(sizeof(PhantomNode) == 48, "PhantomNode has more padding then expe
using PhantomNodePair = std::pair<PhantomNode, PhantomNode>;
struct PhantomNodeWithDistance
{
PhantomNode phantom_node;
double distance;
};
struct PhantomNodes
{
PhantomNode source_phantom;

View File

@ -412,7 +412,7 @@ class StaticRTree
}
// store phantom node in result vector
results.emplace_back(std::move(current_segment));
results.push_back(std::move(current_segment));
if (!use_segment.first)
{
@ -476,7 +476,7 @@ class StaticRTree
}
if (!leaves_stream.good())
{
leaves_stream.clear(std::ios::goodbit);
throw osrm::exception("Could not read from leaf file.");
}
const uint64_t seek_pos = sizeof(uint64_t) + leaf_id * sizeof(LeafNode);
leaves_stream.seekg(seek_pos);

View File

@ -580,8 +580,8 @@ void extractor::BuildRTree(const std::vector<EdgeBasedNode> &node_based_edge_lis
<< " coordinates";
TIMER_START(construction);
StaticRTree<EdgeBasedNode>(node_based_edge_list, config.rtree_nodes_output_path.c_str(),
config.rtree_leafs_output_path.c_str(),
StaticRTree<EdgeBasedNode>(node_based_edge_list, config.rtree_nodes_output_path,
config.rtree_leafs_output_path,
internal_to_external_node_map);
TIMER_STOP(construction);

View File

@ -135,18 +135,18 @@ template <class DataFacadeT> class MapMatchingPlugin : public BasePlugin
// sort by foward id, then by reverse id and then by distance
std::sort(candidates.begin(), candidates.end(),
[](const std::pair<double, PhantomNode>& lhs, const std::pair<double, PhantomNode>& rhs) {
return lhs.second.forward_node_id < rhs.second.forward_node_id ||
(lhs.second.forward_node_id == rhs.second.forward_node_id &&
(lhs.second.reverse_node_id < rhs.second.reverse_node_id ||
(lhs.second.reverse_node_id == rhs.second.reverse_node_id &&
lhs.first < rhs.first)));
[](const PhantomNodeWithDistance& lhs, const PhantomNodeWithDistance& rhs) {
return lhs.phantom_node.forward_node_id < rhs.phantom_node.forward_node_id ||
(lhs.phantom_node.forward_node_id == rhs.phantom_node.forward_node_id &&
(lhs.phantom_node.reverse_node_id < rhs.phantom_node.reverse_node_id ||
(lhs.phantom_node.reverse_node_id == rhs.phantom_node.reverse_node_id &&
lhs.distance < rhs.distance)));
});
auto new_end = std::unique(candidates.begin(), candidates.end(),
[](const std::pair<double, PhantomNode>& lhs, const std::pair<double, PhantomNode>& rhs) {
return lhs.second.forward_node_id == rhs.second.forward_node_id &&
lhs.second.reverse_node_id == rhs.second.reverse_node_id;
[](const PhantomNodeWithDistance& lhs, const PhantomNodeWithDistance& rhs) {
return lhs.phantom_node.forward_node_id == rhs.phantom_node.forward_node_id &&
lhs.phantom_node.reverse_node_id == rhs.phantom_node.reverse_node_id;
});
candidates.resize(new_end - candidates.begin());
@ -156,22 +156,22 @@ template <class DataFacadeT> class MapMatchingPlugin : public BasePlugin
for (const auto i : osrm::irange<std::size_t>(0, compact_size))
{
// Split edge if it is bidirectional and append reverse direction to end of list
if (candidates[i].second.forward_node_id != SPECIAL_NODEID &&
candidates[i].second.reverse_node_id != SPECIAL_NODEID)
if (candidates[i].phantom_node.forward_node_id != SPECIAL_NODEID &&
candidates[i].phantom_node.reverse_node_id != SPECIAL_NODEID)
{
PhantomNode reverse_node(candidates[i].second);
PhantomNode reverse_node(candidates[i].phantom_node);
reverse_node.forward_node_id = SPECIAL_NODEID;
candidates.push_back(std::make_pair(candidates[i].first, reverse_node));
candidates.push_back(PhantomNodeWithDistance { reverse_node, candidates[i].distance});
candidates[i].second.reverse_node_id = SPECIAL_NODEID;
candidates[i].phantom_node.reverse_node_id = SPECIAL_NODEID;
}
}
}
// sort by distance to make pruning effective
std::sort(candidates.begin(), candidates.end(),
[](const std::pair<double, PhantomNode>& lhs, const std::pair<double, PhantomNode>& rhs) {
return lhs.first < rhs.first;
[](const PhantomNodeWithDistance& lhs, const PhantomNodeWithDistance& rhs) {
return lhs.distance < rhs.distance;
});
candidates_lists.push_back(std::move(candidates));

View File

@ -71,7 +71,7 @@ template <class DataFacadeT> class NearestPlugin final : public BasePlugin
const int range = input_bearings.size() > 0 ? (input_bearings.front().second?*input_bearings.front().second:10) : 180;
auto phantom_node_vector = facade->NearestPhantomNodes(route_parameters.coordinates.front(), number_of_results, bearing, range);
if (phantom_node_vector.empty() || !phantom_node_vector.front().second.is_valid())
if (phantom_node_vector.empty() || !phantom_node_vector.front().phantom_node.is_valid())
{
json_result.values["status"] = 207;
}
@ -88,7 +88,7 @@ template <class DataFacadeT> class NearestPlugin final : public BasePlugin
for (const auto i :
osrm::irange<std::size_t>(0, std::min(number_of_results, vector_length)))
{
const auto& node = phantom_node_vector[i].second;
const auto& node = phantom_node_vector[i].phantom_node;
osrm::json::Array json_coordinate;
osrm::json::Object result;
json_coordinate.values.push_back(node.location.lat / COORDINATE_PRECISION);
@ -103,13 +103,13 @@ template <class DataFacadeT> class NearestPlugin final : public BasePlugin
else
{
osrm::json::Array json_coordinate;
json_coordinate.values.push_back(phantom_node_vector.front().second.location.lat /
json_coordinate.values.push_back(phantom_node_vector.front().phantom_node.location.lat /
COORDINATE_PRECISION);
json_coordinate.values.push_back(phantom_node_vector.front().second.location.lon /
json_coordinate.values.push_back(phantom_node_vector.front().phantom_node.location.lon /
COORDINATE_PRECISION);
json_result.values["mapped_coordinate"] = json_coordinate;
json_result.values["name"] =
facade->get_name_for_id(phantom_node_vector.front().second.name_id);
facade->get_name_for_id(phantom_node_vector.front().phantom_node.name_id);
}
}
return 200;

View File

@ -97,7 +97,7 @@ template <class DataFacadeT> class RoundTripPlugin final : public BasePlugin
const int range = input_bearings.size() > 0 ? (input_bearings[i].second?*input_bearings[i].second:10) : 180;
auto phantom_nodes = facade->NearestPhantomNodes(route_parameters.coordinates[i], 1, bearing, range);
// FIXME we only use the pair because that is what DistanceTable expects
phantom_node_pair_list[i] = std::make_pair(phantom_nodes.front().second, phantom_nodes.front().second);
phantom_node_pair_list[i] = std::make_pair(phantom_nodes.front().phantom_node, phantom_nodes.front().phantom_node);
BOOST_ASSERT(phantom_node_pair_list[i].first.is_valid(facade->GetNumberOfNodes()));
}
}

View File

@ -57,7 +57,7 @@ struct SubMatching
double confidence;
};
using CandidateList = std::vector<std::pair<double, PhantomNode>>;
using CandidateList = std::vector<PhantomNodeWithDistance>;
using CandidateLists = std::vector<CandidateList>;
using HMM = HiddenMarkovModel<CandidateLists>;
using SubMatchingList = std::vector<SubMatching>;
@ -232,7 +232,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
// how likely is candidate s_prime at time t to be emitted?
// FIXME this can be pre-computed
const double emission_pr =
emission_log_probability(candidates_list[t][s_prime].first);
emission_log_probability(candidates_list[t][s_prime].distance);
double new_value = prev_viterbi[s] + emission_pr;
if (current_viterbi[s_prime] > new_value)
{
@ -244,8 +244,8 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
// get distance diff between loc1/2 and locs/s_prime
const auto network_distance = super::get_network_distance(
forward_heap, reverse_heap, prev_unbroken_timestamps_list[s].second,
current_timestamps_list[s_prime].second);
forward_heap, reverse_heap, prev_unbroken_timestamps_list[s].phantom_node,
current_timestamps_list[s_prime].phantom_node);
const auto d_t = std::abs(network_distance - haversine_distance);
@ -365,7 +365,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
const auto location_index = reconstructed_indices[i].second;
matching.indices[i] = timestamp_index;
matching.nodes[i] = candidates_list[timestamp_index][location_index].second;
matching.nodes[i] = candidates_list[timestamp_index][location_index].phantom_node;
matching.length += model.path_lengths[timestamp_index][location_index];
matching_debug.add_chosen(timestamp_index, location_index);

View File

@ -93,13 +93,13 @@ template <class EdgeDataT> class BaseDataFacade
virtual TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0;
virtual std::vector<std::pair<double, PhantomNode>>
virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate,
const float max_distance,
const int bearing = 0,
const int bearing_range = 180) = 0;
virtual std::vector<std::pair<double, PhantomNode>>
virtual std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const FixedPointCoordinate &input_coordinate,
const unsigned max_results,
const int bearing = 0,

View File

@ -360,7 +360,7 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
}
std::vector<std::pair<double, PhantomNode>>
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate,
const float max_distance,
const int bearing = 0,
@ -375,7 +375,7 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance, bearing, bearing_range);
}
std::vector<std::pair<double, PhantomNode>>
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const FixedPointCoordinate &input_coordinate,
const unsigned max_results,
const int bearing = 0,

View File

@ -40,6 +40,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../util/make_unique.hpp"
#include "../../util/simple_logger.hpp"
#include <boost/thread.hpp>
#include <algorithm>
#include <limits>
#include <memory>
@ -382,7 +384,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
return m_travel_mode_list.at(id);
}
std::vector<std::pair<double, PhantomNode>>
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate,
const float max_distance,
const int bearing = 0,
@ -397,7 +399,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance, bearing, bearing_range);
}
std::vector<std::pair<double, PhantomNode>>
std::vector<PhantomNodeWithDistance>
NearestPhantomNodes(const FixedPointCoordinate &input_coordinate,
const unsigned max_results,
const int bearing = 0,

View File

@ -62,8 +62,8 @@ struct MatchingDebugInfo
osrm::json::Object state;
state.values["transitions"] = osrm::json::Array();
state.values["coordinate"] =
osrm::json::make_array(elem_s.second.location.lat / COORDINATE_PRECISION,
elem_s.second.location.lon / COORDINATE_PRECISION);
osrm::json::make_array(elem_s.phantom_node.location.lat / COORDINATE_PRECISION,
elem_s.phantom_node.location.lon / COORDINATE_PRECISION);
state.values["viterbi"] =
osrm::json::clamp_float(osrm::matching::IMPOSSIBLE_LOG_PROB);
state.values["pruned"] = 0u;