refactor list of const static int into scoped enum
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BASICROUTINGINTERFACE_H_
|
||||
#define BASICROUTINGINTERFACE_H_
|
||||
#ifndef BASIC_ROUTING_INTERFACE_H
|
||||
#define BASIC_ROUTING_INTERFACE_H
|
||||
|
||||
#include "../DataStructures/RawRouteData.h"
|
||||
#include "../DataStructures/SearchEngineData.h"
|
||||
@@ -35,7 +35,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "../Util/SimpleLogger.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <stack>
|
||||
|
||||
@@ -46,30 +45,32 @@ SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap2;
|
||||
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap3;
|
||||
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3;
|
||||
|
||||
template<class DataFacadeT>
|
||||
class BasicRoutingInterface : boost::noncopyable {
|
||||
private:
|
||||
template <class DataFacadeT> class BasicRoutingInterface
|
||||
{
|
||||
private:
|
||||
typedef typename DataFacadeT::EdgeData EdgeData;
|
||||
protected:
|
||||
DataFacadeT * facade;
|
||||
public:
|
||||
explicit BasicRoutingInterface( DataFacadeT * facade ) : facade(facade) { }
|
||||
virtual ~BasicRoutingInterface(){ };
|
||||
|
||||
inline void RoutingStep(
|
||||
SearchEngineData::QueryHeap & forward_heap,
|
||||
SearchEngineData::QueryHeap & reverse_heap,
|
||||
NodeID * middle_node_id,
|
||||
int * upper_bound,
|
||||
const bool forward_direction
|
||||
) const
|
||||
protected:
|
||||
DataFacadeT *facade;
|
||||
|
||||
public:
|
||||
BasicRoutingInterface() = delete;
|
||||
BasicRoutingInterface(const BasicRoutingInterface &) = delete;
|
||||
explicit BasicRoutingInterface(DataFacadeT *facade) : facade(facade) {}
|
||||
virtual ~BasicRoutingInterface() {};
|
||||
|
||||
inline void RoutingStep(SearchEngineData::QueryHeap &forward_heap,
|
||||
SearchEngineData::QueryHeap &reverse_heap,
|
||||
NodeID *middle_node_id,
|
||||
int *upper_bound,
|
||||
const bool forward_direction) const
|
||||
{
|
||||
const NodeID node = forward_heap.DeleteMin();
|
||||
const int distance = forward_heap.GetKey(node);
|
||||
if (reverse_heap.WasInserted(node))
|
||||
{
|
||||
const int new_distance = reverse_heap.GetKey(node) + distance;
|
||||
if(new_distance < *upper_bound )
|
||||
if (new_distance < *upper_bound)
|
||||
{
|
||||
if (new_distance >= 0)
|
||||
{
|
||||
@@ -85,10 +86,10 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
//Stalling
|
||||
for (EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge)
|
||||
// Stalling
|
||||
for (EdgeID edge = facade->BeginEdges(node); edge < facade->EndEdges(node); ++edge)
|
||||
{
|
||||
const EdgeData & data = facade->GetEdgeData(edge);
|
||||
const EdgeData &data = facade->GetEdgeData(edge);
|
||||
const bool reverse_flag = ((!forward_direction) ? data.forward : data.backward);
|
||||
if (reverse_flag)
|
||||
{
|
||||
@@ -99,7 +100,7 @@ public:
|
||||
|
||||
if (forward_heap.WasInserted(to))
|
||||
{
|
||||
if(forward_heap.GetKey( to ) + edge_weight < distance)
|
||||
if (forward_heap.GetKey(to) + edge_weight < distance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -107,9 +108,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
for (EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node); edge < end_edge; ++edge)
|
||||
for (EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node);
|
||||
edge < end_edge;
|
||||
++edge)
|
||||
{
|
||||
const EdgeData & data = facade->GetEdgeData(edge);
|
||||
const EdgeData &data = facade->GetEdgeData(edge);
|
||||
bool forward_directionFlag = (forward_direction ? data.forward : data.backward);
|
||||
if (forward_directionFlag)
|
||||
{
|
||||
@@ -117,36 +120,41 @@ public:
|
||||
const NodeID to = facade->GetTarget(edge);
|
||||
const int edge_weight = data.distance;
|
||||
|
||||
BOOST_ASSERT_MSG( edge_weight > 0, "edge_weight invalid" );
|
||||
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
|
||||
const int to_distance = distance + edge_weight;
|
||||
|
||||
//New Node discovered -> Add to Heap + Node Info Storage
|
||||
if ( !forward_heap.WasInserted( to ) ) {
|
||||
forward_heap.Insert( to, to_distance, node );
|
||||
// New Node discovered -> Add to Heap + Node Info Storage
|
||||
if (!forward_heap.WasInserted(to))
|
||||
{
|
||||
forward_heap.Insert(to, to_distance, node);
|
||||
}
|
||||
//Found a shorter Path -> Update distance
|
||||
else if ( to_distance < forward_heap.GetKey( to ) ) {
|
||||
//new parent
|
||||
forward_heap.GetData( to ).parent = node;
|
||||
forward_heap.DecreaseKey( to, to_distance );
|
||||
// Found a shorter Path -> Update distance
|
||||
else if (to_distance < forward_heap.GetKey(to))
|
||||
{
|
||||
// new parent
|
||||
forward_heap.GetData(to).parent = node;
|
||||
forward_heap.DecreaseKey(to, to_distance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void UnpackPath(const std::vector<NodeID> & packed_path, const PhantomNodes & phantom_node_pair, std::vector<PathData> & unpacked_path) const
|
||||
inline void UnpackPath(const std::vector<NodeID> &packed_path,
|
||||
const PhantomNodes &phantom_node_pair,
|
||||
std::vector<PathData> &unpacked_path) const
|
||||
{
|
||||
const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.source_phantom.forward_node_id);
|
||||
const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.target_phantom.forward_node_id);
|
||||
const bool start_traversed_in_reverse =
|
||||
(packed_path.front() != phantom_node_pair.source_phantom.forward_node_id);
|
||||
const bool target_traversed_in_reverse =
|
||||
(packed_path.back() != phantom_node_pair.target_phantom.forward_node_id);
|
||||
|
||||
const unsigned packed_path_size = packed_path.size();
|
||||
std::stack<std::pair<NodeID, NodeID> > recursion_stack;
|
||||
std::stack<std::pair<NodeID, NodeID>> recursion_stack;
|
||||
|
||||
//We have to push the path in reverse order onto the stack because it's LIFO.
|
||||
for(unsigned i = packed_path_size-1; i > 0; --i){
|
||||
recursion_stack.push(
|
||||
std::make_pair(packed_path[i-1], packed_path[i])
|
||||
);
|
||||
// We have to push the path in reverse order onto the stack because it's LIFO.
|
||||
for (unsigned i = packed_path_size - 1; i > 0; --i)
|
||||
{
|
||||
recursion_stack.emplace(packed_path[i - 1], packed_path[i]);
|
||||
}
|
||||
|
||||
std::pair<NodeID, NodeID> edge;
|
||||
@@ -159,11 +167,12 @@ public:
|
||||
// The above explanation unclear? Think!
|
||||
EdgeID smaller_edge_id = SPECIAL_EDGEID;
|
||||
int edge_weight = INT_MAX;
|
||||
for (EdgeID edge_id = facade->BeginEdges(edge.first); edge_id < facade->EndEdges(edge.first); ++edge_id)
|
||||
for (EdgeID edge_id = facade->BeginEdges(edge.first);
|
||||
edge_id < facade->EndEdges(edge.first);
|
||||
++edge_id)
|
||||
{
|
||||
const int weight = facade->GetEdgeData(edge_id).distance;
|
||||
if ((facade->GetTarget(edge_id) == edge.second) &&
|
||||
(weight < edge_weight) &&
|
||||
if ((facade->GetTarget(edge_id) == edge.second) && (weight < edge_weight) &&
|
||||
facade->GetEdgeData(edge_id).forward)
|
||||
{
|
||||
smaller_edge_id = edge_id;
|
||||
@@ -172,10 +181,13 @@ public:
|
||||
}
|
||||
if (SPECIAL_EDGEID == smaller_edge_id)
|
||||
{
|
||||
for (EdgeID edge_id = facade->BeginEdges(edge.second); edge_id < facade->EndEdges(edge.second); ++edge_id)
|
||||
for (EdgeID edge_id = facade->BeginEdges(edge.second);
|
||||
edge_id < facade->EndEdges(edge.second);
|
||||
++edge_id)
|
||||
{
|
||||
const int weight = facade->GetEdgeData(edge_id).distance;
|
||||
if ((facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) && facade->GetEdgeData(edge_id).backward)
|
||||
if ((facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) &&
|
||||
facade->GetEdgeData(edge_id).backward)
|
||||
{
|
||||
smaller_edge_id = edge_id;
|
||||
edge_weight = weight;
|
||||
@@ -184,13 +196,13 @@ public:
|
||||
}
|
||||
BOOST_ASSERT_MSG(edge_weight != INVALID_EDGE_WEIGHT, "edge id invalid");
|
||||
|
||||
const EdgeData & ed = facade->GetEdgeData(smaller_edge_id);
|
||||
const EdgeData &ed = facade->GetEdgeData(smaller_edge_id);
|
||||
if (ed.shortcut)
|
||||
{//unpack
|
||||
{ // unpack
|
||||
const NodeID middle_node_id = ed.id;
|
||||
//again, we need to this in reversed order
|
||||
recursion_stack.push(std::make_pair(middle_node_id, edge.second));
|
||||
recursion_stack.push(std::make_pair(edge.first, middle_node_id));
|
||||
// again, we need to this in reversed order
|
||||
recursion_stack.emplace(middle_node_id, edge.second);
|
||||
recursion_stack.emplace(edge.first, middle_node_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -200,36 +212,33 @@ public:
|
||||
|
||||
if (!facade->EdgeIsCompressed(ed.id))
|
||||
{
|
||||
BOOST_ASSERT( !facade->EdgeIsCompressed(ed.id) );
|
||||
unpacked_path.push_back(
|
||||
PathData(
|
||||
facade->GetGeometryIndexForEdgeID(ed.id),
|
||||
name_index,
|
||||
turn_instruction,
|
||||
ed.distance
|
||||
)
|
||||
);
|
||||
BOOST_ASSERT(!facade->EdgeIsCompressed(ed.id));
|
||||
unpacked_path.emplace_back(facade->GetGeometryIndexForEdgeID(ed.id),
|
||||
name_index,
|
||||
turn_instruction,
|
||||
ed.distance);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<unsigned> id_vector;
|
||||
facade->GetUncompressedGeometry(facade->GetGeometryIndexForEdgeID(ed.id), id_vector);
|
||||
facade->GetUncompressedGeometry(facade->GetGeometryIndexForEdgeID(ed.id),
|
||||
id_vector);
|
||||
|
||||
const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1 : phantom_node_pair.source_phantom.fwd_segment_position ) : 0 );
|
||||
const int start_index =
|
||||
(unpacked_path.empty()
|
||||
? ((start_traversed_in_reverse)
|
||||
? id_vector.size() -
|
||||
phantom_node_pair.source_phantom.fwd_segment_position - 1
|
||||
: phantom_node_pair.source_phantom.fwd_segment_position)
|
||||
: 0);
|
||||
const int end_index = id_vector.size();
|
||||
|
||||
BOOST_ASSERT(start_index >= 0);
|
||||
BOOST_ASSERT(start_index <= end_index);
|
||||
for (int i = start_index; i < end_index; ++i)
|
||||
{
|
||||
unpacked_path.push_back(
|
||||
PathData(
|
||||
id_vector[i],
|
||||
name_index,
|
||||
TurnInstructionsClass::NoTurn,
|
||||
0
|
||||
)
|
||||
);
|
||||
unpacked_path.emplace_back(PathData{
|
||||
id_vector[i], name_index, TurnInstruction::NoTurn, 0});
|
||||
}
|
||||
unpacked_path.back().turn_instruction = turn_instruction;
|
||||
unpacked_path.back().segment_duration = ed.distance;
|
||||
@@ -239,18 +248,22 @@ public:
|
||||
if (SPECIAL_EDGEID != phantom_node_pair.target_phantom.packed_geometry_id)
|
||||
{
|
||||
std::vector<unsigned> id_vector;
|
||||
facade->GetUncompressedGeometry(phantom_node_pair.target_phantom.packed_geometry_id, id_vector);
|
||||
facade->GetUncompressedGeometry(phantom_node_pair.target_phantom.packed_geometry_id,
|
||||
id_vector);
|
||||
if (target_traversed_in_reverse)
|
||||
{
|
||||
std::reverse(id_vector.begin(), id_vector.end() );
|
||||
std::reverse(id_vector.begin(), id_vector.end());
|
||||
}
|
||||
const bool is_local_path = (phantom_node_pair.source_phantom.packed_geometry_id == phantom_node_pair.target_phantom.packed_geometry_id) && unpacked_path.empty();
|
||||
const bool is_local_path = (phantom_node_pair.source_phantom.packed_geometry_id ==
|
||||
phantom_node_pair.target_phantom.packed_geometry_id) &&
|
||||
unpacked_path.empty();
|
||||
|
||||
int start_index = 0;
|
||||
int end_index = phantom_node_pair.target_phantom.fwd_segment_position;
|
||||
if (target_traversed_in_reverse)
|
||||
{
|
||||
end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position;
|
||||
end_index =
|
||||
id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position;
|
||||
}
|
||||
if (is_local_path)
|
||||
{
|
||||
@@ -258,23 +271,21 @@ public:
|
||||
end_index = phantom_node_pair.target_phantom.fwd_segment_position;
|
||||
if (target_traversed_in_reverse)
|
||||
{
|
||||
start_index = id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position;
|
||||
end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position;
|
||||
start_index =
|
||||
id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position;
|
||||
end_index =
|
||||
id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_ASSERT(start_index >= 0);
|
||||
for (int i = start_index; i != end_index; (start_index < end_index ? ++i :--i))
|
||||
for (int i = start_index; i != end_index; (start_index < end_index ? ++i : --i))
|
||||
{
|
||||
BOOST_ASSERT( i >= -1 );
|
||||
unpacked_path.push_back(
|
||||
PathData(
|
||||
id_vector[i],
|
||||
phantom_node_pair.target_phantom.name_id,
|
||||
TurnInstructionsClass::NoTurn,
|
||||
0
|
||||
)
|
||||
);
|
||||
BOOST_ASSERT(i >= -1);
|
||||
unpacked_path.emplace_back(PathData{id_vector[i],
|
||||
phantom_node_pair.target_phantom.name_id,
|
||||
TurnInstruction::NoTurn,
|
||||
0});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,10 +296,10 @@ public:
|
||||
// the last node.
|
||||
if (unpacked_path.size() > 1)
|
||||
{
|
||||
const unsigned last_index = unpacked_path.size()-1;
|
||||
const unsigned second_to_last_index = last_index -1;
|
||||
const unsigned last_index = unpacked_path.size() - 1;
|
||||
const unsigned second_to_last_index = last_index - 1;
|
||||
|
||||
//looks like a trivially true check but tests for underflow
|
||||
// looks like a trivially true check but tests for underflow
|
||||
BOOST_ASSERT(last_index > second_to_last_index);
|
||||
|
||||
if (unpacked_path[last_index].node == unpacked_path[second_to_last_index].node)
|
||||
@@ -299,10 +310,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
inline void UnpackEdge(const NodeID s, const NodeID t, std::vector<NodeID> & unpacked_path) const
|
||||
inline void UnpackEdge(const NodeID s, const NodeID t, std::vector<NodeID> &unpacked_path) const
|
||||
{
|
||||
std::stack<std::pair<NodeID, NodeID> > recursion_stack;
|
||||
recursion_stack.push(std::make_pair(s,t));
|
||||
std::stack<std::pair<NodeID, NodeID>> recursion_stack;
|
||||
recursion_stack.emplace(s, t);
|
||||
|
||||
std::pair<NodeID, NodeID> edge;
|
||||
while (!recursion_stack.empty())
|
||||
@@ -312,14 +323,14 @@ public:
|
||||
|
||||
EdgeID smaller_edge_id = SPECIAL_EDGEID;
|
||||
int edge_weight = INT_MAX;
|
||||
for (EdgeID edge_id = facade->BeginEdges(edge.first); edge_id < facade->EndEdges(edge.first); ++edge_id)
|
||||
for (EdgeID edge_id = facade->BeginEdges(edge.first);
|
||||
edge_id < facade->EndEdges(edge.first);
|
||||
++edge_id)
|
||||
{
|
||||
const int weight = facade->GetEdgeData(edge_id).distance;
|
||||
if(
|
||||
(facade->GetTarget(edge_id) == edge.second) &&
|
||||
(weight < edge_weight) &&
|
||||
facade->GetEdgeData(edge_id).forward
|
||||
){
|
||||
if ((facade->GetTarget(edge_id) == edge.second) && (weight < edge_weight) &&
|
||||
facade->GetEdgeData(edge_id).forward)
|
||||
{
|
||||
smaller_edge_id = edge_id;
|
||||
edge_weight = weight;
|
||||
}
|
||||
@@ -327,10 +338,13 @@ public:
|
||||
|
||||
if (SPECIAL_EDGEID == smaller_edge_id)
|
||||
{
|
||||
for (EdgeID edge_id = facade->BeginEdges(edge.second); edge_id < facade->EndEdges(edge.second); ++edge_id)
|
||||
for (EdgeID edge_id = facade->BeginEdges(edge.second);
|
||||
edge_id < facade->EndEdges(edge.second);
|
||||
++edge_id)
|
||||
{
|
||||
const int weight = facade->GetEdgeData(edge_id).distance;
|
||||
if ((facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) && facade->GetEdgeData(edge_id).backward)
|
||||
if ((facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) &&
|
||||
facade->GetEdgeData(edge_id).backward)
|
||||
{
|
||||
smaller_edge_id = edge_id;
|
||||
edge_weight = weight;
|
||||
@@ -339,59 +353,55 @@ public:
|
||||
}
|
||||
BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid");
|
||||
|
||||
const EdgeData& ed = facade->GetEdgeData(smaller_edge_id);
|
||||
const EdgeData &ed = facade->GetEdgeData(smaller_edge_id);
|
||||
if (ed.shortcut)
|
||||
{//unpack
|
||||
{ // unpack
|
||||
const NodeID middle_node_id = ed.id;
|
||||
//again, we need to this in reversed order
|
||||
recursion_stack.push(std::make_pair(middle_node_id, edge.second));
|
||||
recursion_stack.push(std::make_pair(edge.first, middle_node_id));
|
||||
// again, we need to this in reversed order
|
||||
recursion_stack.emplace(middle_node_id, edge.second);
|
||||
recursion_stack.emplace(edge.first, middle_node_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ASSERT_MSG(!ed.shortcut, "edge must be shortcut");
|
||||
unpacked_path.push_back(edge.first );
|
||||
unpacked_path.emplace_back(edge.first);
|
||||
}
|
||||
}
|
||||
unpacked_path.push_back(t);
|
||||
unpacked_path.emplace_back(t);
|
||||
}
|
||||
|
||||
inline void RetrievePackedPathFromHeap(
|
||||
const SearchEngineData::QueryHeap & forward_heap,
|
||||
const SearchEngineData::QueryHeap & reverse_heap,
|
||||
const NodeID middle_node_id,
|
||||
std::vector<NodeID> & packed_path
|
||||
) const
|
||||
inline void RetrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap,
|
||||
const SearchEngineData::QueryHeap &reverse_heap,
|
||||
const NodeID middle_node_id,
|
||||
std::vector<NodeID> &packed_path) const
|
||||
{
|
||||
NodeID current_node_id = middle_node_id;
|
||||
while(current_node_id != forward_heap.GetData(current_node_id).parent)
|
||||
while (current_node_id != forward_heap.GetData(current_node_id).parent)
|
||||
{
|
||||
current_node_id = forward_heap.GetData(current_node_id).parent;
|
||||
packed_path.push_back(current_node_id);
|
||||
packed_path.emplace_back(current_node_id);
|
||||
}
|
||||
std::reverse(packed_path.begin(), packed_path.end());
|
||||
packed_path.push_back(middle_node_id);
|
||||
packed_path.emplace_back(middle_node_id);
|
||||
current_node_id = middle_node_id;
|
||||
while (current_node_id != reverse_heap.GetData(current_node_id).parent)
|
||||
{
|
||||
current_node_id = reverse_heap.GetData(current_node_id).parent;
|
||||
packed_path.push_back(current_node_id);
|
||||
}
|
||||
packed_path.emplace_back(current_node_id);
|
||||
}
|
||||
}
|
||||
|
||||
inline void RetrievePackedPathFromSingleHeap(
|
||||
const SearchEngineData::QueryHeap & search_heap,
|
||||
const NodeID middle_node_id,
|
||||
std::vector<NodeID>& packed_path
|
||||
) const
|
||||
inline void RetrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_heap,
|
||||
const NodeID middle_node_id,
|
||||
std::vector<NodeID> &packed_path) const
|
||||
{
|
||||
NodeID current_node_id = middle_node_id;
|
||||
while(current_node_id != search_heap.GetData(current_node_id).parent)
|
||||
while (current_node_id != search_heap.GetData(current_node_id).parent)
|
||||
{
|
||||
current_node_id = search_heap.GetData(current_node_id).parent;
|
||||
packed_path.push_back(current_node_id);
|
||||
packed_path.emplace_back(current_node_id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* BASICROUTINGINTERFACE_H_ */
|
||||
#endif // BASIC_ROUTING_INTERFACE_H
|
||||
|
||||
@@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SHORTESTPATHROUTING_H_
|
||||
#define SHORTESTPATHROUTING_H_
|
||||
#ifndef SHORTEST_PATH_ROUTING_H
|
||||
#define SHORTEST_PATH_ROUTING_H
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
@@ -34,33 +34,27 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "../DataStructures/SearchEngineData.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
template<class DataFacadeT>
|
||||
class ShortestPathRouting : public BasicRoutingInterface<DataFacadeT>{
|
||||
template <class DataFacadeT> class ShortestPathRouting : public BasicRoutingInterface<DataFacadeT>
|
||||
{
|
||||
typedef BasicRoutingInterface<DataFacadeT> super;
|
||||
typedef SearchEngineData::QueryHeap QueryHeap;
|
||||
SearchEngineData & engine_working_data;
|
||||
SearchEngineData &engine_working_data;
|
||||
|
||||
public:
|
||||
ShortestPathRouting(
|
||||
DataFacadeT * facade,
|
||||
SearchEngineData & engine_working_data
|
||||
) :
|
||||
super(facade),
|
||||
engine_working_data(engine_working_data)
|
||||
{ }
|
||||
|
||||
~ShortestPathRouting() { }
|
||||
|
||||
void operator()(
|
||||
const std::vector<PhantomNodes> & phantom_nodes_vector,
|
||||
RawRouteData & raw_route_data
|
||||
) const
|
||||
public:
|
||||
ShortestPathRouting(DataFacadeT *facade, SearchEngineData &engine_working_data)
|
||||
: super(facade), engine_working_data(engine_working_data)
|
||||
{
|
||||
for (const PhantomNodes & phantom_node_pair : phantom_nodes_vector)
|
||||
}
|
||||
|
||||
~ShortestPathRouting() {}
|
||||
|
||||
void operator()(const std::vector<PhantomNodes> &phantom_nodes_vector,
|
||||
RawRouteData &raw_route_data) const
|
||||
{
|
||||
for (const PhantomNodes &phantom_node_pair : phantom_nodes_vector)
|
||||
{
|
||||
if( phantom_node_pair.AtLeastOnePhantomNodeIsInvalid() ) {
|
||||
// raw_route_data.shortest_path_length = INT_MAX;
|
||||
// raw_route_data.alternative_path_length = INT_MAX;
|
||||
if (phantom_node_pair.AtLeastOnePhantomNodeIsInvalid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -70,283 +64,225 @@ public:
|
||||
bool search_from_2nd_node = true;
|
||||
NodeID middle1 = UINT_MAX;
|
||||
NodeID middle2 = UINT_MAX;
|
||||
std::vector<std::vector<NodeID> > packed_legs1(phantom_nodes_vector.size());
|
||||
std::vector<std::vector<NodeID> > packed_legs2(phantom_nodes_vector.size());
|
||||
std::vector<std::vector<NodeID>> packed_legs1(phantom_nodes_vector.size());
|
||||
std::vector<std::vector<NodeID>> packed_legs2(phantom_nodes_vector.size());
|
||||
|
||||
engine_working_data.InitializeOrClearFirstThreadLocalStorage(
|
||||
super::facade->GetNumberOfNodes()
|
||||
);
|
||||
super::facade->GetNumberOfNodes());
|
||||
engine_working_data.InitializeOrClearSecondThreadLocalStorage(
|
||||
super::facade->GetNumberOfNodes()
|
||||
);
|
||||
super::facade->GetNumberOfNodes());
|
||||
engine_working_data.InitializeOrClearThirdThreadLocalStorage(
|
||||
super::facade->GetNumberOfNodes()
|
||||
);
|
||||
super::facade->GetNumberOfNodes());
|
||||
|
||||
QueryHeap & forward_heap1 = *(engine_working_data.forwardHeap);
|
||||
QueryHeap & reverse_heap1 = *(engine_working_data.backwardHeap);
|
||||
QueryHeap & forward_heap2 = *(engine_working_data.forwardHeap2);
|
||||
QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2);
|
||||
QueryHeap &forward_heap1 = *(engine_working_data.forwardHeap);
|
||||
QueryHeap &reverse_heap1 = *(engine_working_data.backwardHeap);
|
||||
QueryHeap &forward_heap2 = *(engine_working_data.forwardHeap2);
|
||||
QueryHeap &reverse_heap2 = *(engine_working_data.backwardHeap2);
|
||||
|
||||
int current_leg = 0;
|
||||
//Get distance to next pair of target nodes.
|
||||
for(const PhantomNodes & phantom_node_pair : phantom_nodes_vector)
|
||||
// Get distance to next pair of target nodes.
|
||||
for (const PhantomNodes &phantom_node_pair : phantom_nodes_vector)
|
||||
{
|
||||
forward_heap1.Clear(); forward_heap2.Clear();
|
||||
reverse_heap1.Clear(); reverse_heap2.Clear();
|
||||
forward_heap1.Clear();
|
||||
forward_heap2.Clear();
|
||||
reverse_heap1.Clear();
|
||||
reverse_heap2.Clear();
|
||||
int local_upper_bound1 = INT_MAX;
|
||||
int local_upper_bound2 = INT_MAX;
|
||||
|
||||
middle1 = UINT_MAX;
|
||||
middle2 = UINT_MAX;
|
||||
|
||||
//insert new starting nodes into forward heap, adjusted by previous distances.
|
||||
if(
|
||||
search_from_1st_node &&
|
||||
phantom_node_pair.source_phantom.forward_node_id != SPECIAL_NODEID
|
||||
) {
|
||||
// SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset();
|
||||
// insert new starting nodes into forward heap, adjusted by previous distances.
|
||||
if (search_from_1st_node &&
|
||||
phantom_node_pair.source_phantom.forward_node_id != SPECIAL_NODEID)
|
||||
{
|
||||
forward_heap1.Insert(
|
||||
phantom_node_pair.source_phantom.forward_node_id,
|
||||
distance1-phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(),
|
||||
phantom_node_pair.source_phantom.forward_node_id
|
||||
);
|
||||
distance1 - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(),
|
||||
phantom_node_pair.source_phantom.forward_node_id);
|
||||
forward_heap2.Insert(
|
||||
phantom_node_pair.source_phantom.forward_node_id,
|
||||
distance1-phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(),
|
||||
phantom_node_pair.source_phantom.forward_node_id
|
||||
);
|
||||
distance1 - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(),
|
||||
phantom_node_pair.source_phantom.forward_node_id);
|
||||
}
|
||||
if(
|
||||
search_from_2nd_node &&
|
||||
phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID
|
||||
) {
|
||||
// SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset();
|
||||
if (search_from_2nd_node &&
|
||||
phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID)
|
||||
{
|
||||
forward_heap1.Insert(
|
||||
phantom_node_pair.source_phantom.reverse_node_id,
|
||||
distance2-phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(),
|
||||
phantom_node_pair.source_phantom.reverse_node_id
|
||||
);
|
||||
distance2 - phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(),
|
||||
phantom_node_pair.source_phantom.reverse_node_id);
|
||||
forward_heap2.Insert(
|
||||
phantom_node_pair.source_phantom.reverse_node_id,
|
||||
distance2-phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(),
|
||||
phantom_node_pair.source_phantom.reverse_node_id
|
||||
);
|
||||
distance2 - phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(),
|
||||
phantom_node_pair.source_phantom.reverse_node_id);
|
||||
}
|
||||
|
||||
//insert new backward nodes into backward heap, unadjusted.
|
||||
if( phantom_node_pair.target_phantom.forward_node_id != SPECIAL_NODEID ) {
|
||||
// SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset();
|
||||
reverse_heap1.Insert(
|
||||
phantom_node_pair.target_phantom.forward_node_id,
|
||||
phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(),
|
||||
phantom_node_pair.target_phantom.forward_node_id
|
||||
);
|
||||
// insert new backward nodes into backward heap, unadjusted.
|
||||
if (phantom_node_pair.target_phantom.forward_node_id != SPECIAL_NODEID)
|
||||
{
|
||||
reverse_heap1.Insert(phantom_node_pair.target_phantom.forward_node_id,
|
||||
phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(),
|
||||
phantom_node_pair.target_phantom.forward_node_id);
|
||||
}
|
||||
|
||||
if( phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID ) {
|
||||
// SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset();
|
||||
reverse_heap2.Insert(
|
||||
phantom_node_pair.target_phantom.reverse_node_id,
|
||||
phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(),
|
||||
phantom_node_pair.target_phantom.reverse_node_id
|
||||
);
|
||||
if (phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID)
|
||||
{
|
||||
reverse_heap2.Insert(phantom_node_pair.target_phantom.reverse_node_id,
|
||||
phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(),
|
||||
phantom_node_pair.target_phantom.reverse_node_id);
|
||||
}
|
||||
|
||||
// const int forward_offset = phantom_node_pair.ComputeForwardQueueOffset();
|
||||
// const int forward_offset = super::ComputeForwardOffset(
|
||||
// phantom_node_pair.source_phantom
|
||||
// );
|
||||
// const int reverse_offset = -phantom_node_pair.ComputeReverseQueueOffset();
|
||||
// const int reverse_offset = super::ComputeReverseOffset(
|
||||
// phantom_node_pair.target_phantom
|
||||
// );
|
||||
|
||||
//run two-Target Dijkstra routing step.
|
||||
while(0 < (forward_heap1.Size() + reverse_heap1.Size() )){
|
||||
if( 0 < forward_heap1.Size() ){
|
||||
// run two-Target Dijkstra routing step.
|
||||
while (0 < (forward_heap1.Size() + reverse_heap1.Size()))
|
||||
{
|
||||
if (0 < forward_heap1.Size())
|
||||
{
|
||||
super::RoutingStep(
|
||||
forward_heap1,
|
||||
reverse_heap1,
|
||||
&middle1,
|
||||
&local_upper_bound1,
|
||||
true
|
||||
);
|
||||
forward_heap1, reverse_heap1, &middle1, &local_upper_bound1, true);
|
||||
}
|
||||
if( 0 < reverse_heap1.Size() ){
|
||||
if (0 < reverse_heap1.Size())
|
||||
{
|
||||
super::RoutingStep(
|
||||
reverse_heap1,
|
||||
forward_heap1,
|
||||
&middle1,
|
||||
&local_upper_bound1,
|
||||
false
|
||||
);
|
||||
reverse_heap1, forward_heap1, &middle1, &local_upper_bound1, false);
|
||||
}
|
||||
}
|
||||
|
||||
if( !reverse_heap2.Empty() ) {
|
||||
while(0 < (forward_heap2.Size() + reverse_heap2.Size() )){
|
||||
if( 0 < forward_heap2.Size() ){
|
||||
if (!reverse_heap2.Empty())
|
||||
{
|
||||
while (0 < (forward_heap2.Size() + reverse_heap2.Size()))
|
||||
{
|
||||
if (0 < forward_heap2.Size())
|
||||
{
|
||||
super::RoutingStep(
|
||||
forward_heap2,
|
||||
reverse_heap2,
|
||||
&middle2,
|
||||
&local_upper_bound2,
|
||||
true
|
||||
);
|
||||
forward_heap2, reverse_heap2, &middle2, &local_upper_bound2, true);
|
||||
}
|
||||
if( 0 < reverse_heap2.Size() ){
|
||||
if (0 < reverse_heap2.Size())
|
||||
{
|
||||
super::RoutingStep(
|
||||
reverse_heap2,
|
||||
forward_heap2,
|
||||
&middle2,
|
||||
&local_upper_bound2,
|
||||
false
|
||||
);
|
||||
reverse_heap2, forward_heap2, &middle2, &local_upper_bound2, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//No path found for both target nodes?
|
||||
if(
|
||||
(INVALID_EDGE_WEIGHT == local_upper_bound1) &&
|
||||
(INVALID_EDGE_WEIGHT == local_upper_bound2)
|
||||
) {
|
||||
// No path found for both target nodes?
|
||||
if ((INVALID_EDGE_WEIGHT == local_upper_bound1) &&
|
||||
(INVALID_EDGE_WEIGHT == local_upper_bound2))
|
||||
{
|
||||
raw_route_data.shortest_path_length = INVALID_EDGE_WEIGHT;
|
||||
raw_route_data.alternative_path_length = INVALID_EDGE_WEIGHT;
|
||||
return;
|
||||
}
|
||||
if( SPECIAL_NODEID == middle1 ) {
|
||||
if (SPECIAL_NODEID == middle1)
|
||||
{
|
||||
search_from_1st_node = false;
|
||||
}
|
||||
if( SPECIAL_NODEID == middle2 ) {
|
||||
if (SPECIAL_NODEID == middle2)
|
||||
{
|
||||
search_from_2nd_node = false;
|
||||
}
|
||||
|
||||
//Was at most one of the two paths not found?
|
||||
BOOST_ASSERT_MSG(
|
||||
(INT_MAX != distance1 || INT_MAX != distance2),
|
||||
"no path found"
|
||||
);
|
||||
// Was at most one of the two paths not found?
|
||||
BOOST_ASSERT_MSG((INT_MAX != distance1 || INT_MAX != distance2), "no path found");
|
||||
|
||||
//Unpack paths if they exist
|
||||
// Unpack paths if they exist
|
||||
std::vector<NodeID> temporary_packed_leg1;
|
||||
std::vector<NodeID> temporary_packed_leg2;
|
||||
|
||||
BOOST_ASSERT( (unsigned)current_leg < packed_legs1.size() );
|
||||
BOOST_ASSERT( (unsigned)current_leg < packed_legs2.size() );
|
||||
BOOST_ASSERT((unsigned)current_leg < packed_legs1.size());
|
||||
BOOST_ASSERT((unsigned)current_leg < packed_legs2.size());
|
||||
|
||||
if( INVALID_EDGE_WEIGHT != local_upper_bound1 ) {
|
||||
if (INVALID_EDGE_WEIGHT != local_upper_bound1)
|
||||
{
|
||||
super::RetrievePackedPathFromHeap(
|
||||
forward_heap1,
|
||||
reverse_heap1,
|
||||
middle1,
|
||||
temporary_packed_leg1
|
||||
);
|
||||
forward_heap1, reverse_heap1, middle1, temporary_packed_leg1);
|
||||
}
|
||||
|
||||
if( INVALID_EDGE_WEIGHT != local_upper_bound2 ) {
|
||||
if (INVALID_EDGE_WEIGHT != local_upper_bound2)
|
||||
{
|
||||
super::RetrievePackedPathFromHeap(
|
||||
forward_heap2,
|
||||
reverse_heap2,
|
||||
middle2,
|
||||
temporary_packed_leg2
|
||||
);
|
||||
forward_heap2, reverse_heap2, middle2, temporary_packed_leg2);
|
||||
}
|
||||
|
||||
//if one of the paths was not found, replace it with the other one.
|
||||
if( temporary_packed_leg1.empty() ) {
|
||||
temporary_packed_leg1.insert(
|
||||
temporary_packed_leg1.end(),
|
||||
temporary_packed_leg2.begin(),
|
||||
temporary_packed_leg2.end()
|
||||
);
|
||||
// if one of the paths was not found, replace it with the other one.
|
||||
if (temporary_packed_leg1.empty())
|
||||
{
|
||||
temporary_packed_leg1.insert(temporary_packed_leg1.end(),
|
||||
temporary_packed_leg2.begin(),
|
||||
temporary_packed_leg2.end());
|
||||
local_upper_bound1 = local_upper_bound2;
|
||||
}
|
||||
if( temporary_packed_leg2.empty() ) {
|
||||
temporary_packed_leg2.insert(
|
||||
temporary_packed_leg2.end(),
|
||||
temporary_packed_leg1.begin(),
|
||||
temporary_packed_leg1.end()
|
||||
);
|
||||
if (temporary_packed_leg2.empty())
|
||||
{
|
||||
temporary_packed_leg2.insert(temporary_packed_leg2.end(),
|
||||
temporary_packed_leg1.begin(),
|
||||
temporary_packed_leg1.end());
|
||||
local_upper_bound2 = local_upper_bound1;
|
||||
}
|
||||
|
||||
BOOST_ASSERT_MSG(
|
||||
!temporary_packed_leg1.empty() ||
|
||||
!temporary_packed_leg2.empty(),
|
||||
"tempory packed paths empty"
|
||||
);
|
||||
BOOST_ASSERT_MSG(!temporary_packed_leg1.empty() || !temporary_packed_leg2.empty(),
|
||||
"tempory packed paths empty");
|
||||
|
||||
BOOST_ASSERT(
|
||||
(0 == current_leg) || !packed_legs1[current_leg-1].empty()
|
||||
);
|
||||
BOOST_ASSERT(
|
||||
(0 == current_leg) || !packed_legs2[current_leg-1].empty()
|
||||
);
|
||||
BOOST_ASSERT((0 == current_leg) || !packed_legs1[current_leg - 1].empty());
|
||||
BOOST_ASSERT((0 == current_leg) || !packed_legs2[current_leg - 1].empty());
|
||||
|
||||
if( 0 < current_leg ) {
|
||||
const NodeID end_id_of_segment1 = packed_legs1[current_leg-1].back();
|
||||
const NodeID end_id_of_segment2 = packed_legs2[current_leg-1].back();
|
||||
BOOST_ASSERT( !temporary_packed_leg1.empty() );
|
||||
if (0 < current_leg)
|
||||
{
|
||||
const NodeID end_id_of_segment1 = packed_legs1[current_leg - 1].back();
|
||||
const NodeID end_id_of_segment2 = packed_legs2[current_leg - 1].back();
|
||||
BOOST_ASSERT(!temporary_packed_leg1.empty());
|
||||
const NodeID start_id_of_leg1 = temporary_packed_leg1.front();
|
||||
const NodeID start_id_of_leg2 = temporary_packed_leg2.front();
|
||||
if( ( end_id_of_segment1 != start_id_of_leg1 ) &&
|
||||
( end_id_of_segment2 != start_id_of_leg2 )
|
||||
) {
|
||||
if ((end_id_of_segment1 != start_id_of_leg1) &&
|
||||
(end_id_of_segment2 != start_id_of_leg2))
|
||||
{
|
||||
std::swap(temporary_packed_leg1, temporary_packed_leg2);
|
||||
std::swap(local_upper_bound1, local_upper_bound2);
|
||||
}
|
||||
}
|
||||
|
||||
// remove one path if both legs end at the same segment
|
||||
if( 0 < current_leg ) {
|
||||
if (0 < current_leg)
|
||||
{
|
||||
const NodeID start_id_of_leg1 = temporary_packed_leg1.front();
|
||||
const NodeID start_id_of_leg2 = temporary_packed_leg2.front();
|
||||
if(
|
||||
start_id_of_leg1 == start_id_of_leg2
|
||||
) {
|
||||
const NodeID last_id_of_packed_legs1 = packed_legs1[current_leg-1].back();
|
||||
const NodeID last_id_of_packed_legs2 = packed_legs2[current_leg-1].back();
|
||||
if( start_id_of_leg1 != last_id_of_packed_legs1 ) {
|
||||
if (start_id_of_leg1 == start_id_of_leg2)
|
||||
{
|
||||
const NodeID last_id_of_packed_legs1 = packed_legs1[current_leg - 1].back();
|
||||
const NodeID last_id_of_packed_legs2 = packed_legs2[current_leg - 1].back();
|
||||
if (start_id_of_leg1 != last_id_of_packed_legs1)
|
||||
{
|
||||
packed_legs1 = packed_legs2;
|
||||
BOOST_ASSERT(
|
||||
start_id_of_leg1 == temporary_packed_leg1.front()
|
||||
);
|
||||
} else
|
||||
if( start_id_of_leg2 != last_id_of_packed_legs2 ) {
|
||||
BOOST_ASSERT(start_id_of_leg1 == temporary_packed_leg1.front());
|
||||
}
|
||||
else if (start_id_of_leg2 != last_id_of_packed_legs2)
|
||||
{
|
||||
packed_legs2 = packed_legs1;
|
||||
BOOST_ASSERT(
|
||||
start_id_of_leg2 == temporary_packed_leg2.front()
|
||||
);
|
||||
BOOST_ASSERT(start_id_of_leg2 == temporary_packed_leg2.front());
|
||||
}
|
||||
}
|
||||
}
|
||||
BOOST_ASSERT(
|
||||
packed_legs1.size() == packed_legs2.size()
|
||||
);
|
||||
BOOST_ASSERT(packed_legs1.size() == packed_legs2.size());
|
||||
|
||||
packed_legs1[current_leg].insert(
|
||||
packed_legs1[current_leg].end(),
|
||||
temporary_packed_leg1.begin(),
|
||||
temporary_packed_leg1.end()
|
||||
);
|
||||
BOOST_ASSERT(packed_legs1[current_leg].size() == temporary_packed_leg1.size() );
|
||||
packed_legs2[current_leg].insert(
|
||||
packed_legs2[current_leg].end(),
|
||||
temporary_packed_leg2.begin(),
|
||||
temporary_packed_leg2.end()
|
||||
);
|
||||
BOOST_ASSERT(packed_legs2[current_leg].size() == temporary_packed_leg2.size() );
|
||||
packed_legs1[current_leg].insert(packed_legs1[current_leg].end(),
|
||||
temporary_packed_leg1.begin(),
|
||||
temporary_packed_leg1.end());
|
||||
BOOST_ASSERT(packed_legs1[current_leg].size() == temporary_packed_leg1.size());
|
||||
packed_legs2[current_leg].insert(packed_legs2[current_leg].end(),
|
||||
temporary_packed_leg2.begin(),
|
||||
temporary_packed_leg2.end());
|
||||
BOOST_ASSERT(packed_legs2[current_leg].size() == temporary_packed_leg2.size());
|
||||
|
||||
if(
|
||||
(packed_legs1[current_leg].back() == packed_legs2[current_leg].back()) &&
|
||||
phantom_node_pair.target_phantom.isBidirected()
|
||||
) {
|
||||
if ((packed_legs1[current_leg].back() == packed_legs2[current_leg].back()) &&
|
||||
phantom_node_pair.target_phantom.isBidirected())
|
||||
{
|
||||
const NodeID last_node_id = packed_legs2[current_leg].back();
|
||||
search_from_1st_node &= !(last_node_id == phantom_node_pair.target_phantom.reverse_node_id);
|
||||
search_from_2nd_node &= !(last_node_id == phantom_node_pair.target_phantom.forward_node_id);
|
||||
BOOST_ASSERT( search_from_1st_node != search_from_2nd_node );
|
||||
search_from_1st_node &=
|
||||
!(last_node_id == phantom_node_pair.target_phantom.reverse_node_id);
|
||||
search_from_2nd_node &=
|
||||
!(last_node_id == phantom_node_pair.target_phantom.forward_node_id);
|
||||
BOOST_ASSERT(search_from_1st_node != search_from_2nd_node);
|
||||
}
|
||||
|
||||
distance1 = local_upper_bound1;
|
||||
@@ -356,45 +292,33 @@ public:
|
||||
|
||||
if (distance1 > distance2)
|
||||
{
|
||||
std::swap( packed_legs1, packed_legs2 );
|
||||
std::swap(packed_legs1, packed_legs2);
|
||||
}
|
||||
raw_route_data.unpacked_path_segments.resize( packed_legs1.size() );
|
||||
// const int start_offset = ( packed_legs1[0].front() == phantom_nodes_vector.front().source_phantom.forward_node_id ? 1 : -1 )*phantom_nodes_vector.front().source_phantom.fwd_segment_position;
|
||||
raw_route_data.unpacked_path_segments.resize(packed_legs1.size());
|
||||
|
||||
raw_route_data.source_traversed_in_reverse = (packed_legs1.front().front() != phantom_nodes_vector.front().source_phantom.forward_node_id);
|
||||
raw_route_data.target_traversed_in_reverse = (packed_legs1.back().back() != phantom_nodes_vector.back().target_phantom.forward_node_id);
|
||||
raw_route_data.source_traversed_in_reverse =
|
||||
(packed_legs1.front().front() !=
|
||||
phantom_nodes_vector.front().source_phantom.forward_node_id);
|
||||
raw_route_data.target_traversed_in_reverse =
|
||||
(packed_legs1.back().back() !=
|
||||
phantom_nodes_vector.back().target_phantom.forward_node_id);
|
||||
|
||||
for (unsigned i = 0; i < packed_legs1.size(); ++i)
|
||||
{
|
||||
BOOST_ASSERT(!phantom_nodes_vector.empty());
|
||||
// const bool at_beginning = (packed_legs1[i] == packed_legs1.front());
|
||||
// const bool at_end = (packed_legs1[i] == packed_legs1.back());
|
||||
BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size());
|
||||
|
||||
PhantomNodes unpack_phantom_node_pair = phantom_nodes_vector[i];
|
||||
// if (!at_beginning)
|
||||
// {
|
||||
// unpack_phantom_node_pair.source_phantom.packed_geometry_id = SPECIAL_EDGEID;
|
||||
// unpack_phantom_node_pair.source_phantom.fwd_segment_position = 0;
|
||||
// }
|
||||
|
||||
// if (!at_end)
|
||||
// {
|
||||
// unpack_phantom_node_pair.target_phantom.packed_geometry_id = SPECIAL_EDGEID;
|
||||
// unpack_phantom_node_pair.target_phantom.fwd_segment_position = 0;
|
||||
// }
|
||||
|
||||
super::UnpackPath(
|
||||
// -- packed input
|
||||
packed_legs1[i],
|
||||
// -- start and end of (sub-)route
|
||||
unpack_phantom_node_pair,
|
||||
// -- unpacked output
|
||||
raw_route_data.unpacked_path_segments[i]
|
||||
);
|
||||
raw_route_data.unpacked_path_segments[i]);
|
||||
}
|
||||
raw_route_data.shortest_path_length = std::min(distance1, distance2);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* SHORTESTPATHROUTING_H_ */
|
||||
#endif /* SHORTEST_PATH_ROUTING_H */
|
||||
|
||||
Reference in New Issue
Block a user