1
#ifndef VALHALLA_THOR_BIDIRECTIONAL_ASTAR_H_
2
#define VALHALLA_THOR_BIDIRECTIONAL_ASTAR_H_
6
#include <unordered_map>
10
#include <valhalla/baldr/double_bucket_queue.h>
11
#include <valhalla/sif/edgelabel.h>
12
#include <valhalla/sif/hierarchylimits.h>
13
#include <valhalla/thor/pathalgorithm.h>
14
#include <valhalla/thor/astarheuristic.h>
15
#include <valhalla/thor/edgestatus.h>
21
* Candidate connections - a directed edge and its opposing directed edge
22
* are both temporarily labeled. Store the edge Ids and its cost.
24
struct CandidateConnection {
25
baldr::GraphId edgeid;
26
baldr::GraphId opp_edgeid;
31
* Bidirectional A* algorithm. Method for finding least-cost path.
33
class BidirectionalAStar : public PathAlgorithm {
43
virtual ~BidirectionalAStar();
46
* Form path between and origin and destination location using
47
* the supplied mode and costing method.
48
* @param origin Origin location
49
* @param dest Destination location
50
* @param graphreader Graph reader for accessing routing graph.
51
* @param mode_costing An array of costing methods, one per TravelMode.
52
* @param mode Travel mode from the origin.
53
* @return Returns the path edges (and elapsed time/modes at end of
56
std::vector<PathInfo> GetBestPath(baldr::PathLocation& origin,
57
baldr::PathLocation& dest, baldr::GraphReader& graphreader,
58
const std::shared_ptr<sif::DynamicCost>* mode_costing,
59
const sif::TravelMode mode);
62
* Clear the temporary information generated during path construction.
67
// Access mode used by the costing method
68
uint32_t access_mode_;
70
// Current travel mode
71
sif::TravelMode mode_;
73
// Current travel type
76
// Current costing mode
77
std::shared_ptr<sif::DynamicCost> costing_;
80
std::vector<sif::HierarchyLimits> hierarchy_limits_forward_;
81
std::vector<sif::HierarchyLimits> hierarchy_limits_reverse_;
85
AStarHeuristic astarheuristic_forward_;
86
AStarHeuristic astarheuristic_reverse_;
88
// Vector of edge labels (requires access by index).
89
std::vector<sif::EdgeLabel> edgelabels_forward_;
90
std::vector<sif::EdgeLabel> edgelabels_reverse_;
92
// Adjacency list - approximate double bucket sort
93
std::shared_ptr<baldr::DoubleBucketQueue> adjacencylist_forward_;
94
std::shared_ptr<baldr::DoubleBucketQueue> adjacencylist_reverse_;
96
// Edge status. Mark edges that are in adjacency list or settled.
97
std::shared_ptr<EdgeStatus> edgestatus_forward_;
98
std::shared_ptr<EdgeStatus> edgestatus_reverse_;
100
// Best candidate connection and threshold to extend search.
102
CandidateConnection best_connection_;
105
* Initialize the A* heuristic and adjacency lists for both the forward
106
* and reverse search.
107
* @param origll Lat,lng of the origin.
108
* @param destll Lat,lng of the destination.
109
* @param costing Dynamic costing method.
111
void Init(const PointLL& origll, const PointLL& destll);
114
* Expand from the node along the forward search path.
116
void ExpandForward(baldr::GraphReader& graphreader,
117
const baldr::GraphId& node, const sif::EdgeLabel& pred,
118
const uint32_t pred_idx, const bool from_transition);
121
* Expand from the node along the reverse search path.
123
void ExpandReverse(baldr::GraphReader& graphreader,
124
const baldr::GraphId& node, const sif::EdgeLabel& pred,
125
const uint32_t pred_idx, const baldr::DirectedEdge* opp_pred_edge,
126
const bool from_transition);
129
* Add edges at the origin to the forward adjacency list.
130
* @param graphreader Graph tile reader.
131
* @param origin Location information of the destination
132
* @param costing Dynamic costing
134
void SetOrigin(baldr::GraphReader& graphreader,
135
baldr::PathLocation& origin);
138
* Add destination edges to the reverse path adjacency list.
139
* @param dest Location information of the destination
140
* @param costing Dynamic costing
142
void SetDestination(baldr::GraphReader& graphreader,
143
const baldr::PathLocation& dest);
146
* The edge on the forward search connects to a reached edge on the reverse
147
* search tree. Check if this is the best connection so far and set the
149
* @param pred Edge label of the predecessor.
151
void SetForwardConnection(const sif::EdgeLabel& pred);
154
* The edge on the reverse search connects to a reached edge on the forward
155
* search tree. Check if this is the best connection so far and set the
157
* @param pred Edge label of the predecessor.
159
void SetReverseConnection(const sif::EdgeLabel& pred);
162
* Form the path from the adjacency lists. Recovers the path from the
163
* where the paths meet back towards the origin then reverses this path.
164
* The path from where the paths meet to the destination is then appended
165
* using the opposing edges (so the path is traversed forward).
166
* @param graphreader Graph tile reader (for getting opposing edges).
167
* @return Returns the path info, a list of GraphIds representing the
168
* directed edges along the path - ordered from origin to
169
* destination - along with travel modes and elapsed time.
171
std::vector<PathInfo> FormPath(baldr::GraphReader& graphreader);
177
#endif // VALHALLA_THOR_BIDIRECTIONAL_ASTAR_H_