Reduce source/targets to a single phantom node based on the small/big components that are present.
This commit is contained in:
parent
9414a8085d
commit
f3f153cb38
@ -175,11 +175,15 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
|
||||
phantom_node_target_out_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_ASSERT((phantom_node_source_out_iter - phantom_node_source_vector.begin()) ==
|
||||
number_of_sources);
|
||||
BOOST_ASSERT((phantom_node_target_out_iter - phantom_node_target_vector.begin()) ==
|
||||
number_of_destination);
|
||||
|
||||
snapPhantomNodes(phantom_node_source_vector);
|
||||
snapPhantomNodes(phantom_node_target_vector);
|
||||
|
||||
std::shared_ptr<std::vector<EdgeWeight>> result_table = search_engine_ptr->distance_table(
|
||||
phantom_node_source_vector, phantom_node_target_vector);
|
||||
|
||||
|
@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef BASE_PLUGIN_HPP
|
||||
#define BASE_PLUGIN_HPP
|
||||
|
||||
#include "../data_structures/phantom_node.hpp"
|
||||
|
||||
#include <osrm/coordinate.hpp>
|
||||
#include <osrm/json_container.hpp>
|
||||
#include <osrm/route_parameters.hpp>
|
||||
@ -57,6 +59,53 @@ class BasePlugin
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Decides whether to use the phantom node from a big or small component if both are found.
|
||||
// Returns true if all phantom nodes are in the same component after snapping.
|
||||
bool snapPhantomNodes(std::vector<std::pair<PhantomNode, PhantomNode>> &phantom_node_pair_list) const
|
||||
{
|
||||
const auto check_component_id_is_tiny = [](const std::pair<PhantomNode, PhantomNode> &phantom_pair)
|
||||
{
|
||||
return phantom_pair.first.component.is_tiny;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
// are all phantoms from a tiny cc?
|
||||
const auto check_all_in_same_component = [](const std::vector<std::pair<PhantomNode, PhantomNode>> &nodes)
|
||||
{
|
||||
const auto component_id = nodes.front().first.component.id;
|
||||
|
||||
return std::all_of(std::begin(nodes), std::end(nodes),
|
||||
[component_id](const PhantomNodePair &phantom_pair)
|
||||
{
|
||||
return component_id == phantom_pair.first.component.id;
|
||||
});
|
||||
};
|
||||
|
||||
auto swap_phantom_from_big_cc_into_front = [](std::pair<PhantomNode, PhantomNode> &phantom_pair)
|
||||
{
|
||||
if (phantom_pair.first.component.is_tiny && phantom_pair.second.is_valid() && !phantom_pair.second.component.is_tiny)
|
||||
{
|
||||
using namespace std;
|
||||
swap(phantom_pair.first, phantom_pair.second);
|
||||
}
|
||||
};
|
||||
|
||||
auto all_in_same_component = check_all_in_same_component(phantom_node_pair_list);
|
||||
|
||||
// this case is true if we take phantoms from the big CC
|
||||
if (every_phantom_is_in_tiny_cc && !all_in_same_component)
|
||||
{
|
||||
std::for_each(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
|
||||
swap_phantom_from_big_cc_into_front);
|
||||
|
||||
// update check with new component ids
|
||||
all_in_same_component = check_all_in_same_component(phantom_node_pair_list);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* BASE_PLUGIN_HPP */
|
||||
|
@ -115,47 +115,7 @@ template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
|
||||
BOOST_ASSERT(phantom_node_pair_list[i].second.is_valid(facade->GetNumberOfNodes()));
|
||||
}
|
||||
|
||||
const auto check_component_id_is_tiny = [](const PhantomNodePair &phantom_pair)
|
||||
{
|
||||
return phantom_pair.first.component.is_tiny;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
// are all phantoms from a tiny cc?
|
||||
const auto check_all_in_same_component = [](const std::vector<PhantomNodePair> &nodes)
|
||||
{
|
||||
const auto component_id = nodes.front().first.component.id;
|
||||
|
||||
return std::all_of(std::begin(nodes), std::end(nodes),
|
||||
[component_id](const PhantomNodePair &phantom_pair)
|
||||
{
|
||||
return component_id == phantom_pair.first.component.id;
|
||||
});
|
||||
};
|
||||
|
||||
auto swap_phantom_from_big_cc_into_front = [](PhantomNodePair &phantom_pair)
|
||||
{
|
||||
if (phantom_pair.first.component.is_tiny && phantom_pair.second.is_valid() && !phantom_pair.second.component.is_tiny)
|
||||
{
|
||||
using namespace std;
|
||||
swap(phantom_pair.first, phantom_pair.second);
|
||||
}
|
||||
};
|
||||
|
||||
auto all_in_same_component = check_all_in_same_component(phantom_node_pair_list);
|
||||
|
||||
// this case is true if we take phantoms from the big CC
|
||||
if (every_phantom_is_in_tiny_cc && !all_in_same_component)
|
||||
{
|
||||
std::for_each(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
|
||||
swap_phantom_from_big_cc_into_front);
|
||||
|
||||
// update check with new component ids
|
||||
all_in_same_component = check_all_in_same_component(phantom_node_pair_list);
|
||||
}
|
||||
auto all_in_same_component = snapPhantomNodes(phantom_node_pair_list);
|
||||
|
||||
InternalRouteResult raw_route;
|
||||
auto build_phantom_pairs =
|
||||
|
Loading…
Reference in New Issue
Block a user