osrm-backend/Contractor/EdgeBasedGraphFactory.h

214 lines
6.8 KiB
C
Raw Normal View History

2011-10-10 11:52:47 -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_
#include "../typedefs.h"
#include "../DataStructures/DeallocatingVector.h"
#include "../DataStructures/DynamicGraph.h"
#include "../DataStructures/EdgeBasedNode.h"
#include "../DataStructures/HashTable.h"
#include "../DataStructures/ImportEdge.h"
#include "../DataStructures/OriginalEdgeData.h"
#include "../DataStructures/Percent.h"
2013-11-25 13:05:58 -05:00
#include "../DataStructures/QueryEdge.h"
#include "../DataStructures/QueryNode.h"
2011-11-17 12:04:49 -05:00
#include "../DataStructures/TurnInstructions.h"
#include "../DataStructures/Restriction.h"
#include "../Util/LuaUtil.h"
#include "../Util/SimpleLogger.h"
2013-11-25 13:05:58 -05:00
#include "GeometryCompressor.h"
#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>
#include <queue>
#include <vector>
2013-02-23 02:33:33 -05:00
class EdgeBasedGraphFactory : boost::noncopyable {
public:
2014-01-04 06:10:22 -05:00
struct SpeedProfileProperties;
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-02-11 05:42:24 -05:00
NodeBasedEdgeData() {
//TODO: proper c'tor
edgeBasedNodeID = UINT_MAX;
}
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;
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;
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);
}
};
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;
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;
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;
void InsertEdgeBasedNode(
NodeBasedDynamicGraph::NodeIterator u,
NodeBasedDynamicGraph::NodeIterator v,
NodeBasedDynamicGraph::EdgeIterator e1,
bool belongsToTinyComponent
);
void BFSCompentExplorer(
std::vector<unsigned> & component_index_list,
std::vector<unsigned> & component_index_size
) const;
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
);
unsigned max_id;
2011-10-10 11:52:47 -04:00
};
#endif /* EDGEBASEDGRAPHFACTORY_H_ */