use tiny cc id if all phantoms have such an id, and if and only if all ids are equal
This commit is contained in:
parent
55d47b3e31
commit
fa5c0560fa
@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef VIA_ROUTE_PLUGIN_H
|
#ifndef VIA_ROUTE_HPP
|
||||||
#define VIA_ROUTE_PLUGIN_H
|
#define VIA_ROUTE_HPP
|
||||||
|
|
||||||
#include "plugin_base.hpp"
|
#include "plugin_base.hpp"
|
||||||
|
|
||||||
@ -88,14 +88,17 @@ template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
|
|||||||
for (const auto i : osrm::irange<std::size_t>(0, route_parameters.coordinates.size()))
|
for (const auto i : osrm::irange<std::size_t>(0, route_parameters.coordinates.size()))
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << "[" << i << "] checking coordinate";
|
SimpleLogger().Write() << "[" << i << "] checking coordinate";
|
||||||
SimpleLogger().Write() << "route_parameters.hints.size()" << route_parameters.hints.size();
|
SimpleLogger().Write() << "route_parameters.hints.size() "
|
||||||
|
<< route_parameters.hints.size();
|
||||||
|
|
||||||
|
// TODO: Remove hinting mechanism
|
||||||
if (checksum_OK && i < route_parameters.hints.size() &&
|
if (checksum_OK && i < route_parameters.hints.size() &&
|
||||||
!route_parameters.hints[i].empty())
|
!route_parameters.hints[i].empty())
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << "decoding hint " << i;
|
SimpleLogger().Write() << "decoding hint " << i;
|
||||||
|
|
||||||
ObjectEncoder::DecodeFromBase64(route_parameters.hints[i], phantom_node_pair_list[i]);
|
ObjectEncoder::DecodeFromBase64(route_parameters.hints[i],
|
||||||
|
phantom_node_pair_list[i]);
|
||||||
if (phantom_node_pair_list[i].first.is_valid(facade->GetNumberOfNodes()))
|
if (phantom_node_pair_list[i].first.is_valid(facade->GetNumberOfNodes()))
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << "decoded PhantomNode";
|
SimpleLogger().Write() << "decoded PhantomNode";
|
||||||
@ -106,8 +109,7 @@ template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
|
|||||||
SimpleLogger().Write() << "finding coordinate";
|
SimpleLogger().Write() << "finding coordinate";
|
||||||
|
|
||||||
if (facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates[i],
|
if (facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates[i],
|
||||||
phantom_node_vector,
|
phantom_node_vector, 1))
|
||||||
1))
|
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << "found first PhantomNode" << phantom_node_vector.front();
|
SimpleLogger().Write() << "found first PhantomNode" << phantom_node_vector.front();
|
||||||
|
|
||||||
@ -115,37 +117,85 @@ template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
|
|||||||
phantom_node_pair_list[i].first = phantom_node_vector.front();
|
phantom_node_pair_list[i].first = phantom_node_vector.front();
|
||||||
if (phantom_node_vector.size() > 1)
|
if (phantom_node_vector.size() > 1)
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << "found second PhantomNode" << phantom_node_vector.back();
|
SimpleLogger().Write() << "found second PhantomNode"
|
||||||
|
<< phantom_node_vector.back();
|
||||||
phantom_node_pair_list[i].second = phantom_node_vector.back();
|
phantom_node_pair_list[i].second = phantom_node_vector.back();
|
||||||
}
|
}
|
||||||
} else {
|
// } else {
|
||||||
SimpleLogger().Write() << "found no PhantomNode";
|
// SimpleLogger().Write() << "found no PhantomNode";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: - if all PhantomNodes are from same tiny cc then take those
|
// TODO: - if all PhantomNodes are from same tiny cc then take those
|
||||||
// - otherwise take all from big component.
|
// - otherwise take all from big component.
|
||||||
// - rotate results into phantom_node_pair.first
|
// - rotate results into phantom_node_pair.first
|
||||||
|
|
||||||
RawRouteData raw_route;
|
auto check_component_id_is_tiny = [](const phantom_node_pair &phantom_pair)
|
||||||
auto build_phantom_pairs = [&raw_route] (const phantom_node_pair &first_pair, const phantom_node_pair &second_pair)
|
|
||||||
{
|
{
|
||||||
raw_route.segment_end_coordinates.emplace_back(PhantomNodes{first_pair.first, second_pair.first});
|
return phantom_pair.first.component_id != 0;
|
||||||
SimpleLogger().Write() << "emplaced: " << raw_route.segment_end_coordinates.back().source_phantom;
|
};
|
||||||
SimpleLogger().Write() << " " << raw_route.segment_end_coordinates.back().target_phantom;
|
|
||||||
|
const bool every_phantom_is_in_tiny_cc =
|
||||||
|
std::all_of(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
|
||||||
|
check_component_id_is_tiny);
|
||||||
|
SimpleLogger().Write() << "every_phantom_is_in_tiny_cc: "
|
||||||
|
<< (every_phantom_is_in_tiny_cc ? "y" : "n");
|
||||||
|
|
||||||
|
// are all phantoms from a tiny cc?
|
||||||
|
const auto component_id = phantom_node_pair_list.front().first.component_id;
|
||||||
|
BOOST_ASSERT(0 != component_id);
|
||||||
|
|
||||||
|
auto check_component_id_is_equal = [component_id](const phantom_node_pair &phantom_pair)
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(0 != phantom_pair.first.component_id);
|
||||||
|
return component_id == phantom_pair.first.component_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
const bool every_phantom_has_equal_id =
|
||||||
|
std::all_of(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
|
||||||
|
check_component_id_is_equal);
|
||||||
|
|
||||||
|
SimpleLogger().Write() << "every_phantom_has_equal_id: "
|
||||||
|
<< (every_phantom_has_equal_id ? "y" : "n");
|
||||||
|
|
||||||
|
auto swap_phantom_from_big_cc_into_front = [](phantom_node_pair &phantom_pair)
|
||||||
|
{
|
||||||
|
if (0 != phantom_pair.first.component_id)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
swap(phantom_pair.first, phantom_pair.second);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// this case is true if we take phantoms from the big CC
|
||||||
|
if (!every_phantom_is_in_tiny_cc || !every_phantom_has_equal_id)
|
||||||
|
{
|
||||||
|
std::for_each(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
|
||||||
|
swap_phantom_from_big_cc_into_front);
|
||||||
|
}
|
||||||
|
|
||||||
|
RawRouteData raw_route;
|
||||||
|
auto build_phantom_pairs =
|
||||||
|
[&raw_route](const phantom_node_pair &first_pair, const phantom_node_pair &second_pair)
|
||||||
|
{
|
||||||
|
raw_route.segment_end_coordinates.emplace_back(
|
||||||
|
PhantomNodes{first_pair.first, second_pair.first});
|
||||||
|
SimpleLogger().Write()
|
||||||
|
<< "emplaced: " << raw_route.segment_end_coordinates.back().source_phantom;
|
||||||
|
SimpleLogger().Write() << " "
|
||||||
|
<< raw_route.segment_end_coordinates.back().target_phantom;
|
||||||
};
|
};
|
||||||
osrm::for_each_pair(phantom_node_pair_list, build_phantom_pairs);
|
osrm::for_each_pair(phantom_node_pair_list, build_phantom_pairs);
|
||||||
|
|
||||||
if (route_parameters.alternate_route &&
|
if (route_parameters.alternate_route && 1 == raw_route.segment_end_coordinates.size())
|
||||||
1 == raw_route.segment_end_coordinates.size())
|
|
||||||
{
|
{
|
||||||
search_engine_ptr->alternative_path(
|
search_engine_ptr->alternative_path(raw_route.segment_end_coordinates.front(),
|
||||||
raw_route.segment_end_coordinates.front(), raw_route);
|
raw_route);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
search_engine_ptr->shortest_path(
|
search_engine_ptr->shortest_path(raw_route.segment_end_coordinates,
|
||||||
raw_route.segment_end_coordinates, route_parameters.uturns, raw_route);
|
route_parameters.uturns, raw_route);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (INVALID_EDGE_WEIGHT == raw_route.shortest_path_length)
|
if (INVALID_EDGE_WEIGHT == raw_route.shortest_path_length)
|
||||||
@ -172,4 +222,4 @@ template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VIA_ROUTE_PLUGIN_H
|
#endif // VIA_ROUTE_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user