1
/***************************************************************************
2
* Copyright (C) 2009 by Sergey Yakushev *
3
* yakushevs <at> list.ru *
5
* This is file define road-graph plugins utils *
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
11
***************************************************************************/
12
#ifndef ROADGRAPHPLUGIN_UTILS_H
13
#define ROADGRAPHPLUGIN_UTILS_H
25
// forward declaration Qgis-classes
28
@author Sergey Yakushev
32
* \brief return big const double value
37
* return distance from length <x1,y1><x2,y2> to point <x,y> or infinity() value
40
double distance( const QgsPoint& p1, const QgsPoint& p2, const QgsPoint& p, QgsPoint& center );
43
* \class QgsPointCompare
44
* \brief This class implement operation "<", ">", "==" and etc. for use QgsPoint type in STL containers
50
bool operator()( const QgsPoint& a, const QgsPoint& b ) const;
54
* \class ArcAttributes
55
* \brief This class contained arcs attributes.
61
ArcAttributes( double cost, double time, int mFeatureId );
68
typedef std::map< QgsPoint, ArcAttributes, QgsPointCompare > AdjacencyMatrixString;
69
typedef std::map< QgsPoint, AdjacencyMatrixString, QgsPointCompare > AdjacencyMatrix;
73
* \class DijkstraFinder
74
* \brief This class find shortest path via two points using Dijkstra's algorithm
79
enum OptimizationCriterion { byTime = 1, byCost = 2 };
81
class DijkstraIterator
94
class CompareDijkstraIterator
97
CompareDijkstraIterator( OptimizationCriterion criterion = byCost ) :
98
mCriterion( criterion )
100
bool operator()( const DijkstraIterator& a, const DijkstraIterator& b ) const
102
if ( mCriterion == byCost )
104
return a.mCost < b.mCost;
106
return a.mTime < b.mTime;
108
bool operator==( const CompareDijkstraIterator& a ) const
110
return mCriterion == a.mCriterion;
113
OptimizationCriterion mCriterion;
118
* m is adjacency matrix of graph, criterion is a citerion of shortest path
120
DijkstraFinder( const AdjacencyMatrix &m, OptimizationCriterion criterion );
123
* find all shortest path from point frontPoint to all points of graph.
126
std::map< QgsPoint , DijkstraIterator, QgsPointCompare > find( const QgsPoint& p );
129
* return shortest path form point frontPoint to endPoint
131
AdjacencyMatrix find( const QgsPoint& frontPoint, const QgsPoint& endPoint );
134
const AdjacencyMatrix& mAdjacencyMatrix;
135
OptimizationCriterion mCriterion;