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.
|
|
|
|
*/
|
|
|
|
|
2013-08-14 12:43:01 -04:00
|
|
|
// This class constructs the edge-expanded routing graph
|
2011-10-10 11:52:47 -04:00
|
|
|
|
|
|
|
#ifndef EDGEBASEDGRAPHFACTORY_H_
|
|
|
|
#define EDGEBASEDGRAPHFACTORY_H_
|
|
|
|
|
2011-11-09 10:12:05 -05:00
|
|
|
#include "../typedefs.h"
|
2012-05-23 15:18:38 -04:00
|
|
|
#include "../DataStructures/DeallocatingVector.h"
|
2011-11-09 10:12:05 -05:00
|
|
|
#include "../DataStructures/DynamicGraph.h"
|
2012-08-27 11:40:59 -04:00
|
|
|
#include "../Extractor/ExtractorStructs.h"
|
2012-01-02 07:09:20 -05:00
|
|
|
#include "../DataStructures/HashTable.h"
|
2011-11-09 10:12:05 -05:00
|
|
|
#include "../DataStructures/ImportEdge.h"
|
2012-04-25 04:51:16 -04:00
|
|
|
#include "../DataStructures/QueryEdge.h"
|
2011-11-09 10:12:05 -05:00
|
|
|
#include "../DataStructures/Percent.h"
|
2011-11-17 12:04:49 -05:00
|
|
|
#include "../DataStructures/TurnInstructions.h"
|
2013-06-26 09:49:00 -04:00
|
|
|
#include "../Util/LuaUtil.h"
|
2013-08-08 08:17:01 -04:00
|
|
|
#include "../Util/SimpleLogger.h"
|
2012-02-28 10:25:01 -05:00
|
|
|
|
2013-06-26 09:49:00 -04:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/unordered_map.hpp>
|
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
|
|
|
|
#include <algorithm>
|
2013-08-14 12:43:01 -04:00
|
|
|
#include <fstream>
|
2013-06-26 09:49:00 -04:00
|
|
|
#include <queue>
|
|
|
|
#include <vector>
|
2013-02-23 02:33:33 -05:00
|
|
|
|
2013-01-18 15:28:13 -05:00
|
|
|
class EdgeBasedGraphFactory : boost::noncopyable {
|
|
|
|
public:
|
|
|
|
struct EdgeBasedNode {
|
2013-06-27 11:44:32 -04:00
|
|
|
EdgeBasedNode() :
|
|
|
|
id(INT_MAX),
|
|
|
|
lat1(INT_MAX),
|
|
|
|
lat2(INT_MAX),
|
|
|
|
lon1(INT_MAX),
|
|
|
|
lon2(INT_MAX >> 1),
|
|
|
|
belongsToTinyComponent(false),
|
|
|
|
nameID(UINT_MAX),
|
|
|
|
weight(UINT_MAX >> 1),
|
|
|
|
ignoreInGrid(false)
|
|
|
|
{ }
|
2013-08-14 12:43:01 -04:00
|
|
|
|
2013-01-18 15:28:13 -05:00
|
|
|
bool operator<(const EdgeBasedNode & other) const {
|
|
|
|
return other.id < id;
|
|
|
|
}
|
2013-06-26 09:32:03 -04:00
|
|
|
|
2013-01-18 15:28:13 -05:00
|
|
|
bool operator==(const EdgeBasedNode & other) const {
|
|
|
|
return id == other.id;
|
|
|
|
}
|
2013-06-26 09:32:03 -04:00
|
|
|
|
2013-08-14 07:12:28 -04:00
|
|
|
inline FixedPointCoordinate Centroid() const {
|
|
|
|
FixedPointCoordinate centroid;
|
2013-06-26 09:32:03 -04:00
|
|
|
//The coordinates of the midpoint are given by:
|
|
|
|
//x = (x1 + x2) /2 and y = (y1 + y2) /2.
|
|
|
|
centroid.lon = (std::min(lon1, lon2) + std::max(lon1, lon2))/2;
|
|
|
|
centroid.lat = (std::min(lat1, lat2) + std::max(lat1, lat2))/2;
|
|
|
|
return centroid;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isIgnored() const {
|
|
|
|
return ignoreInGrid;
|
|
|
|
}
|
2013-08-14 07:12:28 -04:00
|
|
|
|
2013-01-18 15:28:13 -05:00
|
|
|
NodeID id;
|
|
|
|
int lat1;
|
|
|
|
int lat2;
|
|
|
|
int lon1;
|
|
|
|
int lon2:31;
|
|
|
|
bool belongsToTinyComponent:1;
|
|
|
|
NodeID nameID;
|
|
|
|
unsigned weight:31;
|
|
|
|
bool ignoreInGrid:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SpeedProfileProperties{
|
2013-08-14 12:43:01 -04:00
|
|
|
SpeedProfileProperties() :
|
|
|
|
trafficSignalPenalty(0),
|
|
|
|
uTurnPenalty(0),
|
|
|
|
has_turn_penalty_function(false)
|
|
|
|
{ }
|
|
|
|
|
2013-01-18 15:28:13 -05:00
|
|
|
int trafficSignalPenalty;
|
|
|
|
int uTurnPenalty;
|
2013-02-27 13:47:04 -05:00
|
|
|
bool has_turn_penalty_function;
|
2013-08-14 12:43:01 -04:00
|
|
|
} speed_profile;
|
2013-01-18 15:28:13 -05:00
|
|
|
|
2013-08-14 05:59:46 -04:00
|
|
|
explicit EdgeBasedGraphFactory(
|
2013-08-14 12:43:01 -04:00
|
|
|
int number_of_nodes,
|
|
|
|
std::vector<ImportEdge> & input_edge_list,
|
|
|
|
std::vector<NodeID> & barrier_node_list,
|
|
|
|
std::vector<NodeID> & traffic_light_node_list,
|
|
|
|
std::vector<TurnRestriction> & input_restrictions_list,
|
|
|
|
std::vector<NodeInfo> & m_node_info_list,
|
|
|
|
SpeedProfileProperties speed_profile
|
2013-08-14 05:59:46 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
void Run(const char * originalEdgeDataFilename, lua_State *myLuaState);
|
|
|
|
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
|
|
|
|
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
|
2013-08-14 12:43:01 -04:00
|
|
|
void GetOriginalEdgeData( std::vector<OriginalEdgeData> & originalEdgeData);
|
|
|
|
TurnInstruction AnalyzeTurn(
|
|
|
|
const NodeID u,
|
|
|
|
const NodeID v,
|
|
|
|
const NodeID w
|
|
|
|
) const;
|
|
|
|
int GetTurnPenalty(
|
|
|
|
const NodeID u,
|
|
|
|
const NodeID v,
|
|
|
|
const NodeID w,
|
|
|
|
lua_State *myLuaState
|
|
|
|
) const;
|
2013-08-14 05:59:46 -04:00
|
|
|
|
|
|
|
unsigned GetNumberOfNodes() const;
|
|
|
|
|
2011-10-10 11:52:47 -04:00
|
|
|
private:
|
2013-08-14 12:43:01 -04:00
|
|
|
struct NodeBasedEdgeData {
|
2011-11-16 11:29:00 -05:00
|
|
|
int distance;
|
2011-11-14 07:12:56 -05:00
|
|
|
unsigned edgeBasedNodeID;
|
2013-01-18 12:59:38 -05:00
|
|
|
unsigned nameID;
|
|
|
|
short type;
|
2013-02-14 11:11:18 -05:00
|
|
|
bool isAccessRestricted:1;
|
2011-11-25 06:02:52 -05:00
|
|
|
bool shortcut:1;
|
|
|
|
bool forward:1;
|
|
|
|
bool backward:1;
|
|
|
|
bool roundabout:1;
|
2011-12-16 08:05:30 -05:00
|
|
|
bool ignoreInGrid:1;
|
2013-02-14 11:11:18 -05:00
|
|
|
bool contraFlow:1;
|
2012-03-01 08:36:10 -05:00
|
|
|
};
|
2011-10-10 11:52:47 -04:00
|
|
|
|
2011-11-09 10:12:05 -05:00
|
|
|
struct _EdgeBasedEdgeData {
|
2011-11-16 11:29:00 -05:00
|
|
|
int distance;
|
2011-11-14 07:12:56 -05:00
|
|
|
unsigned via;
|
2011-11-16 12:10:51 -05:00
|
|
|
unsigned nameID;
|
2011-11-09 10:12:05 -05:00
|
|
|
bool forward;
|
|
|
|
bool backward;
|
2012-12-17 07:14:43 -05:00
|
|
|
TurnInstruction turnInstruction;
|
2011-11-09 10:12:05 -05:00
|
|
|
};
|
|
|
|
|
2013-08-14 05:59:46 -04:00
|
|
|
unsigned m_turn_restrictions_count;
|
|
|
|
|
2013-08-14 12:43:01 -04:00
|
|
|
typedef DynamicGraph<NodeBasedEdgeData> NodeBasedDynamicGraph;
|
|
|
|
typedef NodeBasedDynamicGraph::InputEdge NodeBasedEdge;
|
|
|
|
typedef NodeBasedDynamicGraph::NodeIterator NodeIterator;
|
|
|
|
typedef NodeBasedDynamicGraph::EdgeIterator EdgeIterator;
|
|
|
|
typedef NodeBasedDynamicGraph::EdgeData EdgeData;
|
|
|
|
typedef std::pair<NodeID, NodeID> RestrictionSource;
|
|
|
|
typedef std::pair<NodeID, bool> RestrictionTarget;
|
|
|
|
typedef std::vector<RestrictionTarget> EmanatingRestrictionsVector;
|
|
|
|
typedef boost::unordered_map<RestrictionSource, unsigned > RestrictionMap;
|
2012-09-13 08:12:44 -04:00
|
|
|
|
2013-08-14 12:43:01 -04:00
|
|
|
std::vector<NodeInfo> m_node_info_list;
|
|
|
|
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
|
|
|
|
std::vector<EdgeBasedNode> m_edge_based_node_list;
|
|
|
|
DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
|
2011-11-09 10:12:05 -05:00
|
|
|
|
2013-08-14 12:43:01 -04:00
|
|
|
boost::shared_ptr<NodeBasedDynamicGraph> m_node_based_graph;
|
|
|
|
boost::unordered_set<NodeID> m_barrier_nodes;
|
|
|
|
boost::unordered_set<NodeID> m_traffic_lights;
|
|
|
|
|
|
|
|
RestrictionMap m_restriction_map;
|
2012-02-29 14:02:04 -05:00
|
|
|
|
2011-10-10 11:52:47 -04:00
|
|
|
|
2013-08-14 12:43:01 -04:00
|
|
|
NodeID CheckForEmanatingIsOnlyTurn(
|
|
|
|
const NodeID u,
|
|
|
|
const NodeID v
|
|
|
|
) const;
|
|
|
|
|
|
|
|
bool CheckIfTurnIsRestricted(
|
|
|
|
const NodeID u,
|
|
|
|
const NodeID v,
|
|
|
|
const NodeID w
|
|
|
|
) const;
|
|
|
|
|
2012-03-01 13:41:06 -05:00
|
|
|
void InsertEdgeBasedNode(
|
2013-08-14 12:43:01 -04:00
|
|
|
NodeBasedDynamicGraph::EdgeIterator e1,
|
|
|
|
NodeBasedDynamicGraph::NodeIterator u,
|
|
|
|
NodeBasedDynamicGraph::NodeIterator v,
|
2012-07-13 11:01:21 -04:00
|
|
|
bool belongsToTinyComponent);
|
2011-10-10 11:52:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* EDGEBASEDGRAPHFACTORY_H_ */
|