Refactoring graph factory
This commit is contained in:
parent
b01e30acfd
commit
0a0bed7ae0
@ -21,52 +21,56 @@
|
|||||||
#include "EdgeBasedGraphFactory.h"
|
#include "EdgeBasedGraphFactory.h"
|
||||||
|
|
||||||
EdgeBasedGraphFactory::EdgeBasedGraphFactory(
|
EdgeBasedGraphFactory::EdgeBasedGraphFactory(
|
||||||
int nodes, std::vector<ImportEdge> & inputEdges,
|
int number_of_nodes,
|
||||||
|
std::vector<ImportEdge> & input_edge_list,
|
||||||
std::vector<NodeID> & barrier_node_list,
|
std::vector<NodeID> & barrier_node_list,
|
||||||
std::vector<NodeID> & traffic_light_node_list,
|
std::vector<NodeID> & traffic_light_node_list,
|
||||||
std::vector<TurnRestriction> & input_restrictions_list,
|
std::vector<TurnRestriction> & input_restrictions_list,
|
||||||
std::vector<NodeInfo> & inputNodeInfoList,
|
std::vector<NodeInfo> & m_node_info_list,
|
||||||
SpeedProfileProperties speedProfile
|
SpeedProfileProperties speed_profile
|
||||||
) : speedProfile(speedProfile),
|
) : speed_profile(speed_profile),
|
||||||
m_turn_restrictions_count(0),
|
m_turn_restrictions_count(0),
|
||||||
inputNodeInfoList(inputNodeInfoList)
|
m_node_info_list(m_node_info_list)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) {
|
BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) {
|
||||||
std::pair<NodeID, NodeID> restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode);
|
std::pair<NodeID, NodeID> restriction_source =
|
||||||
|
std::make_pair(restriction.fromNode, restriction.viaNode);
|
||||||
unsigned index;
|
unsigned index;
|
||||||
RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource);
|
RestrictionMap::iterator restriction_iter = m_restriction_map.find(restriction_source);
|
||||||
if(restrIter == _restrictionMap.end()) {
|
if(restriction_iter == m_restriction_map.end()) {
|
||||||
index = _restrictionBucketVector.size();
|
index = m_restriction_bucket_list.size();
|
||||||
_restrictionBucketVector.resize(index+1);
|
m_restriction_bucket_list.resize(index+1);
|
||||||
_restrictionMap[restrictionSource] = index;
|
m_restriction_map[restriction_source] = index;
|
||||||
} else {
|
} else {
|
||||||
index = restrIter->second;
|
index = restriction_iter->second;
|
||||||
//Map already contains an is_only_*-restriction
|
//Map already contains an is_only_*-restriction
|
||||||
if(_restrictionBucketVector.at(index).begin()->second)
|
if(m_restriction_bucket_list.at(index).begin()->second) {
|
||||||
continue;
|
continue;
|
||||||
else if(restriction.flags.isOnly){
|
} else if(restriction.flags.isOnly) {
|
||||||
//We are going to insert an is_only_*-restriction. There can be only one.
|
//We are going to insert an is_only_*-restriction. There can be only one.
|
||||||
m_turn_restrictions_count -= _restrictionBucketVector.at(index).size();
|
m_turn_restrictions_count -= m_restriction_bucket_list.at(index).size();
|
||||||
_restrictionBucketVector.at(index).clear();
|
m_restriction_bucket_list.at(index).clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++m_turn_restrictions_count;
|
++m_turn_restrictions_count;
|
||||||
_restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly));
|
m_restriction_bucket_list.at(index).push_back(
|
||||||
|
std::make_pair( restriction.toNode, restriction.flags.isOnly)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_barrierNodes.insert(
|
m_barrier_nodes.insert(
|
||||||
barrier_node_list.begin(),
|
barrier_node_list.begin(),
|
||||||
barrier_node_list.end()
|
barrier_node_list.end()
|
||||||
);
|
);
|
||||||
|
|
||||||
_trafficLights.insert(
|
m_traffic_lights.insert(
|
||||||
traffic_light_node_list.begin(),
|
traffic_light_node_list.begin(),
|
||||||
traffic_light_node_list.end()
|
traffic_light_node_list.end()
|
||||||
);
|
);
|
||||||
|
|
||||||
DeallocatingVector< _NodeBasedEdge > edges;
|
DeallocatingVector< NodeBasedEdge > edges_list;
|
||||||
_NodeBasedEdge edge;
|
NodeBasedEdge edge;
|
||||||
BOOST_FOREACH(const ImportEdge & import_edge, inputEdges) {
|
BOOST_FOREACH(const ImportEdge & import_edge, input_edge_list) {
|
||||||
if(!import_edge.isForward()) {
|
if(!import_edge.isForward()) {
|
||||||
edge.source = import_edge.target();
|
edge.source = import_edge.target();
|
||||||
edge.target = import_edge.source();
|
edge.target = import_edge.source();
|
||||||
@ -89,139 +93,189 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(
|
|||||||
edge.data.nameID = import_edge.name();
|
edge.data.nameID = import_edge.name();
|
||||||
edge.data.type = import_edge.type();
|
edge.data.type = import_edge.type();
|
||||||
edge.data.isAccessRestricted = import_edge.isAccessRestricted();
|
edge.data.isAccessRestricted = import_edge.isAccessRestricted();
|
||||||
edge.data.edgeBasedNodeID = edges.size();
|
edge.data.edgeBasedNodeID = edges_list.size();
|
||||||
edge.data.contraFlow = import_edge.isContraFlow();
|
edge.data.contraFlow = import_edge.isContraFlow();
|
||||||
edges.push_back( edge );
|
edges_list.push_back( edge );
|
||||||
if( edge.data.backward ) {
|
if( edge.data.backward ) {
|
||||||
std::swap( edge.source, edge.target );
|
std::swap( edge.source, edge.target );
|
||||||
edge.data.forward = import_edge.isBackward();
|
edge.data.forward = import_edge.isBackward();
|
||||||
edge.data.backward = import_edge.isForward();
|
edge.data.backward = import_edge.isForward();
|
||||||
edge.data.edgeBasedNodeID = edges.size();
|
edge.data.edgeBasedNodeID = edges_list.size();
|
||||||
edges.push_back( edge );
|
edges_list.push_back( edge );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::vector<ImportEdge>().swap(inputEdges);
|
std::vector<ImportEdge>().swap(input_edge_list);
|
||||||
std::sort( edges.begin(), edges.end() );
|
std::sort( edges_list.begin(), edges_list.end() );
|
||||||
_nodeBasedGraph = boost::make_shared<_NodeBasedDynamicGraph>( nodes, edges );
|
m_node_based_graph = boost::make_shared<NodeBasedDynamicGraph>(
|
||||||
|
number_of_nodes, edges_list
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector< EdgeBasedEdge >& outputEdgeList ) {
|
void EdgeBasedGraphFactory::GetEdgeBasedEdges(
|
||||||
|
DeallocatingVector< EdgeBasedEdge >& output_edge_list
|
||||||
|
) {
|
||||||
BOOST_ASSERT_MSG(
|
BOOST_ASSERT_MSG(
|
||||||
0 == outputEdgeList.size(),
|
0 == output_edge_list.size(),
|
||||||
"Vector is not empty"
|
"Vector is not empty"
|
||||||
);
|
);
|
||||||
edgeBasedEdges.swap(outputEdgeList);
|
m_edge_based_edge_list.swap(output_edge_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector<EdgeBasedNode> & nodes) {
|
void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector<EdgeBasedNode> & nodes) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
BOOST_FOREACH(const EdgeBasedNode & node, edgeBasedNodes){
|
BOOST_FOREACH(const EdgeBasedNode & node, m_edge_based_node_list){
|
||||||
assert(node.lat1 != INT_MAX); assert(node.lon1 != INT_MAX);
|
assert(node.lat1 != INT_MAX); assert(node.lon1 != INT_MAX);
|
||||||
assert(node.lat2 != INT_MAX); assert(node.lon2 != INT_MAX);
|
assert(node.lat2 != INT_MAX); assert(node.lon2 != INT_MAX);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
nodes.swap(edgeBasedNodes);
|
nodes.swap(m_edge_based_node_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(
|
NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(
|
||||||
const NodeID u,
|
const NodeID u,
|
||||||
const NodeID v
|
const NodeID v
|
||||||
) const {
|
) const {
|
||||||
const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v);
|
const std::pair < NodeID, NodeID > restriction_source = std::make_pair(u, v);
|
||||||
RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource);
|
RestrictionMap::const_iterator restriction_iter = m_restriction_map.find(restriction_source);
|
||||||
if (restrIter != _restrictionMap.end()) {
|
if (restriction_iter != m_restriction_map.end()) {
|
||||||
const unsigned index = restrIter->second;
|
const unsigned index = restriction_iter->second;
|
||||||
BOOST_FOREACH(const RestrictionSource & restrictionTarget, _restrictionBucketVector.at(index)) {
|
BOOST_FOREACH(
|
||||||
if(restrictionTarget.second) {
|
const RestrictionSource & restriction_target,
|
||||||
return restrictionTarget.first;
|
m_restriction_bucket_list.at(index)
|
||||||
|
) {
|
||||||
|
if(restriction_target.second) {
|
||||||
|
return restriction_target.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return UINT_MAX;
|
return UINT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const {
|
bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted(
|
||||||
|
const NodeID u,
|
||||||
|
const NodeID v,
|
||||||
|
const NodeID w
|
||||||
|
) const {
|
||||||
//only add an edge if turn is not a U-turn except it is the end of dead-end street.
|
//only add an edge if turn is not a U-turn except it is the end of dead-end street.
|
||||||
const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v);
|
const std::pair < NodeID, NodeID > restriction_source = std::make_pair(u, v);
|
||||||
RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource);
|
RestrictionMap::const_iterator restriction_iter = m_restriction_map.find(restriction_source);
|
||||||
if (restrIter != _restrictionMap.end()) {
|
if (restriction_iter != m_restriction_map.end()) {
|
||||||
const unsigned index = restrIter->second;
|
const unsigned index = restriction_iter->second;
|
||||||
BOOST_FOREACH(const RestrictionTarget & restrictionTarget, _restrictionBucketVector.at(index)) {
|
BOOST_FOREACH(
|
||||||
if(w == restrictionTarget.first)
|
const RestrictionTarget & restriction_target,
|
||||||
|
m_restriction_bucket_list.at(index)
|
||||||
|
) {
|
||||||
|
if(w == restriction_target.first) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EdgeBasedGraphFactory::InsertEdgeBasedNode(
|
void EdgeBasedGraphFactory::InsertEdgeBasedNode(
|
||||||
_NodeBasedDynamicGraph::EdgeIterator e1,
|
EdgeIterator e1,
|
||||||
_NodeBasedDynamicGraph::NodeIterator u,
|
NodeIterator u,
|
||||||
_NodeBasedDynamicGraph::NodeIterator v,
|
NodeIterator v,
|
||||||
bool belongsToTinyComponent) {
|
bool belongsToTinyComponent) {
|
||||||
_NodeBasedDynamicGraph::EdgeData & data = _nodeBasedGraph->GetEdgeData(e1);
|
EdgeData & data = m_node_based_graph->GetEdgeData(e1);
|
||||||
EdgeBasedNode currentNode;
|
EdgeBasedNode currentNode;
|
||||||
currentNode.nameID = data.nameID;
|
currentNode.nameID = data.nameID;
|
||||||
currentNode.lat1 = inputNodeInfoList[u].lat;
|
currentNode.lat1 = m_node_info_list[u].lat;
|
||||||
currentNode.lon1 = inputNodeInfoList[u].lon;
|
currentNode.lon1 = m_node_info_list[u].lon;
|
||||||
currentNode.lat2 = inputNodeInfoList[v].lat;
|
currentNode.lat2 = m_node_info_list[v].lat;
|
||||||
currentNode.lon2 = inputNodeInfoList[v].lon;
|
currentNode.lon2 = m_node_info_list[v].lon;
|
||||||
currentNode.belongsToTinyComponent = belongsToTinyComponent;
|
currentNode.belongsToTinyComponent = belongsToTinyComponent;
|
||||||
currentNode.id = data.edgeBasedNodeID;
|
currentNode.id = data.edgeBasedNodeID;
|
||||||
currentNode.ignoreInGrid = data.ignoreInGrid;
|
currentNode.ignoreInGrid = data.ignoreInGrid;
|
||||||
currentNode.weight = data.distance;
|
currentNode.weight = data.distance;
|
||||||
edgeBasedNodes.push_back(currentNode);
|
m_edge_based_node_list.push_back(currentNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State *myLuaState) {
|
void EdgeBasedGraphFactory::Run(
|
||||||
Percent p(_nodeBasedGraph->GetNumberOfNodes());
|
const char * original_edge_data_filename,
|
||||||
int numberOfSkippedTurns(0);
|
lua_State *lua_state
|
||||||
int nodeBasedEdgeCounter(0);
|
) {
|
||||||
unsigned numberOfOriginalEdges(0);
|
SimpleLogger().Write() << "Identifying components of the road network";
|
||||||
std::ofstream originalEdgeDataOutFile(originalEdgeDataFilename, std::ios::binary);
|
|
||||||
originalEdgeDataOutFile.write((char*)&numberOfOriginalEdges, sizeof(unsigned));
|
|
||||||
|
|
||||||
|
Percent p(m_node_based_graph->GetNumberOfNodes());
|
||||||
|
unsigned skipped_turns_counter = 0;
|
||||||
|
unsigned node_based_edge_counter = 0;
|
||||||
|
unsigned original_edges_counter = 0;
|
||||||
|
|
||||||
SimpleLogger().Write() << "Identifying small components";
|
std::ofstream edge_data_file(
|
||||||
|
original_edge_data_filename,
|
||||||
|
std::ios::binary
|
||||||
|
);
|
||||||
|
|
||||||
|
//writes a dummy value that is updated later
|
||||||
|
edge_data_file.write(
|
||||||
|
(char*)&original_edges_counter,
|
||||||
|
sizeof(unsigned)
|
||||||
|
);
|
||||||
|
|
||||||
|
unsigned current_component = 0, current_component_size = 0;
|
||||||
//Run a BFS on the undirected graph and identify small components
|
//Run a BFS on the undirected graph and identify small components
|
||||||
std::queue<std::pair<NodeID, NodeID> > bfsQueue;
|
std::queue<std::pair<NodeID, NodeID> > bfs_queue;
|
||||||
std::vector<unsigned> componentsIndex(_nodeBasedGraph->GetNumberOfNodes(), UINT_MAX);
|
std::vector<unsigned> component_index_list(
|
||||||
std::vector<NodeID> vectorOfComponentSizes;
|
m_node_based_graph->GetNumberOfNodes(),
|
||||||
unsigned currentComponent = 0, sizeOfCurrentComponent = 0;
|
UINT_MAX
|
||||||
|
);
|
||||||
|
|
||||||
|
std::vector<NodeID> component_size_list;
|
||||||
//put unexplorered node with parent pointer into queue
|
//put unexplorered node with parent pointer into queue
|
||||||
for(NodeID node = 0, endNodes = _nodeBasedGraph->GetNumberOfNodes(); node < endNodes; ++node) {
|
for(
|
||||||
if(UINT_MAX == componentsIndex[node]) {
|
NodeID node = 0,
|
||||||
bfsQueue.push(std::make_pair(node, node));
|
last_node = m_node_based_graph->GetNumberOfNodes();
|
||||||
|
node < last_node;
|
||||||
|
++node
|
||||||
|
) {
|
||||||
|
if(UINT_MAX == component_index_list[node]) {
|
||||||
|
bfs_queue.push(std::make_pair(node, node));
|
||||||
//mark node as read
|
//mark node as read
|
||||||
componentsIndex[node] = currentComponent;
|
component_index_list[node] = current_component;
|
||||||
p.printIncrement();
|
p.printIncrement();
|
||||||
while(!bfsQueue.empty()) {
|
while(!bfs_queue.empty()) {
|
||||||
//fetch element from BFS queue
|
//fetch element from BFS queue
|
||||||
std::pair<NodeID, NodeID> currentQueueItem = bfsQueue.front();
|
std::pair<NodeID, NodeID> current_queue_item = bfs_queue.front();
|
||||||
bfsQueue.pop();
|
bfs_queue.pop();
|
||||||
// SimpleLogger().Write() << "sizeof queue: " << bfsQueue.size() << ", sizeOfCurrentComponents: " << sizeOfCurrentComponent << ", settled nodes: " << settledNodes++ << ", max: " << endNodes;
|
// SimpleLogger().Write() << "sizeof queue: " << bfs_queue.size() <<
|
||||||
const NodeID v = currentQueueItem.first; //current node
|
// ", current_component_sizes: " << current_component_size <<
|
||||||
const NodeID u = currentQueueItem.second; //parent
|
//", settled nodes: " << settledNodes++ << ", max: " << endNodes;
|
||||||
|
const NodeID v = current_queue_item.first; //current node
|
||||||
|
const NodeID u = current_queue_item.second; //parent
|
||||||
//increment size counter of current component
|
//increment size counter of current component
|
||||||
++sizeOfCurrentComponent;
|
++current_component_size;
|
||||||
const bool isBollardNode = (_barrierNodes.find(v) != _barrierNodes.end());
|
const bool is_barrier_node = (m_barrier_nodes.find(v) != m_barrier_nodes.end());
|
||||||
if(!isBollardNode) {
|
if(!is_barrier_node) {
|
||||||
const NodeID onlyToNode = CheckForEmanatingIsOnlyTurn(u, v);
|
const NodeID to_node_of_only_restriction = CheckForEmanatingIsOnlyTurn(u, v);
|
||||||
|
|
||||||
//relaxieren edge outgoing edge like below where edge-expanded graph
|
//relaxieren edge outgoing edge like below where edge-expanded graph
|
||||||
for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) {
|
for(
|
||||||
_NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2);
|
EdgeIterator e2 = m_node_based_graph->BeginEdges(v);
|
||||||
|
e2 < m_node_based_graph->EndEdges(v);
|
||||||
|
++e2
|
||||||
|
) {
|
||||||
|
NodeIterator w = m_node_based_graph->GetTarget(e2);
|
||||||
|
|
||||||
if(onlyToNode != UINT_MAX && w != onlyToNode) { //We are at an only_-restriction but not at the right turn.
|
if(
|
||||||
|
to_node_of_only_restriction != UINT_MAX &&
|
||||||
|
w != to_node_of_only_restriction
|
||||||
|
) {
|
||||||
|
//We are at an only_-restriction but not at the right turn.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if( u != w ) { //only add an edge if turn is not a U-turn except it is the end of dead-end street.
|
if( u != w ) {
|
||||||
if (!CheckIfTurnIsRestricted(u, v, w) ) { //only add an edge if turn is not prohibited
|
//only add an edge if turn is not a U-turn except
|
||||||
//insert next (node, parent) only if w has not yet been explored
|
//when it is at the end of a dead-end street.
|
||||||
if(UINT_MAX == componentsIndex[w]) {
|
if (!CheckIfTurnIsRestricted(u, v, w) ) {
|
||||||
|
//only add an edge if turn is not prohibited
|
||||||
|
if(UINT_MAX == component_index_list[w]) {
|
||||||
|
//insert next (node, parent) only if w has
|
||||||
|
//not yet been explored
|
||||||
//mark node as read
|
//mark node as read
|
||||||
componentsIndex[w] = currentComponent;
|
component_index_list[w] = current_component;
|
||||||
bfsQueue.push(std::make_pair(w,v));
|
bfs_queue.push(std::make_pair(w,v));
|
||||||
p.printIncrement();
|
p.printIncrement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,142 +284,206 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//push size into vector
|
//push size into vector
|
||||||
vectorOfComponentSizes.push_back(sizeOfCurrentComponent);
|
component_size_list.push_back(current_component_size);
|
||||||
//reset counters;
|
//reset counters;
|
||||||
sizeOfCurrentComponent = 0;
|
current_component_size = 0;
|
||||||
++currentComponent;
|
++current_component;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SimpleLogger().Write() << "identified: " << vectorOfComponentSizes.size() << " many components";
|
SimpleLogger().Write() <<
|
||||||
|
"identified: " << component_size_list.size() << " many components";
|
||||||
|
|
||||||
p.reinit(_nodeBasedGraph->GetNumberOfNodes());
|
p.reinit(m_node_based_graph->GetNumberOfNodes());
|
||||||
//loop over all edges and generate new set of nodes.
|
//loop over all edges and generate new set of nodes.
|
||||||
for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) {
|
for(
|
||||||
for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) {
|
NodeIterator u = 0,
|
||||||
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);
|
number_of_nodes = m_node_based_graph->GetNumberOfNodes();
|
||||||
|
u < number_of_nodes;
|
||||||
|
++u
|
||||||
|
) {
|
||||||
|
for(
|
||||||
|
EdgeIterator e1 = m_node_based_graph->BeginEdges(u),
|
||||||
|
last_edge = m_node_based_graph->EndEdges(u);
|
||||||
|
e1 < last_edge;
|
||||||
|
++e1
|
||||||
|
) {
|
||||||
|
NodeIterator v = m_node_based_graph->GetTarget(e1);
|
||||||
|
|
||||||
if(_nodeBasedGraph->GetEdgeData(e1).type != SHRT_MAX) {
|
if(m_node_based_graph->GetEdgeData(e1).type != SHRT_MAX) {
|
||||||
assert(e1 != UINT_MAX);
|
BOOST_ASSERT_MSG(e1 != UINT_MAX, "edge id invalid");
|
||||||
assert(u != UINT_MAX);
|
BOOST_ASSERT_MSG(u != UINT_MAX, "souce node invalid");
|
||||||
assert(v != UINT_MAX);
|
BOOST_ASSERT_MSG(v != UINT_MAX, "target node invalid");
|
||||||
//edges that end on bollard nodes may actually be in two distinct components
|
//Note: edges that end on barrier nodes or on a turn restriction
|
||||||
InsertEdgeBasedNode(e1, u, v, (std::min(vectorOfComponentSizes[componentsIndex[u]], vectorOfComponentSizes[componentsIndex[v]]) < 1000) );
|
//may actually be in two distinct components. We choose the smallest
|
||||||
|
const unsigned size_of_component = std::min(
|
||||||
|
component_size_list[component_index_list[u]],
|
||||||
|
component_size_list[component_index_list[v]]
|
||||||
|
);
|
||||||
|
|
||||||
|
InsertEdgeBasedNode( e1, u, v, size_of_component < 1000 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<NodeID>().swap(vectorOfComponentSizes);
|
std::vector<NodeID>().swap(component_size_list);
|
||||||
std::vector<NodeID>().swap(componentsIndex);
|
BOOST_ASSERT_MSG(
|
||||||
|
0 == component_size_list.capacity(),
|
||||||
|
"component size vector not deallocated"
|
||||||
|
);
|
||||||
|
std::vector<NodeID>().swap(component_index_list);
|
||||||
|
BOOST_ASSERT_MSG(
|
||||||
|
0 == component_index_list.capacity(),
|
||||||
|
"component index vector not deallocated"
|
||||||
|
);
|
||||||
std::vector<OriginalEdgeData> original_edge_data_vector;
|
std::vector<OriginalEdgeData> original_edge_data_vector;
|
||||||
original_edge_data_vector.reserve(10000);
|
original_edge_data_vector.reserve(10000);
|
||||||
|
|
||||||
//Loop over all turns and generate new set of edges.
|
//Loop over all turns and generate new set of edges.
|
||||||
//Three nested loop look super-linear, but we are dealing with a linear number of turns only.
|
//Three nested loop look super-linear, but we are dealing with a (kind of)
|
||||||
for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) {
|
//linear number of turns only.
|
||||||
for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) {
|
for(
|
||||||
++nodeBasedEdgeCounter;
|
NodeIterator u = 0,
|
||||||
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);
|
last_node = m_node_based_graph->GetNumberOfNodes();
|
||||||
bool isBollardNode = (_barrierNodes.find(v) != _barrierNodes.end());
|
u < last_node;
|
||||||
//EdgeWeight heightPenalty = ComputeHeightPenalty(u, v);
|
++u
|
||||||
NodeID onlyToNode = CheckForEmanatingIsOnlyTurn(u, v);
|
) {
|
||||||
for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) {
|
for(
|
||||||
const _NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2);
|
EdgeIterator e1 = m_node_based_graph->BeginEdges(u),
|
||||||
|
last_edge_u = m_node_based_graph->EndEdges(u);
|
||||||
if(onlyToNode != UINT_MAX && w != onlyToNode) { //We are at an only_-restriction but not at the right turn.
|
e1 < last_edge_u;
|
||||||
++numberOfSkippedTurns;
|
++e1
|
||||||
|
) {
|
||||||
|
++node_based_edge_counter;
|
||||||
|
NodeIterator v = m_node_based_graph->GetTarget(e1);
|
||||||
|
bool is_barrier_node = (m_barrier_nodes.find(v) != m_barrier_nodes.end());
|
||||||
|
NodeID to_node_of_only_restriction = CheckForEmanatingIsOnlyTurn(u, v);
|
||||||
|
for(
|
||||||
|
EdgeIterator e2 = m_node_based_graph->BeginEdges(v),
|
||||||
|
last_edge_v = m_node_based_graph->EndEdges(v);
|
||||||
|
e2 < last_edge_v;
|
||||||
|
++e2
|
||||||
|
) {
|
||||||
|
const NodeIterator w = m_node_based_graph->GetTarget(e2);
|
||||||
|
if(
|
||||||
|
to_node_of_only_restriction != UINT_MAX &&
|
||||||
|
w != to_node_of_only_restriction
|
||||||
|
) {
|
||||||
|
//We are at an only_-restriction but not at the right turn.
|
||||||
|
++skipped_turns_counter;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(u == w && 1 != _nodeBasedGraph->GetOutDegree(v) ) {
|
if(u == w && 1 != m_node_based_graph->GetOutDegree(v) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !isBollardNode ) { //only add an edge if turn is not a U-turn except it is the end of dead-end street.
|
if( !is_barrier_node ) {
|
||||||
if (!CheckIfTurnIsRestricted(u, v, w) || (onlyToNode != UINT_MAX && w == onlyToNode)) { //only add an edge if turn is not prohibited
|
//only add an edge if turn is not a U-turn except when it is
|
||||||
const _NodeBasedDynamicGraph::EdgeData edgeData1 = _nodeBasedGraph->GetEdgeData(e1);
|
//at the end of a dead-end street
|
||||||
const _NodeBasedDynamicGraph::EdgeData edgeData2 = _nodeBasedGraph->GetEdgeData(e2);
|
if (
|
||||||
assert(edgeData1.edgeBasedNodeID < _nodeBasedGraph->GetNumberOfEdges());
|
!CheckIfTurnIsRestricted(u, v, w) ||
|
||||||
assert(edgeData2.edgeBasedNodeID < _nodeBasedGraph->GetNumberOfEdges());
|
(to_node_of_only_restriction != UINT_MAX && w == to_node_of_only_restriction)
|
||||||
|
) { //only add an edge if turn is not prohibited
|
||||||
|
const EdgeData edge_data1 = m_node_based_graph->GetEdgeData(e1);
|
||||||
|
const EdgeData edge_data2 = m_node_based_graph->GetEdgeData(e2);
|
||||||
|
assert(edge_data1.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges());
|
||||||
|
assert(edge_data2.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges());
|
||||||
|
|
||||||
if(!edgeData1.forward || !edgeData2.forward) {
|
if(!edge_data1.forward || !edge_data2.forward) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned distance = edgeData1.distance;
|
unsigned distance = edge_data1.distance;
|
||||||
if(_trafficLights.find(v) != _trafficLights.end()) {
|
if(m_traffic_lights.find(v) != m_traffic_lights.end()) {
|
||||||
distance += speedProfile.trafficSignalPenalty;
|
distance += speed_profile.trafficSignalPenalty;
|
||||||
}
|
}
|
||||||
unsigned penalty = GetTurnPenalty(u, v, w, myLuaState);
|
const unsigned penalty =
|
||||||
|
GetTurnPenalty(u, v, w, lua_state);
|
||||||
TurnInstruction turnInstruction = AnalyzeTurn(u, v, w);
|
TurnInstruction turnInstruction = AnalyzeTurn(u, v, w);
|
||||||
if(turnInstruction == TurnInstructions.UTurn)
|
if(turnInstruction == TurnInstructions.UTurn){
|
||||||
distance += speedProfile.uTurnPenalty;
|
distance += speed_profile.uTurnPenalty;
|
||||||
// if(!edgeData1.isAccessRestricted && edgeData2.isAccessRestricted) {
|
}
|
||||||
// distance += TurnInstructions.AccessRestrictionPenalty;
|
|
||||||
// turnInstruction |= TurnInstructions.AccessRestrictionFlag;
|
|
||||||
// }
|
|
||||||
distance += penalty;
|
distance += penalty;
|
||||||
|
|
||||||
|
|
||||||
//distance += heightPenalty;
|
//distance += heightPenalty;
|
||||||
//distance += ComputeTurnPenalty(u, v, w);
|
//distance += ComputeTurnPenalty(u, v, w);
|
||||||
assert(edgeData1.edgeBasedNodeID != edgeData2.edgeBasedNodeID);
|
assert(edge_data1.edgeBasedNodeID != edge_data2.edgeBasedNodeID);
|
||||||
OriginalEdgeData oed(v,edgeData2.nameID, turnInstruction);
|
original_edge_data_vector.push_back(
|
||||||
original_edge_data_vector.push_back(oed);
|
OriginalEdgeData(
|
||||||
++numberOfOriginalEdges;
|
v,
|
||||||
|
edge_data2.nameID,
|
||||||
|
turnInstruction
|
||||||
|
)
|
||||||
|
);
|
||||||
|
++original_edges_counter;
|
||||||
|
|
||||||
if(original_edge_data_vector.size() > 100000) {
|
if(original_edge_data_vector.size() > 100000) {
|
||||||
originalEdgeDataOutFile.write((char*)&(original_edge_data_vector[0]), original_edge_data_vector.size()*sizeof(OriginalEdgeData));
|
edge_data_file.write(
|
||||||
|
(char*)&(original_edge_data_vector[0]),
|
||||||
|
original_edge_data_vector.size()*sizeof(OriginalEdgeData)
|
||||||
|
);
|
||||||
original_edge_data_vector.clear();
|
original_edge_data_vector.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeBasedEdge newEdge(edgeData1.edgeBasedNodeID, edgeData2.edgeBasedNodeID, edgeBasedEdges.size(), distance, true, false );
|
m_edge_based_edge_list.push_back(
|
||||||
edgeBasedEdges.push_back(newEdge);
|
EdgeBasedEdge(
|
||||||
|
edge_data1.edgeBasedNodeID,
|
||||||
|
edge_data2.edgeBasedNodeID,
|
||||||
|
m_edge_based_edge_list.size(),
|
||||||
|
distance,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
++numberOfSkippedTurns;
|
++skipped_turns_counter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.printIncrement();
|
p.printIncrement();
|
||||||
}
|
}
|
||||||
originalEdgeDataOutFile.write((char*)&(original_edge_data_vector[0]), original_edge_data_vector.size()*sizeof(OriginalEdgeData));
|
edge_data_file.write(
|
||||||
originalEdgeDataOutFile.seekp(std::ios::beg);
|
(char*)&(original_edge_data_vector[0]),
|
||||||
originalEdgeDataOutFile.write((char*)&numberOfOriginalEdges, sizeof(unsigned));
|
original_edge_data_vector.size()*sizeof(OriginalEdgeData)
|
||||||
originalEdgeDataOutFile.close();
|
);
|
||||||
|
edge_data_file.seekp(std::ios::beg);
|
||||||
|
edge_data_file.write(
|
||||||
|
(char*)&original_edges_counter,
|
||||||
|
sizeof(unsigned)
|
||||||
|
);
|
||||||
|
edge_data_file.close();
|
||||||
|
|
||||||
// SimpleLogger().Write() <<"Sorting edge-based Nodes";
|
SimpleLogger().Write() <<
|
||||||
// std::sort(edgeBasedNodes.begin(), edgeBasedNodes.end();
|
"Generated " << m_edge_based_node_list.size() << " edge based nodes";
|
||||||
// SimpleLogger().Write() <<"Removing duplicate nodes (if any)";
|
SimpleLogger().Write() <<
|
||||||
// edgeBasedNodes.erase( std::unique(edgeBasedNodes.begin(), edgeBasedNodes.end()), edgeBasedNodes.end() );
|
"Node-based graph contains " << node_based_edge_counter << " edges";
|
||||||
// SimpleLogger().Write() <<"Applying vector self-swap trick to free up memory";
|
SimpleLogger().Write() <<
|
||||||
// SimpleLogger().Write() <<"size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity();
|
"Edge-expanded graph ...";
|
||||||
// std::vector<EdgeBasedNode>(edgeBasedNodes).swap(edgeBasedNodes);
|
SimpleLogger().Write() <<
|
||||||
// SimpleLogger().Write() <<"size: " << edgeBasedNodes.size() << ", cap: " << edgeBasedNodes.capacity();
|
" contains " << m_edge_based_edge_list.size() << " edges";
|
||||||
SimpleLogger().Write() <<"Node-based graph contains " << nodeBasedEdgeCounter << " edges";
|
SimpleLogger().Write() <<
|
||||||
SimpleLogger().Write() <<"Edge-based graph contains " << edgeBasedEdges.size() << " edges";
|
" skips " << skipped_turns_counter << " turns, "
|
||||||
// SimpleLogger().Write() << "Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << 2*((double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter;
|
"defined by " << m_turn_restrictions_count << " restrictions";
|
||||||
SimpleLogger().Write() <<"Edge-based graph skipped " << numberOfSkippedTurns << " turns, defined by " << numberOfTurnRestrictions << " restrictions.";
|
|
||||||
SimpleLogger().Write() <<"Generated " << edgeBasedNodes.size() << " edge based nodes";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int EdgeBasedGraphFactory::GetTurnPenalty(
|
int EdgeBasedGraphFactory::GetTurnPenalty(
|
||||||
const NodeID u,
|
const NodeID u,
|
||||||
const NodeID v,
|
const NodeID v,
|
||||||
const NodeID w,
|
const NodeID w,
|
||||||
lua_State *myLuaState
|
lua_State *lua_state
|
||||||
) const {
|
) const {
|
||||||
const double angle = GetAngleBetweenTwoEdges(
|
const double angle = GetAngleBetweenThreeFixedPointCoordinates (
|
||||||
inputNodeInfoList[u],
|
m_node_info_list[u],
|
||||||
inputNodeInfoList[v],
|
m_node_info_list[v],
|
||||||
inputNodeInfoList[w]
|
m_node_info_list[w]
|
||||||
);
|
);
|
||||||
|
|
||||||
if( speedProfile.has_turn_penalty_function ) {
|
if( speed_profile.has_turn_penalty_function ) {
|
||||||
try {
|
try {
|
||||||
//call lua profile to compute turn penalty
|
//call lua profile to compute turn penalty
|
||||||
return luabind::call_function<int>(
|
return luabind::call_function<int>(
|
||||||
myLuaState,
|
lua_state,
|
||||||
"turn_function",
|
"turn_function",
|
||||||
180.-angle
|
180.-angle
|
||||||
);
|
);
|
||||||
@ -381,17 +499,15 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
|
|||||||
const NodeID v,
|
const NodeID v,
|
||||||
const NodeID w
|
const NodeID w
|
||||||
) const {
|
) const {
|
||||||
const double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
|
|
||||||
|
|
||||||
if(u == w) {
|
if(u == w) {
|
||||||
return TurnInstructions.UTurn;
|
return TurnInstructions.UTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
_NodeBasedDynamicGraph::EdgeIterator edge1 = _nodeBasedGraph->FindEdge(u, v);
|
EdgeIterator edge1 = m_node_based_graph->FindEdge(u, v);
|
||||||
_NodeBasedDynamicGraph::EdgeIterator edge2 = _nodeBasedGraph->FindEdge(v, w);
|
EdgeIterator edge2 = m_node_based_graph->FindEdge(v, w);
|
||||||
|
|
||||||
_NodeBasedDynamicGraph::EdgeData & data1 = _nodeBasedGraph->GetEdgeData(edge1);
|
EdgeData & data1 = m_node_based_graph->GetEdgeData(edge1);
|
||||||
_NodeBasedDynamicGraph::EdgeData & data2 = _nodeBasedGraph->GetEdgeData(edge2);
|
EdgeData & data2 = m_node_based_graph->GetEdgeData(edge2);
|
||||||
|
|
||||||
if(!data1.contraFlow && data2.contraFlow) {
|
if(!data1.contraFlow && data2.contraFlow) {
|
||||||
return TurnInstructions.EnterAgainstAllowedDirection;
|
return TurnInstructions.EnterAgainstAllowedDirection;
|
||||||
@ -403,7 +519,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
|
|||||||
//roundabouts need to be handled explicitely
|
//roundabouts need to be handled explicitely
|
||||||
if(data1.roundabout && data2.roundabout) {
|
if(data1.roundabout && data2.roundabout) {
|
||||||
//Is a turn possible? If yes, we stay on the roundabout!
|
//Is a turn possible? If yes, we stay on the roundabout!
|
||||||
if( 1 == (_nodeBasedGraph->EndEdges(v) - _nodeBasedGraph->BeginEdges(v)) ) {
|
if( 1 == m_node_based_graph->GetOutDegree(v) ) {
|
||||||
//No turn possible.
|
//No turn possible.
|
||||||
return TurnInstructions.NoTurn;
|
return TurnInstructions.NoTurn;
|
||||||
}
|
}
|
||||||
@ -421,31 +537,28 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//If street names stay the same and if we are certain that it is not a roundabout, we skip it.
|
//If street names stay the same and if we are certain that it is not a
|
||||||
if( (data1.nameID == data2.nameID) && (0 != data1.nameID)) {
|
//a segment of a roundabout, we skip it.
|
||||||
return TurnInstructions.NoTurn;
|
if( data1.nameID == data2.nameID ) {
|
||||||
}
|
//TODO: Here we should also do a small graph exploration to check for
|
||||||
if( (data1.nameID == data2.nameID) && (0 == data1.nameID) && (_nodeBasedGraph->GetOutDegree(v) <= 2) ) {
|
// more complex situations
|
||||||
return TurnInstructions.NoTurn;
|
if( 0 != data1.nameID ) {
|
||||||
|
return TurnInstructions.NoTurn;
|
||||||
|
} else if (m_node_based_graph->GetOutDegree(v) <= 2) {
|
||||||
|
return TurnInstructions.NoTurn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const double angle = GetAngleBetweenThreeFixedPointCoordinates (
|
||||||
|
m_node_info_list[u],
|
||||||
|
m_node_info_list[v],
|
||||||
|
m_node_info_list[w]
|
||||||
|
);
|
||||||
|
|
||||||
return TurnInstructions.GetTurnDirectionOfInstruction(angle);
|
return TurnInstructions.GetTurnDirectionOfInstruction(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const {
|
unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const {
|
||||||
return _nodeBasedGraph->GetNumberOfEdges();
|
return m_node_based_graph->GetNumberOfEdges();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
|
|
||||||
template<class CoordinateT>
|
|
||||||
double EdgeBasedGraphFactory::GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const {
|
|
||||||
const double v1x = (A.lon - C.lon)/COORDINATE_PRECISION;
|
|
||||||
const double v1y = lat2y(A.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION);
|
|
||||||
const double v2x = (B.lon - C.lon)/COORDINATE_PRECISION;
|
|
||||||
const double v2y = lat2y(B.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION);
|
|
||||||
|
|
||||||
double angle = (atan2(v2y,v2x) - atan2(v1y,v1x) )*180/M_PI;
|
|
||||||
while(angle < 0)
|
|
||||||
angle += 360;
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
@ -18,9 +18,7 @@
|
|||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
// This class constructs the edge-expanded routing graph
|
||||||
* This class constructs the edge base representation of a graph from a given node based edge list
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef EDGEBASEDGRAPHFACTORY_H_
|
#ifndef EDGEBASEDGRAPHFACTORY_H_
|
||||||
#define EDGEBASEDGRAPHFACTORY_H_
|
#define EDGEBASEDGRAPHFACTORY_H_
|
||||||
@ -31,15 +29,12 @@
|
|||||||
#include "../Extractor/ExtractorStructs.h"
|
#include "../Extractor/ExtractorStructs.h"
|
||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../DataStructures/ImportEdge.h"
|
#include "../DataStructures/ImportEdge.h"
|
||||||
#include "../DataStructures/MercatorUtil.h"
|
|
||||||
#include "../DataStructures/QueryEdge.h"
|
#include "../DataStructures/QueryEdge.h"
|
||||||
#include "../DataStructures/Percent.h"
|
#include "../DataStructures/Percent.h"
|
||||||
#include "../DataStructures/TurnInstructions.h"
|
#include "../DataStructures/TurnInstructions.h"
|
||||||
#include "../Util/LuaUtil.h"
|
#include "../Util/LuaUtil.h"
|
||||||
#include "../Util/SimpleLogger.h"
|
#include "../Util/SimpleLogger.h"
|
||||||
|
|
||||||
#include <stxxl.h>
|
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
@ -47,9 +42,8 @@
|
|||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
#include <boost/unordered_set.hpp>
|
#include <boost/unordered_set.hpp>
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -67,6 +61,7 @@ public:
|
|||||||
weight(UINT_MAX >> 1),
|
weight(UINT_MAX >> 1),
|
||||||
ignoreInGrid(false)
|
ignoreInGrid(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool operator<(const EdgeBasedNode & other) const {
|
bool operator<(const EdgeBasedNode & other) const {
|
||||||
return other.id < id;
|
return other.id < id;
|
||||||
}
|
}
|
||||||
@ -100,33 +95,47 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct SpeedProfileProperties{
|
struct SpeedProfileProperties{
|
||||||
SpeedProfileProperties() : trafficSignalPenalty(0), uTurnPenalty(0), has_turn_penalty_function(false) {}
|
SpeedProfileProperties() :
|
||||||
|
trafficSignalPenalty(0),
|
||||||
|
uTurnPenalty(0),
|
||||||
|
has_turn_penalty_function(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
int trafficSignalPenalty;
|
int trafficSignalPenalty;
|
||||||
int uTurnPenalty;
|
int uTurnPenalty;
|
||||||
bool has_turn_penalty_function;
|
bool has_turn_penalty_function;
|
||||||
} speedProfile;
|
} speed_profile;
|
||||||
|
|
||||||
explicit EdgeBasedGraphFactory(
|
explicit EdgeBasedGraphFactory(
|
||||||
int nodes,
|
int number_of_nodes,
|
||||||
std::vector<ImportEdge> & inputEdges,
|
std::vector<ImportEdge> & input_edge_list,
|
||||||
std::vector<NodeID> & _bollardNodes,
|
std::vector<NodeID> & barrier_node_list,
|
||||||
std::vector<NodeID> & trafficLights,
|
std::vector<NodeID> & traffic_light_node_list,
|
||||||
std::vector<TurnRestriction> & inputRestrictions,
|
std::vector<TurnRestriction> & input_restrictions_list,
|
||||||
std::vector<NodeInfo> & nI,
|
std::vector<NodeInfo> & m_node_info_list,
|
||||||
SpeedProfileProperties speedProfile
|
SpeedProfileProperties speed_profile
|
||||||
);
|
);
|
||||||
|
|
||||||
void Run(const char * originalEdgeDataFilename, lua_State *myLuaState);
|
void Run(const char * originalEdgeDataFilename, lua_State *myLuaState);
|
||||||
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
|
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
|
||||||
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
|
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
|
||||||
void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData);
|
void GetOriginalEdgeData( std::vector<OriginalEdgeData> & originalEdgeData);
|
||||||
TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const;
|
TurnInstruction AnalyzeTurn(
|
||||||
int GetTurnPenalty(const NodeID u, const NodeID v, const NodeID w, lua_State *myLuaState) const;
|
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;
|
||||||
|
|
||||||
unsigned GetNumberOfNodes() const;
|
unsigned GetNumberOfNodes() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct _NodeBasedEdgeData {
|
struct NodeBasedEdgeData {
|
||||||
int distance;
|
int distance;
|
||||||
unsigned edgeBasedNodeID;
|
unsigned edgeBasedNodeID;
|
||||||
unsigned nameID;
|
unsigned nameID;
|
||||||
@ -151,35 +160,44 @@ private:
|
|||||||
|
|
||||||
unsigned m_turn_restrictions_count;
|
unsigned m_turn_restrictions_count;
|
||||||
|
|
||||||
typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
|
typedef DynamicGraph<NodeBasedEdgeData> NodeBasedDynamicGraph;
|
||||||
typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge;
|
typedef NodeBasedDynamicGraph::InputEdge NodeBasedEdge;
|
||||||
std::vector<NodeInfo> inputNodeInfoList;
|
typedef NodeBasedDynamicGraph::NodeIterator NodeIterator;
|
||||||
unsigned numberOfTurnRestrictions;
|
typedef NodeBasedDynamicGraph::EdgeIterator EdgeIterator;
|
||||||
|
typedef NodeBasedDynamicGraph::EdgeData EdgeData;
|
||||||
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
|
typedef std::pair<NodeID, NodeID> RestrictionSource;
|
||||||
boost::unordered_set<NodeID> _barrierNodes;
|
typedef std::pair<NodeID, bool> RestrictionTarget;
|
||||||
boost::unordered_set<NodeID> _trafficLights;
|
typedef std::vector<RestrictionTarget> EmanatingRestrictionsVector;
|
||||||
|
|
||||||
typedef std::pair<NodeID, NodeID> RestrictionSource;
|
|
||||||
typedef std::pair<NodeID, bool> RestrictionTarget;
|
|
||||||
typedef std::vector<RestrictionTarget> EmanatingRestrictionsVector;
|
|
||||||
typedef boost::unordered_map<RestrictionSource, unsigned > RestrictionMap;
|
typedef boost::unordered_map<RestrictionSource, unsigned > RestrictionMap;
|
||||||
std::vector<EmanatingRestrictionsVector> _restrictionBucketVector;
|
|
||||||
RestrictionMap _restrictionMap;
|
|
||||||
|
|
||||||
DeallocatingVector<EdgeBasedEdge> edgeBasedEdges;
|
std::vector<NodeInfo> m_node_info_list;
|
||||||
std::vector<EdgeBasedNode> edgeBasedNodes;
|
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
|
||||||
|
std::vector<EdgeBasedNode> m_edge_based_node_list;
|
||||||
|
DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
NodeID CheckForEmanatingIsOnlyTurn(
|
||||||
|
const NodeID u,
|
||||||
|
const NodeID v
|
||||||
|
) const;
|
||||||
|
|
||||||
|
bool CheckIfTurnIsRestricted(
|
||||||
|
const NodeID u,
|
||||||
|
const NodeID v,
|
||||||
|
const NodeID w
|
||||||
|
) const;
|
||||||
|
|
||||||
NodeID CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const;
|
|
||||||
bool CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const;
|
|
||||||
void InsertEdgeBasedNode(
|
void InsertEdgeBasedNode(
|
||||||
_NodeBasedDynamicGraph::EdgeIterator e1,
|
NodeBasedDynamicGraph::EdgeIterator e1,
|
||||||
_NodeBasedDynamicGraph::NodeIterator u,
|
NodeBasedDynamicGraph::NodeIterator u,
|
||||||
_NodeBasedDynamicGraph::NodeIterator v,
|
NodeBasedDynamicGraph::NodeIterator v,
|
||||||
bool belongsToTinyComponent);
|
bool belongsToTinyComponent);
|
||||||
template<class CoordinateT>
|
|
||||||
double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* EDGEBASEDGRAPHFACTORY_H_ */
|
#endif /* EDGEBASEDGRAPHFACTORY_H_ */
|
||||||
|
@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef FIXED_POINT_COORDINATE_H_
|
#ifndef FIXED_POINT_COORDINATE_H_
|
||||||
#define FIXED_POINT_COORDINATE_H_
|
#define FIXED_POINT_COORDINATE_H_
|
||||||
|
|
||||||
|
#include "../DataStructures/MercatorUtil.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@ -35,7 +36,7 @@ struct FixedPointCoordinate {
|
|||||||
int lat;
|
int lat;
|
||||||
int lon;
|
int lon;
|
||||||
FixedPointCoordinate () : lat(INT_MIN), lon(INT_MIN) {}
|
FixedPointCoordinate () : lat(INT_MIN), lon(INT_MIN) {}
|
||||||
explicit FixedPointCoordinate (int t, int n) : lat(t) , lon(n) {}
|
explicit FixedPointCoordinate (int lat, int lon) : lat(lat) , lon(lon) {}
|
||||||
|
|
||||||
void Reset() {
|
void Reset() {
|
||||||
lat = INT_MIN;
|
lat = INT_MIN;
|
||||||
@ -141,4 +142,22 @@ static inline void convertInternalReversedCoordinateToString(const FixedPointCoo
|
|||||||
output += " ";
|
output += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/
|
||||||
|
template<class CoordinateT>
|
||||||
|
static inline double GetAngleBetweenThreeFixedPointCoordinates (
|
||||||
|
const CoordinateT & A,
|
||||||
|
const CoordinateT & C,
|
||||||
|
const CoordinateT & B
|
||||||
|
) {
|
||||||
|
const double v1x = (A.lon - C.lon)/COORDINATE_PRECISION;
|
||||||
|
const double v1y = lat2y(A.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION);
|
||||||
|
const double v2x = (B.lon - C.lon)/COORDINATE_PRECISION;
|
||||||
|
const double v2y = lat2y(B.lat/COORDINATE_PRECISION) - lat2y(C.lat/COORDINATE_PRECISION);
|
||||||
|
|
||||||
|
double angle = (atan2(v2y,v2x) - atan2(v1y,v1x) )*180/M_PI;
|
||||||
|
while(angle < 0)
|
||||||
|
angle += 360;
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
#endif /* FIXED_POINT_COORDINATE_H_ */
|
#endif /* FIXED_POINT_COORDINATE_H_ */
|
||||||
|
@ -18,8 +18,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef QUERYEDGE_H_
|
#ifndef QUERYEDGE_H_
|
||||||
#define QUERYEDGE_H_
|
#define QUERYEDGE_H_
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user