libosmscout  1.1.1
MultiDBRoutingService.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_MULTIDBROUTINGSERVICE_H
2 #define OSMSCOUT_MULTIDBROUTINGSERVICE_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2016 Tim Teulings
7  Copyright (C) 2017 Lukas Karas
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 
24 #include <osmscout/Pixel.h>
30 
31 namespace osmscout {
32 
38  class OSMSCOUT_API MultiDBRoutingService CLASS_FINAL : public AbstractRoutingService<MultiDBRoutingState>
39  {
40  private:
41  struct DatabaseHandle CLASS_FINAL
42  {
43  DatabaseId dbId; //<! Numeric id of the database (also index to the handles array)
44  DatabaseRef database; //<! Object database
45  RoutingDatabaseRef routingDatabase; //<! Routing database
46  SimpleRoutingServiceRef router; //<! Simple router for the given database
47  RoutingProfileRef profile; //<! Profile for the given database
48  };
49 
50  public:
51  using RoutingProfileBuilder = std::function<RoutingProfileRef (const DatabaseRef &)>;
52 
53  private:
54  std::vector<DatabaseHandle> handles;
55  bool isOpen;
56 
57  private:
58  Vehicle GetVehicle(const MultiDBRoutingState& state) override;
59 
60  bool CanUseForward(const MultiDBRoutingState& state,
61  const DatabaseId& database,
62  const WayRef& way) override;
63 
64  bool CanUseBackward(const MultiDBRoutingState& state,
65  const DatabaseId& database,
66  const WayRef& way) override;
67 
68  double GetCosts(const MultiDBRoutingState& state,
69  DatabaseId databaseId,
70  const RouteNode& routeNode,
71  size_t inPathIndex,
72  size_t outPathIndex) override;
73 
74  double GetCosts(const MultiDBRoutingState& state,
75  DatabaseId database,
76  const WayRef &way,
77  const Distance &wayLength) override;
78 
79  double GetEstimateCosts(const MultiDBRoutingState& state,
80  DatabaseId database,
81  const Distance &targetDistance) override;
82 
83  double GetCostLimit(const MultiDBRoutingState& state,
84  DatabaseId database,
85  const Distance &targetDistance) override;
86 
87  std::string GetCostString(const MultiDBRoutingState& profile,
88  DatabaseId database,
89  double cost) const override;
90 
91  bool GetRouteNodes(const std::set<DBId> &routeNodeIds,
92  std::unordered_map<DBId,RouteNodeRef> &routeNodeMap) override;
93 
94  bool GetRouteNode(const DBId &id,
95  RouteNodeRef &node) override;
96 
97  bool GetWayByOffset(const DBFileOffset &offset,
98  WayRef &way) override;
99 
100  bool GetWaysByOffset(const std::set<DBFileOffset> &wayOffsets,
101  std::unordered_map<DBFileOffset,WayRef> &wayMap) override;
102 
103  bool GetAreaByOffset(const DBFileOffset &offset,
104  AreaRef &area) override;
105 
106  bool GetAreasByOffset(const std::set<DBFileOffset> &areaOffsets,
107  std::unordered_map<DBFileOffset,AreaRef> &areaMap) override;
108 
109  bool ResolveRouteDataJunctions(RouteData& route) override;
110 
111  std::vector<DBId> GetNodeTwins(const MultiDBRoutingState& state,
112  DatabaseId database,
113  Id id) override;
114 
115  bool CanUse(const MultiDBRoutingState& state,
116  DatabaseId databaseId,
117  const RouteNode& routeNode,
118  size_t pathIndex) override;
119 
120  public:
121  MultiDBRoutingService(const RouterParameter& parameter,
122  const std::vector<DatabaseRef> &databases);
123  ~MultiDBRoutingService() override;
124 
125  bool Open(RoutingProfileBuilder routingProfileBuilder);
126 
127  void Close();
128 
129  RoutePositionResult GetClosestRoutableNode(const GeoCoord &coord,
130  const Distance &radius=Kilometers(1)) const;
131 
132  RoutingResult CalculateRoute(const RoutePosition &start,
133  const RoutePosition &target,
134  const RoutingParameter &parameter);
135 
136  RoutingResult CalculateRoute(std::vector<osmscout::GeoCoord> via,
137  const Distance &radius,
138  const RoutingParameter& parameter);
139 
140  RouteDescriptionResult TransformRouteDataToRouteDescription(const RouteData& data);
141 
142  RoutePointsResult TransformRouteDataToPoints(const RouteData& data);
143 
144  RouteWayResult TransformRouteDataToWay(const RouteData& data);
145 
146  bool PostProcessRouteDescription(RouteDescription &description,
147  const std::list<RoutePostprocessor::PostprocessorRef> &postprocessors);
148 
149  std::map<DatabaseId, std::string> GetDatabaseMapping() const override;
150  };
151 
154  using MultiDBRoutingServiceRef = std::shared_ptr<MultiDBRoutingService>;
155 
156 }
157 
158 #endif /* OSMSCOUT_MULTIDBROUTINGSERVICE_H */
uint64_t Id
Definition: OSMScoutTypes.h:41
Definition: RouteDescription.h:53
std::shared_ptr< RoutingProfile > RoutingProfileRef
Definition: RoutingProfile.h:171
Vehicle
Definition: OSMScoutTypes.h:55
std::shared_ptr< Way > WayRef
Definition: Way.h:202
std::shared_ptr< MultiDBRoutingService > MultiDBRoutingServiceRef
Definition: MultiDBRoutingService.h:154
DatabaseRef database
Definition: MultiDBRoutingService.h:44
DatabaseId dbId
Definition: MultiDBRoutingService.h:43
std::shared_ptr< Database > DatabaseRef
Reference counted reference to an Database instance.
Definition: Database.h:555
Definition: RouteData.h:35
Distance Kilometers(double km)
Definition: Distance.h:362
SimpleRoutingServiceRef router
Definition: MultiDBRoutingService.h:46
RoutingProfileRef profile
Definition: MultiDBRoutingService.h:47
RoutingDatabaseRef routingDatabase
Definition: MultiDBRoutingService.h:45
Definition: Area.h:38
std::shared_ptr< RoutingDatabase > RoutingDatabaseRef
Definition: RoutingDB.h:101
std::shared_ptr< SimpleRoutingService > SimpleRoutingServiceRef
Definition: SimpleRoutingService.h:223
#define CLASS_FINAL
Definition: Compiler.h:26
std::shared_ptr< Area > AreaRef
Definition: Area.h:358
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
std::function< RoutingProfileRef(const DatabaseRef &)> RoutingProfileBuilder
Definition: MultiDBRoutingService.h:51
std::shared_ptr< RouteNode > RouteNodeRef
Definition: RouteNode.h:160
Definition: DBFileOffset.h:38
Definition: DBFileOffset.h:92
Definition: MultiDBRoutingState.h:39
Definition: RouteNode.h:61
uint32_t DatabaseId
Definition: DBFileOffset.h:30