2011-10-10 11:52:47 -04:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2011-10-10 11:52:47 -04:00
|
|
|
|
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"
|
2013-10-11 10:14:59 -04:00
|
|
|
#include "../DataStructures/EdgeBasedNode.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"
|
2013-12-09 11:45:45 -05:00
|
|
|
#include "../DataStructures/OriginalEdgeData.h"
|
2011-11-09 10:12:05 -05:00
|
|
|
#include "../DataStructures/Percent.h"
|
2013-11-25 13:05:58 -05:00
|
|
|
#include "../DataStructures/QueryEdge.h"
|
2014-01-09 10:13:35 -05:00
|
|
|
#include "../DataStructures/QueryNode.h"
|
2011-11-17 12:04:49 -05:00
|
|
|
#include "../DataStructures/TurnInstructions.h"
|
2014-01-09 10:13:35 -05:00
|
|
|
#include "../DataStructures/Restriction.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-11-25 13:05:58 -05:00
|
|
|
#include "GeometryCompressor.h"
|
|
|
|
|
2013-06-26 09:49:00 -04:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/unordered_map.hpp>
|
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
|
|
|
|
#include <algorithm>
|
2014-01-04 06:10:22 -05:00
|
|
|
#include <iosfwd>
|
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:
|
2014-01-04 06:10:22 -05:00
|
|
|
struct SpeedProfileProperties;
|
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,
|
2014-01-04 06:10:22 -05:00
|
|
|
SpeedProfileProperties & speed_profile
|
2013-08-14 05:59:46 -04:00
|
|
|
);
|
|
|
|
|
2014-01-04 06:10:22 -05:00
|
|
|
void Run(
|
|
|
|
const std::string & original_edge_data_filename,
|
|
|
|
const std::string & geometry_filename,
|
|
|
|
lua_State *myLuaState
|
|
|
|
);
|
2013-12-27 09:47:51 -05:00
|
|
|
|
2013-08-14 05:59:46 -04:00
|
|
|
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
|
2013-12-27 09:47:51 -05:00
|
|
|
|
2013-08-14 05:59:46 -04:00
|
|
|
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
|
2013-12-27 09:47:51 -05:00
|
|
|
|
2013-08-14 12:43:01 -04:00
|
|
|
TurnInstruction AnalyzeTurn(
|
|
|
|
const NodeID u,
|
|
|
|
const NodeID v,
|
|
|
|
const NodeID w
|
|
|
|
) const;
|
2013-12-27 09:47:51 -05:00
|
|
|
|
2013-08-14 12:43:01 -04:00
|
|
|
int GetTurnPenalty(
|
|
|
|
const NodeID u,
|
|
|
|
const NodeID v,
|
|
|
|
const NodeID w,
|
|
|
|
lua_State *myLuaState
|
|
|
|
) const;
|
2013-08-14 05:59:46 -04:00
|
|
|
|
2014-02-11 05:42:24 -05:00
|
|
|
unsigned GetNumberOfEdgeBasedNodes() const;
|
2013-08-14 05:59:46 -04:00
|
|
|
|
2014-01-04 06:10:22 -05:00
|
|
|
struct SpeedProfileProperties{
|
|
|
|
SpeedProfileProperties() :
|
|
|
|
trafficSignalPenalty(0),
|
|
|
|
uTurnPenalty(0),
|
|
|
|
has_turn_penalty_function(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
int trafficSignalPenalty;
|
|
|
|
int uTurnPenalty;
|
|
|
|
bool has_turn_penalty_function;
|
|
|
|
} speed_profile;
|
|
|
|
|
2011-10-10 11:52:47 -04:00
|
|
|
private:
|
2013-08-14 12:43:01 -04:00
|
|
|
struct NodeBasedEdgeData {
|
2014-05-01 08:31:48 -04:00
|
|
|
NodeBasedEdgeData() : distance(INVALID_EDGE_WEIGHT), edgeBasedNodeID(SPECIAL_NODEID), nameID(std::numeric_limits<unsigned>::max()),
|
|
|
|
type(std::numeric_limits<short>::max()), isAccessRestricted(false), shortcut(false), forward(false), backward(false),
|
|
|
|
roundabout(false), ignore_in_grid(false), contraFlow(false)
|
|
|
|
{ }
|
2014-02-11 05:42:24 -05:00
|
|
|
|
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;
|
2014-02-11 05:42:24 -05:00
|
|
|
bool ignore_in_grid:1;
|
2013-02-14 11:11:18 -05:00
|
|
|
bool contraFlow:1;
|
2014-01-04 06:10:22 -05:00
|
|
|
|
|
|
|
void SwapDirectionFlags() {
|
|
|
|
bool temp_flag = forward;
|
|
|
|
forward = backward;
|
|
|
|
backward = temp_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEqualTo( const NodeBasedEdgeData & other ) const {
|
|
|
|
return (forward == other.forward) &&
|
|
|
|
(backward == other.backward) &&
|
|
|
|
(nameID == other.nameID) &&
|
2014-02-11 05:42:24 -05:00
|
|
|
(ignore_in_grid == other.ignore_in_grid) &&
|
2014-01-04 06:10:22 -05:00
|
|
|
(contraFlow == other.contraFlow);
|
|
|
|
}
|
2012-03-01 08:36:10 -05:00
|
|
|
};
|
2011-10-10 11:52:47 -04:00
|
|
|
|
2013-11-29 13:00:00 -05:00
|
|
|
unsigned m_turn_restrictions_count;
|
2014-02-11 05:42:24 -05:00
|
|
|
unsigned m_number_of_edge_based_nodes;
|
2013-11-29 13:00:00 -05:00
|
|
|
|
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;
|
2014-01-04 06:10:22 -05:00
|
|
|
GeometryCompressor m_geometry_compressor;
|
2012-02-29 14:02:04 -05: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-11-26 13:43:30 -05:00
|
|
|
NodeBasedDynamicGraph::NodeIterator u,
|
|
|
|
NodeBasedDynamicGraph::NodeIterator v,
|
2014-02-18 13:26:57 -05:00
|
|
|
NodeBasedDynamicGraph::EdgeIterator e1,
|
2013-11-26 13:43:30 -05:00
|
|
|
bool belongsToTinyComponent
|
|
|
|
);
|
|
|
|
|
|
|
|
void BFSCompentExplorer(
|
|
|
|
std::vector<unsigned> & component_index_list,
|
|
|
|
std::vector<unsigned> & component_index_size
|
|
|
|
) const;
|
2013-11-28 12:50:12 -05:00
|
|
|
|
|
|
|
void FlushVectorToStream(
|
|
|
|
std::ofstream & edge_data_file,
|
|
|
|
std::vector<OriginalEdgeData> & original_edge_data_vector
|
|
|
|
) const;
|
2014-01-04 06:10:22 -05:00
|
|
|
|
|
|
|
void FixupArrivingTurnRestriction(
|
|
|
|
const NodeID u,
|
|
|
|
const NodeID v,
|
|
|
|
const NodeID w
|
|
|
|
);
|
|
|
|
|
|
|
|
void FixupStartingTurnRestriction(
|
|
|
|
const NodeID u,
|
|
|
|
const NodeID v,
|
|
|
|
const NodeID w
|
|
|
|
);
|
2014-03-19 11:42:37 -04:00
|
|
|
|
|
|
|
unsigned max_id;
|
2011-10-10 11:52:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* EDGEBASEDGRAPHFACTORY_H_ */
|