2017-08-20 19:24:05 -04:00
|
|
|
#include "contractor/contractor_search.hpp"
|
|
|
|
|
|
|
|
#include "contractor/contractor_graph.hpp"
|
|
|
|
#include "contractor/contractor_heap.hpp"
|
2017-01-13 02:32:17 -05:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace contractor
|
|
|
|
{
|
|
|
|
|
2017-08-20 19:24:05 -04:00
|
|
|
namespace
|
2017-01-13 02:32:17 -05:00
|
|
|
{
|
2017-08-20 19:24:05 -04:00
|
|
|
void relaxNode(ContractorHeap &heap,
|
|
|
|
const ContractorGraph &graph,
|
|
|
|
const NodeID node,
|
|
|
|
const EdgeWeight node_weight,
|
|
|
|
const NodeID forbidden_node)
|
2017-01-13 02:32:17 -05:00
|
|
|
{
|
|
|
|
const short current_hop = heap.GetData(node).hop + 1;
|
|
|
|
for (auto edge : graph.GetAdjacentEdgeRange(node))
|
|
|
|
{
|
2017-08-20 19:24:05 -04:00
|
|
|
const auto &data = graph.GetEdgeData(edge);
|
2017-01-13 02:32:17 -05:00
|
|
|
if (!data.forward)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const NodeID to = graph.GetTarget(edge);
|
2017-08-20 19:24:05 -04:00
|
|
|
BOOST_ASSERT(to != SPECIAL_NODEID);
|
2017-01-13 02:32:17 -05:00
|
|
|
if (forbidden_node == to)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-12 12:50:10 -04:00
|
|
|
const EdgeWeight to_weight = node_weight + data.weight;
|
2017-01-13 02:32:17 -05:00
|
|
|
|
2020-11-25 05:22:30 -05:00
|
|
|
const auto toHeapNode= heap.GetHeapNodeIfWasInserted(to);
|
2017-01-13 02:32:17 -05:00
|
|
|
// New Node discovered -> Add to Heap + Node Info Storage
|
2020-11-23 16:33:08 -05:00
|
|
|
if (!toHeapNode)
|
2017-01-13 02:32:17 -05:00
|
|
|
{
|
|
|
|
heap.Insert(to, to_weight, ContractorHeapData{current_hop, false});
|
|
|
|
}
|
|
|
|
// Found a shorter Path -> Update weight
|
2020-11-23 16:33:08 -05:00
|
|
|
else if (to_weight < toHeapNode->weight)
|
2017-01-13 02:32:17 -05:00
|
|
|
{
|
2020-11-23 16:33:08 -05:00
|
|
|
toHeapNode->weight=to_weight;
|
|
|
|
heap.DecreaseKey(*toHeapNode);
|
|
|
|
toHeapNode->data.hop = current_hop;
|
2017-01-13 02:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-20 19:24:05 -04:00
|
|
|
}
|
2017-01-13 02:32:17 -05:00
|
|
|
|
2017-08-20 19:24:05 -04:00
|
|
|
void search(ContractorHeap &heap,
|
|
|
|
const ContractorGraph &graph,
|
|
|
|
const unsigned number_of_targets,
|
|
|
|
const int node_limit,
|
|
|
|
const EdgeWeight weight_limit,
|
|
|
|
const NodeID forbidden_node)
|
|
|
|
{
|
|
|
|
int nodes = 0;
|
|
|
|
unsigned number_of_targets_found = 0;
|
|
|
|
while (!heap.Empty())
|
|
|
|
{
|
|
|
|
const NodeID node = heap.DeleteMin();
|
|
|
|
BOOST_ASSERT(node != SPECIAL_NODEID);
|
|
|
|
const auto node_weight = heap.GetKey(node);
|
|
|
|
if (++nodes > node_limit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (node_weight > weight_limit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-01-13 02:32:17 -05:00
|
|
|
|
2017-08-20 19:24:05 -04:00
|
|
|
// Destination settled?
|
|
|
|
if (heap.GetData(node).target)
|
|
|
|
{
|
|
|
|
++number_of_targets_found;
|
|
|
|
if (number_of_targets_found >= number_of_targets)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-01-13 02:32:17 -05:00
|
|
|
|
2017-08-20 19:24:05 -04:00
|
|
|
relaxNode(heap, graph, node, node_weight, forbidden_node);
|
|
|
|
}
|
|
|
|
}
|
2017-01-13 02:32:17 -05:00
|
|
|
}
|
|
|
|
}
|