osrm-backend/Contractor/EdgeBasedGraphFactory.h

141 lines
4.9 KiB
C
Raw Normal View History

2011-10-10 11:52:47 -04:00
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
/*
* This class constructs the edge base representation of a graph from a given node based edge list
*/
#ifndef EDGEBASEDGRAPHFACTORY_H_
#define EDGEBASEDGRAPHFACTORY_H_
#include <boost/shared_ptr.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
2011-10-10 11:52:47 -04:00
#include <vector>
#include <stxxl.h>
#include <cstdlib>
#include "../typedefs.h"
#include "../DataStructures/DeallocatingVector.h"
#include "../DataStructures/DynamicGraph.h"
#include "../DataStructures/ExtractorStructs.h"
#include "../DataStructures/HashTable.h"
#include "../DataStructures/ImportEdge.h"
#include "../DataStructures/QueryEdge.h"
#include "../DataStructures/Percent.h"
2011-11-17 12:04:49 -05:00
#include "../DataStructures/TurnInstructions.h"
#include "../Util/BaseConfiguration.h"
2011-12-14 13:01:57 -05:00
//#include "../Util/SRTMLookup.h"
2011-10-10 11:52:47 -04:00
class EdgeBasedGraphFactory {
private:
struct _NodeBasedEdgeData {
2011-11-16 11:29:00 -05:00
int distance;
2011-11-14 07:12:56 -05:00
unsigned edgeBasedNodeID;
unsigned nameID:31;
2011-11-25 06:02:52 -05:00
bool shortcut:1;
bool forward:1;
bool backward:1;
bool roundabout:1;
bool ignoreInGrid:1;
2011-11-14 07:12:56 -05:00
short type;
bool isAccessRestricted;
};
2011-10-10 11:52:47 -04:00
struct _EdgeBasedEdgeData {
2011-11-16 11:29:00 -05:00
int distance;
2011-11-14 07:12:56 -05:00
unsigned via;
unsigned nameID;
bool forward;
bool backward;
2011-11-14 07:12:56 -05:00
short turnInstruction;
};
2011-10-10 11:52:47 -04:00
typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge;
public:
2011-11-14 07:12:56 -05:00
struct EdgeBasedNode {
bool operator<(const EdgeBasedNode & other) const {
return other.id < id;
}
bool operator==(const EdgeBasedNode & other) const {
return id == other.id;
}
2012-05-11 09:11:13 -04:00
NodeID id;
2011-11-14 07:12:56 -05:00
int lat1;
int lat2;
int lon1;
2012-07-13 11:01:21 -04:00
int lon2:31;
bool belongsToTinyComponent:1;
2011-11-15 10:24:13 -05:00
NodeID nameID;
unsigned weight:31;
bool ignoreInGrid:1;
2011-11-14 07:12:56 -05:00
};
private:
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
boost::unordered_map<NodeID, bool> _barrierNodes;
boost::unordered_map<NodeID, bool> _trafficLights;
2012-02-29 14:02:04 -05:00
typedef std::pair<NodeID, NodeID> RestrictionSource;
typedef std::pair<NodeID, bool> RestrictionTarget;
typedef std::vector<RestrictionTarget> EmanatingRestrictionsVector;
typedef boost::unordered_map<RestrictionSource, unsigned > RestrictionMap;
std::vector<EmanatingRestrictionsVector> _restrictionBucketVector;
RestrictionMap _restrictionMap;
2011-10-10 11:52:47 -04:00
DeallocatingVector<EdgeBasedEdge> edgeBasedEdges;
2012-04-25 12:36:18 -04:00
std::vector<EdgeBasedNode> edgeBasedNodes;
std::vector<OriginalEdgeData> originalEdgeData;
std::vector<NodeInfo> inputNodeInfoList;
2011-10-10 11:52:47 -04:00
2012-02-29 14:02:04 -05:00
NodeID CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const;
bool CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const;
void InsertEdgeBasedNode(
_NodeBasedDynamicGraph::EdgeIterator e1,
_NodeBasedDynamicGraph::NodeIterator u,
2012-07-13 11:01:21 -04:00
_NodeBasedDynamicGraph::NodeIterator v,
bool belongsToTinyComponent);
template<class CoordinateT>
double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const;
2011-12-14 13:01:57 -05:00
// SRTMLookup srtmLookup;
2012-02-29 14:02:04 -05:00
unsigned numberOfTurnRestrictions;
2012-03-05 03:36:20 -05:00
unsigned trafficSignalPenalty;
unsigned uturnPenalty;
bool takeMinimumOfSpeeds;
2011-12-14 13:01:57 -05:00
2011-10-10 11:52:47 -04:00
public:
template< class InputEdgeT >
explicit EdgeBasedGraphFactory(int nodes, std::vector<InputEdgeT> & inputEdges, std::vector<NodeID> & _bollardNodes, std::vector<NodeID> & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector<NodeInfo> & nI, boost::property_tree::ptree speedProfile, std::string & srtm);
2011-10-10 11:52:47 -04:00
void Run(const char * originalEdgeDataFilename);
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
2011-11-14 07:12:56 -05:00
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData);
2011-11-17 12:04:49 -05:00
short AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const;
unsigned GetNumberOfNodes() const;
2011-10-10 11:52:47 -04:00
};
#endif /* EDGEBASEDGRAPHFACTORY_H_ */