4 #include <boost/make_shared.hpp> 14 bool withLaneChange) {
15 auto route =
self.getRoute(from, to, costId, withLaneChange);
19 return std::make_shared<lanelet::routing::Route>(std::move(*route));
26 bool withLaneChange) {
27 auto route =
self.getRouteVia(from, via, to, costId, withLaneChange);
31 return std::make_shared<lanelet::routing::Route>(std::move(*route));
36 return routing::RoutingGraph::build(laneletMap, trafficRules, routingCosts);
42 return routing::RoutingGraph::build(laneletMap, trafficRules, routingCosts);
47 return v ? object(*v) : object();
56 auto trafficRules =
import(
"lanelet2.traffic_rules");
62 OptionalConverter<Route>();
63 OptionalConverter<std::shared_ptr<Route>>();
64 OptionalConverter<RelationType>();
65 OptionalConverter<LaneletRelation>();
66 OptionalConverter<LaneletPath>();
68 VectorToListConverter<LaneletRelations>();
69 VectorToListConverter<RoutingCostPtrs>();
70 VectorToListConverter<LaneletPaths>();
75 implicitly_convertible<std::shared_ptr<RoutingCostDistance>,
RoutingCostPtr>();
76 implicitly_convertible<std::shared_ptr<RoutingCostTravelTime>,
RoutingCostPtr>();
77 implicitly_convertible<LaneletMapPtr, LaneletMapConstPtr>();
80 class_<RoutingCost, boost::noncopyable, std::shared_ptr<RoutingCost>>(
81 "RoutingCost",
"Object for calculating routing costs between lanelets", no_init);
83 class_<RoutingCostDistance, bases<RoutingCost>, std::shared_ptr<RoutingCostDistance>>(
84 "RoutingCostDistance",
"Distance based routing cost calculation object",
85 init<double, double>((arg(
"laneChangeCost"), arg(
"minLaneChangeDistance") = 0)));
87 class_<RoutingCostTravelTime, bases<RoutingCost>, std::shared_ptr<RoutingCostTravelTime>>(
88 "RoutingCostTravelTime",
"Travel time based routing cost calculation object",
89 init<double, double>((arg(
"laneChangeCost"), arg(
"minLaneChangeTime") = 0)));
92 &RoutingGraph::possiblePaths);
94 &RoutingGraph::possiblePaths);
96 &RoutingGraph::possiblePaths);
99 &RoutingGraph::possiblePathsTowards);
102 &RoutingGraph::possiblePathsTowards);
105 &RoutingGraph::possiblePathsTowards);
107 class_<LaneletPath>(
"LaneletPath",
108 "A set of consecutive lanelets connected in straight " 109 "directon or by lane changes",
110 init<ConstLanelets>(arg(
"lanelets")))
111 .def(
"__iter__", iterator<LaneletPath>())
112 .def(
"__len__", &LaneletPath::size)
113 .def(
"__getitem__", wrappers::getItem<LaneletPath>, return_internal_reference<>())
117 "get the sequence of remaining lanelets without a lane change")
121 class_<LaneletVisitInformation>(
"LaneletVisitInformation",
122 "Object passed as input for the forEachSuccessor function of the routing graph")
123 .def_readwrite(
"lanelet", &LaneletVisitInformation::lanelet,
"the currently visited lanelet")
124 .def_readwrite(
"predecessor", &LaneletVisitInformation::predecessor,
"the predecessor within the shortest path")
125 .def_readwrite(
"length", &LaneletVisitInformation::length,
126 "The length of the shortest path to this lanelet (including lanelet")
127 .def_readwrite(
"cost", &LaneletVisitInformation::cost,
"The cost along the shortest path")
128 .def_readwrite(
"numLaneChanges", &LaneletVisitInformation::numLaneChanges,
129 "The number of lane changes necessary along the shortest path");
131 class_<LaneletOrAreaVisitInformation>(
132 "LaneletOrAreaVisitInformation",
133 "Object passed as input for the forEachSuccessorIncludingAreas function of the routing graph")
134 .def_readwrite(
"laneletOrArea", &LaneletOrAreaVisitInformation::laneletOrArea,
135 "the currently visited lanelet/area")
136 .def_readwrite(
"predecessor", &LaneletOrAreaVisitInformation::predecessor,
137 "the predecessor within the shortest path")
138 .def_readwrite(
"length", &LaneletOrAreaVisitInformation::length,
139 "The length of the shortest path to this lanelet (including lanelet")
140 .def_readwrite(
"cost", &LaneletOrAreaVisitInformation::cost,
"The cost along the shortest path")
141 .def_readwrite(
"numLaneChanges", &LaneletOrAreaVisitInformation::numLaneChanges,
142 "The number of lane changes necessary along the shortest path");
144 class_<PossiblePathsParams>(
145 "PossiblePathsParams",
"Parameters for configuring the behaviour of the possible path algorithms of RoutingGraph")
148 +[](
const object& costLimit,
const object& elemLimit,
RoutingCostId costId,
bool includeLc,
149 bool includeShorter) {
151 objectToOptional<double>(costLimit), objectToOptional<std::uint32_t>(elemLimit), costId, includeLc,
154 default_call_policies{},
155 (arg(
"routingCostLimit") = object(), arg(
"elementLimit") = object(), arg(
"routingCostId") = 0,
156 arg(
"includeLaneChanges") =
false, arg(
"includeShorterPaths") =
false)))
160 self.routingCostLimit = objectToOptional<double>(value);
165 self.elementLimit = objectToOptional<std::uint32_t>(value);
167 .def_readwrite(
"routingCostId", &PossiblePathsParams::routingCostId)
168 .def_readwrite(
"includeLaneChanges", &PossiblePathsParams::includeLaneChanges)
169 .def_readwrite(
"includeShorterPaths", &PossiblePathsParams::includeShorterPaths);
171 auto lltAndLc = (arg(
"lanelet"), arg(
"withLaneChanges") =
false);
172 auto lltAndRoutingCost = (arg(
"lanelet"), arg(
"routingCostId") = 0);
173 class_<RoutingGraph, boost::noncopyable, RoutingGraphPtr>(
175 "Main class of the routing module that holds routing information and can " 181 "Initialization with default routing costs")
185 "Initialization from a submap")
186 .def(
"getRoute",
getRouteWrapper,
"driving route from 'start' to 'end' lanelet",
187 (arg(
"from"), arg(
"to"), arg(
"routingCostId") = 0, arg(
"withLaneChanges") =
true))
188 .def(
"getRouteVia",
getRouteViaWrapper,
"driving route from 'start' to 'end' lanelet using the 'via' lanelets",
189 (arg(
"from"), arg(
"via"), arg(
"to"), arg(
"routingCostId") = 0, arg(
"withLaneChanges") =
true))
190 .def(
"shortestPath", &RoutingGraph::shortestPath,
"shortest path between 'start' and 'end'",
191 (arg(
"from"), arg(
"to"), arg(
"routingCostId") = 0, arg(
"withLaneChanges") =
true))
192 .def(
"shortestPathWithVia", &RoutingGraph::shortestPathVia,
193 "shortest path between 'start' and 'end' using intermediate points",
194 (arg(
"start"), arg(
"via"), arg(
"end"), arg(
"routingCostId") = 0, arg(
"withLaneChanges") =
true))
195 .def(
"routingRelation", &RoutingGraph::routingRelation,
"relation between two lanelets excluding 'conflicting'",
196 (arg(
"from"), arg(
"to")))
197 .def(
"following", &RoutingGraph::following,
"lanelets that can be reached from this lanelet", lltAndLc)
198 .def(
"followingRelations", &RoutingGraph::followingRelations,
"relations to following lanelets", lltAndLc)
199 .def(
"previous", &RoutingGraph::previous,
"previous lanelets of this lanelet", lltAndLc)
200 .def(
"previousRelations", &RoutingGraph::previousRelations,
"relations to preceding lanelets", lltAndLc)
201 .def(
"besides", &RoutingGraph::besides,
202 "all reachable left and right lanelets, including lanelet, from " 205 .def(
"left", &RoutingGraph::left,
"left (routable)lanelet, if exists", lltAndRoutingCost)
206 .def(
"right", &RoutingGraph::right,
"right (routable)lanelet, if it exists", lltAndRoutingCost)
207 .def(
"adjacentLeft", &RoutingGraph::adjacentLeft,
"left non-routable lanelet", lltAndRoutingCost)
208 .def(
"adjacentRight", &RoutingGraph::adjacentRight,
"right non-routable lanelet", lltAndRoutingCost)
209 .def(
"lefts", &RoutingGraph::lefts,
"all left (routable) lanelets", lltAndRoutingCost)
210 .def(
"rights", &RoutingGraph::rights,
"all right (routable) lanelets", lltAndRoutingCost)
211 .def(
"adjacentLefts", &RoutingGraph::adjacentLefts,
"all left (non-routable) lanelets", lltAndRoutingCost)
212 .def(
"adjacentRights", &RoutingGraph::adjacentRights,
"all right (non-routable) lanelets", lltAndRoutingCost)
213 .def(
"leftRelations", &RoutingGraph::leftRelations,
"relations to left lanelets", lltAndRoutingCost)
214 .def(
"rightRelations", &RoutingGraph::rightRelations,
"relations to right lanelets", lltAndRoutingCost)
215 .def(
"conflicting", &RoutingGraph::conflicting,
"Conflicting lanelets", arg(
"lanelet"))
216 .def(
"reachableSet", &RoutingGraph::reachableSet,
"set of lanelets that can be reached from a given lanelet",
217 (arg(
"lanelet"), arg(
"maxRoutingCost"), arg(
"RoutingCostId") = 0, arg(
"allowLaneChanges") =
true))
218 .def(
"reachableSetTowards", &RoutingGraph::reachableSetTowards,
"set of lanelets that can reach a given lanelet",
219 (arg(
"lanelet"), arg(
"maxRoutingCost"), arg(
"RoutingCostId") = 0, arg(
"allowLaneChanges") =
true))
220 .def(
"possiblePaths", possPCost,
"possible paths from a given start lanelet that are 'minRoutingCost'-long",
221 (arg(
"lanelet"), arg(
"minRoutingCost"), arg(
"RoutingCostId") = 0, arg(
"allowLaneChanges") =
false,
222 arg(
"routingCostId") = 0))
223 .def(
"possiblePaths", possPParam,
"possible paths from a given start lanelet as configured in parameters",
224 (arg(
"lanelet"), arg(
"parameters")))
225 .def(
"possiblePathsTowards", possPToCost,
226 "possible paths to a given start lanelet that are 'minRoutingCost'-long",
227 (arg(
"lanelet"), arg(
"minRoutingCost"), arg(
"RoutingCostId") = 0, arg(
"allowLaneChanges") =
false,
228 arg(
"routingCostId") = 0))
229 .def(
"possiblePathsTowards", possPToParam,
"possible paths to a given lanelet as configured in parameters",
230 (arg(
"lanelet"), arg(
"parameters")))
231 .def(
"possiblePathsMinLen", possPLen,
"possible routes from a given start lanelet that are 'minLanelets'-long",
232 (arg(
"lanelet"), arg(
"minLanelets"), arg(
"allowLaneChanges") =
false, arg(
"routingCostId") = 0))
233 .def(
"possiblePathsTowardsMinLen", possPToLen,
234 "possible routes from a given start lanelet that are 'minLanelets'-long",
235 (arg(
"lanelet"), arg(
"minLanelets"), arg(
"allowLaneChanges") =
false, arg(
"routingCostId") = 0))
239 self.forEachSuccessor(from, std::move(func), lc, costId);
241 "calls a function on each successor of lanelet with increasing cost. The function must receives a " 242 "LaneletVisitInformation object as input and must return a bool whether followers of the current lanelet " 243 "should be visited as well. The function can raise an exception if an early exit is desired",
244 (arg(
"lanelet"), arg(
"func"), arg(
"allowLaneChanges") =
true, arg(
"routingCostId") = 0))
246 "forEachSuccessorIncludingAreas",
248 self.forEachSuccessorIncludingAreas(from, std::move(func), lc, costId);
250 "similar to forEachSuccessor but also includes areas into the search",
251 (arg(
"lanelet"), arg(
"func"), arg(
"allowLaneChanges") =
true, arg(
"routingCostId") = 0))
253 "forEachPredecessor",
255 self.forEachPredecessor(from, std::move(func), lc, costId);
257 "similar to forEachSuccessor but instead goes backwards along the routing graph",
258 (arg(
"lanelet"), arg(
"func"), arg(
"allowLaneChanges") =
true, arg(
"routingCostId") = 0))
260 "forEachPredecessorIncludingAreas",
262 self.forEachPredecessorIncludingAreas(from, std::move(func), lc, costId);
264 "calls a function on each successor of lanelet. The function must receives a LaneletVisitInformation object " 265 "as input and must return a bool whether followers of the current lanelet should be visited as well. The " 266 "function can throw an exception if an early exit is desired",
267 (arg(
"lanelet"), arg(
"func"), arg(
"allowLaneChanges") =
true, arg(
"routingCostId") = 0))
269 "exportGraphML", +[](
RoutingGraph&
self,
const std::string& path) {
self.exportGraphML(path); },
270 "Export the internal graph to graphML (xml-based) file format")
272 "exportGraphViz", +[](
RoutingGraph&
self,
const std::string& path) {
self.exportGraphViz(path); },
273 "Export the internal graph to graphViz (DOT) file format")
274 .def(
"getDebugLaneletMap", &RoutingGraph::getDebugLaneletMap,
275 "abstract lanelet map holding the information of the routing graph",
276 (arg(
"routingCostId") = 0, arg(
"includeAdjacent") =
false, arg(
"includeConflicting") =
false))
277 .def(
"passableLaneletSubmap", &RoutingGraph::passableSubmap,
"LaneletMap that includes all passable lanelets")
278 .def(
"checkValidity", &RoutingGraph::checkValidity,
"Performs some basic sanity checks",
279 (arg(
"throwOnError") =
true));
281 class_<LaneletRelation>(
"LaneletRelation")
282 .def_readwrite(
"lanelet", &LaneletRelation::lanelet)
283 .def_readwrite(
"relationType", &LaneletRelation::relationType);
285 enum_<RelationType>(
"RelationType")
286 .value(
"Successor", RelationType::Successor)
287 .value(
"Left", RelationType::Left)
288 .value(
"Right", RelationType::Right)
289 .value(
"Conflicting", RelationType::Conflicting)
290 .value(
"AdjacentLeft", RelationType::AdjacentLeft)
291 .value(
"AdjacentRight", RelationType::AdjacentRight)
294 class_<Route, boost::noncopyable, std::shared_ptr<Route>>(
"Route",
295 "The famous route object that marks a route from A to B, " 296 "including all lanelets that can be used",
298 .def(
"shortestPath", &Route::shortestPath,
"Returns the shortest path along this route",
299 return_internal_reference<>())
300 .def(
"fullLane", &Route::fullLane,
"Returns the complete lane a Lanelet belongs to")
301 .def(
"remainingLane", &Route::remainingLane,
"Returns that remaining lane a Lanelet belongs to")
302 .def(
"remainingShortestPath", &Route::remainingShortestPath,
303 "Returns all lanelets on the shortest path that follow the input lanelet")
304 .def(
"length2d", &Route::length2d,
"2d length of shortest path")
305 .def(
"numLanes", &Route::numLanes,
"Number of inidividual lanes")
308 "laneletSubmap with all lanelets that are part of the route")
309 .def(
"getDebugLaneletMap", &Route::getDebugLaneletMap,
310 "laneletMap that represents the Lanelets of the Route and their relationship")
311 .def(
"size", &Route::size,
"Number of lanelets")
312 .def(
"followingRelations", &Route::followingRelations,
"Provides the following lanelets within the Route")
313 .def(
"previousRelations", &Route::previousRelations,
"Provides the previous lanelets within the Route")
314 .def(
"leftRelation", &Route::leftRelation,
"Provides the lanelet left of a given lanelet within the Route")
315 .def(
"leftRelations", &Route::leftRelations,
"*all* lanelets left of a given lanelet within the Route")
316 .def(
"rightRelation", &Route::rightRelation,
"Provides the lanelet right of a given lanelet within the Route")
317 .def(
"rightRelations", &Route::rightRelations,
"*all* lanelets right of a given lanelet within the Route")
318 .def(
"conflictingInRoute", &Route::conflictingInRoute,
"conflicting lanelets of a lanelet within the route")
319 .def(
"conflictingInMap", &Route::conflictingInMap,
320 "conflicting lanelets of a lanelet within all passable lanelets in the laneletMap")
321 .def(
"allConflictingInMap", &Route::allConflictingInMap,
322 "all lanelets in the map that conflict with any lanelet in the route")
325 +[](
Route&
self,
const ConstLanelet& from,
object func) {
self.forEachSuccessor(from, std::move(func)); },
326 "calls a function on each successor of lanelet with increasing cost. The function must receives a " 327 "LaneletVisitInformation object as input and must return a bool whether followers of the current lanelet " 328 "should be visited as well. The function can raise an exception if an early exit is desired",
329 (arg(
"lanelet"), arg(
"func")))
331 "forEachPredecessor",
332 +[](
Route&
self,
const ConstLanelet& from,
object func) {
self.forEachPredecessor(from, std::move(func)); },
333 "similar to forEachSuccessor but instead goes backwards along the routing graph",
334 (arg(
"lanelet"), arg(
"func")))
335 .def(
"checkValidity", &Route::checkValidity,
"perform sanity check on the route");
Optional< T > objectToOptional(const object &o)
Optional< std::shared_ptr< lanelet::routing::Route > > getRouteWrapper(const lanelet::routing::RoutingGraph &self, const ConstLanelet &from, const ConstLanelet &to, lanelet::routing::RoutingCostId costId, bool withLaneChange)
object optionalToObject(const Optional< T > &v)
routing::RoutingGraphPtr makeRoutingGraph(LaneletMap &laneletMap, const traffic_rules::TrafficRules &trafficRules, const routing::RoutingCostPtrs &routingCosts)
py::to_python_converter< T, VectorToList< T > > VectorToListConverter
std::vector< LaneletPath > LaneletPaths
boost::optional< T > Optional
std::shared_ptr< RoutingGraph > RoutingGraphPtr
std::shared_ptr< RoutingCost > RoutingCostPtr
BOOST_PYTHON_MODULE(PYTHON_API_MODULE_NAME)
routing::RoutingGraphPtr makeRoutingGraphSubmap(LaneletSubmap &laneletMap, const traffic_rules::TrafficRules &trafficRules, const routing::RoutingCostPtrs &routingCosts)
RoutingCostPtrs defaultRoutingCosts()
py::to_python_converter< lanelet::Optional< T >, OptionalToObject< T > > OptionalConverter
std::vector< RoutingCostPtr > RoutingCostPtrs
LaneletSubmapConstPtr laneletSubmap() const noexcept
Optional< std::shared_ptr< lanelet::routing::Route > > getRouteViaWrapper(const lanelet::routing::RoutingGraph &self, const ConstLanelet &from, const ConstLanelets &via, const ConstLanelet &to, lanelet::routing::RoutingCostId costId, bool withLaneChange)
std::vector< ConstLanelet > ConstLanelets