SVN checkout 11/12/2010
[monav:monav.git] / plugins / contractionhierarchies / contractionhierarchiesclient.h
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 IsCompatible( int fileFormatVersion );
42         virtual bool LoadData();
43         virtual bool GetRoute( double* distance, QVector< Node>* pathNodes, QVector< Edge >* pathEdges, const IGPSLookup::Result& source, const IGPSLookup::Result& target );
44         virtual bool GetName( QString* result, unsigned name );
45         virtual bool GetNames( QVector< QString >* result, QVector< unsigned > names );
46         virtual bool GetType( QString* result, unsigned type );
47         virtual bool GetTypes( QVector< QString >* result, QVector< unsigned > types );
48
49 protected:
50         struct HeapData {
51                 CompressedGraph::NodeIterator parent;
52                 bool stalled: 1;
53                 HeapData( CompressedGraph::NodeIterator p ) {
54                         parent = p;
55                         stalled = false;
56                 }
57         };
58
59         class AllowForwardEdge {
60                 public:
61                         bool operator()( bool forward, bool /*backward*/ ) const {
62                                 return forward;
63                         }
64         };
65
66         class AllowBackwardEdge {
67                 public:
68                         bool operator()( bool /*forward*/, bool backward ) const {
69                                 return backward;
70                         }
71         };
72
73         typedef CompressedGraph::NodeIterator NodeIterator;
74         typedef CompressedGraph::EdgeIterator EdgeIterator;
75         typedef BinaryHeap< NodeIterator, int, int, HeapData, MapStorage< NodeIterator, unsigned > > Heap;
76
77         CompressedGraph m_graph;
78         const char* m_names;
79         QFile m_namesFile;
80         Heap* m_heapForward;
81         Heap* m_heapBackward;
82         std::queue< NodeIterator > m_stallQueue;
83         QString m_directory;
84         QStringList m_types;
85
86         void unload();
87         template< class EdgeAllowed, class StallEdgeAllowed >
88         void computeStep( Heap* heapForward, Heap* heapBackward, const EdgeAllowed& edgeAllowed, const StallEdgeAllowed& stallEdgeAllowed, NodeIterator* middle, int* targetDistance );
89         int computeRoute( const IGPSLookup::Result& source, const IGPSLookup::Result& target, QVector< Node>* pathNodes, QVector< Edge >* pathEdges );
90         bool unpackEdge( const NodeIterator source, const NodeIterator target, bool forward, QVector< Node>* pathNodes, QVector< Edge >* pathEdges );
91
92 };
93
94 #endif // CONTRACTIONHIERARCHIESCLIENT_H