Root/
| 1 | /* |
| 2 | Copyright 2010 Christian Vetter veaac.fdirct@gmail.com |
| 3 | |
| 4 | This file is part of MoNav. |
| 5 | |
| 6 | MoNav is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | MoNav is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with MoNav. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef CONTRACTIONHIERARCHIESCLIENT_H |
| 21 | #define CONTRACTIONHIERARCHIESCLIENT_H |
| 22 | |
| 23 | #include <QObject> |
| 24 | #include <QStringList> |
| 25 | #include "interfaces/irouter.h" |
| 26 | #include "binaryheap.h" |
| 27 | #include "compressedgraph.h" |
| 28 | #include <queue> |
| 29 | |
| 30 | class ContractionHierarchiesClient : public QObject, public IRouter |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | Q_INTERFACES( IRouter ) |
| 34 | public: |
| 35 | ContractionHierarchiesClient(); |
| 36 | virtual ~ContractionHierarchiesClient(); |
| 37 | |
| 38 | virtual QString GetName(); |
| 39 | virtual void SetInputDirectory( const QString& dir ); |
| 40 | virtual void ShowSettings(); |
| 41 | virtual bool LoadData(); |
| 42 | virtual bool GetRoute( double* distance, QVector< Node>* pathNodes, QVector< Edge >* pathEdges, const IGPSLookup::Result& source, const IGPSLookup::Result& target ); |
| 43 | virtual bool GetName( QString* result, unsigned name ); |
| 44 | virtual bool GetNames( QVector< QString >* result, QVector< unsigned > names ); |
| 45 | virtual bool GetType( QString* result, unsigned type ); |
| 46 | virtual bool GetTypes( QVector< QString >* result, QVector< unsigned > types ); |
| 47 | |
| 48 | protected: |
| 49 | struct HeapData { |
| 50 | CompressedGraph::NodeIterator parent; |
| 51 | bool stalled: 1; |
| 52 | HeapData( CompressedGraph::NodeIterator p ) { |
| 53 | parent = p; |
| 54 | stalled = false; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | class AllowForwardEdge { |
| 59 | public: |
| 60 | bool operator()( bool forward, bool /*backward*/ ) const { |
| 61 | return forward; |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | class AllowBackwardEdge { |
| 66 | public: |
| 67 | bool operator()( bool /*forward*/, bool backward ) const { |
| 68 | return backward; |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | typedef CompressedGraph::NodeIterator NodeIterator; |
| 73 | typedef CompressedGraph::EdgeIterator EdgeIterator; |
| 74 | typedef BinaryHeap< NodeIterator, int, int, HeapData, MapStorage< NodeIterator, unsigned > > Heap; |
| 75 | |
| 76 | CompressedGraph m_graph; |
| 77 | const char* m_names; |
| 78 | QFile m_namesFile; |
| 79 | Heap* m_heapForward; |
| 80 | Heap* m_heapBackward; |
| 81 | std::queue< NodeIterator > m_stallQueue; |
| 82 | QString m_directory; |
| 83 | QStringList m_types; |
| 84 | |
| 85 | void unload(); |
| 86 | template< class EdgeAllowed, class StallEdgeAllowed > |
| 87 | void computeStep( Heap* heapForward, Heap* heapBackward, const EdgeAllowed& edgeAllowed, const StallEdgeAllowed& stallEdgeAllowed, NodeIterator* middle, int* targetDistance ); |
| 88 | int computeRoute( const IGPSLookup::Result& source, const IGPSLookup::Result& target, QVector< Node>* pathNodes, QVector< Edge >* pathEdges ); |
| 89 | bool unpackEdge( const NodeIterator source, const NodeIterator target, bool forward, QVector< Node>* pathNodes, QVector< Edge >* pathEdges ); |
| 90 | |
| 91 | }; |
| 92 | |
| 93 | #endif // CONTRACTIONHIERARCHIESCLIENT_H |
| 94 |
Branches:
master
