Skip to content

Commit

Permalink
mode flags
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed May 12, 2013
1 parent 9588ef0 commit b03ccfa
Show file tree
Hide file tree
Showing 44 changed files with 1,006 additions and 645 deletions.
40 changes: 18 additions & 22 deletions Algorithms/StronglyConnectedComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class TarjanSCC {
unsigned edgeBasedNodeID;
unsigned nameID:31;
bool shortcut:1;
short type;
bool isAccessRestricted:1;
bool forward:1;
bool backward:1;
Expand Down Expand Up @@ -165,7 +164,6 @@ class TarjanSCC {
edge.data.roundabout = i->isRoundabout();
edge.data.ignoreInGrid = i->ignoreInGrid();
edge.data.nameID = i->name();
edge.data.type = i->type();
edge.data.isAccessRestricted = i->isAccessRestricted();
edge.data.edgeBasedNodeID = edges.size();
edges.push_back( edge );
Expand Down Expand Up @@ -312,27 +310,25 @@ class TarjanSCC {
for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) {
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);

if(_nodeBasedGraph->GetEdgeData(e1).type != SHRT_MAX) {
assert(e1 != UINT_MAX);
assert(u != UINT_MAX);
assert(v != UINT_MAX);
//edges that end on bollard nodes may actually be in two distinct components
if(std::min(vectorOfComponentSizes[componentsIndex[u]], vectorOfComponentSizes[componentsIndex[v]]) < 10) {

//INFO("(" << inputNodeInfoList[u].lat/100000. << ";" << inputNodeInfoList[u].lon/100000. << ") -> (" << inputNodeInfoList[v].lat/100000. << ";" << inputNodeInfoList[v].lon/100000. << ")");
OGRLineString lineString;
lineString.addPoint(inputNodeInfoList[u].lon/100000., inputNodeInfoList[u].lat/100000.);
lineString.addPoint(inputNodeInfoList[v].lon/100000., inputNodeInfoList[v].lat/100000.);

OGRFeature *poFeature;
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
poFeature->SetGeometry( &lineString );
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
{
ERR( "Failed to create feature in shapefile.\n" );
}
OGRFeature::DestroyFeature( poFeature );
assert(e1 != UINT_MAX);
assert(u != UINT_MAX);
assert(v != UINT_MAX);
//edges that end on bollard nodes may actually be in two distinct components
if(std::min(vectorOfComponentSizes[componentsIndex[u]], vectorOfComponentSizes[componentsIndex[v]]) < 10) {

//INFO("(" << inputNodeInfoList[u].lat/100000. << ";" << inputNodeInfoList[u].lon/100000. << ") -> (" << inputNodeInfoList[v].lat/100000. << ";" << inputNodeInfoList[v].lon/100000. << ")");
OGRLineString lineString;
lineString.addPoint(inputNodeInfoList[u].lon/100000., inputNodeInfoList[u].lat/100000.);
lineString.addPoint(inputNodeInfoList[v].lon/100000., inputNodeInfoList[v].lat/100000.);

OGRFeature *poFeature;
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
poFeature->SetGeometry( &lineString );
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
{
ERR( "Failed to create feature in shapefile.\n" );
}
OGRFeature::DestroyFeature( poFeature );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ file(GLOB PrepareGlob Contractor/*.cpp)
set(PrepareSources createHierarchy.cpp ${PrepareGlob})
add_executable(osrm-prepare ${PrepareSources})

file(GLOB RoutedGlob Server/DataStructures/*.cpp Descriptors/*.cpp)
file(GLOB RoutedGlob Server/DataStructures/*.cpp Descriptors/*.cpp DataStructures/*.cpp)
set(RoutedSources routed.cpp ${RoutedGlob})
add_executable(osrm-routed ${RoutedSources})
set_target_properties(osrm-routed PROPERTIES COMPILE_FLAGS -DROUTED)
Expand Down
2 changes: 2 additions & 0 deletions Contractor/ContractionCleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <sys/time.h>
#endif
#include "Contractor.h"
#include "TravelMode.h"

class ContractionCleanup {
private:
Expand Down Expand Up @@ -64,6 +65,7 @@ class ContractionCleanup {
bool shortcut:1;
bool forward:1;
bool backward:1;
TravelMode mode;
} data;
bool operator<( const Edge& right ) const {
if ( source != right.source )
Expand Down
31 changes: 11 additions & 20 deletions Contractor/EdgeBasedGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
edge.data.roundabout = i->isRoundabout();
edge.data.ignoreInGrid = i->ignoreInGrid();
edge.data.nameID = i->name();
edge.data.type = i->type();
edge.data.isAccessRestricted = i->isAccessRestricted();
edge.data.edgeBasedNodeID = edges.size();
edge.data.contraFlow = i->isContraFlow();
edge.data.mode = i->mode();
edges.push_back( edge );
if( edge.data.backward ) {
std::swap( edge.source, edge.target );
Expand Down Expand Up @@ -147,6 +146,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(
currentNode.id = data.edgeBasedNodeID;
currentNode.ignoreInGrid = data.ignoreInGrid;
currentNode.weight = data.distance;
currentNode.mode = data.mode;
edgeBasedNodes.push_back(currentNode);
}

Expand Down Expand Up @@ -221,13 +221,11 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State
for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) {
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);

if(_nodeBasedGraph->GetEdgeData(e1).type != SHRT_MAX) {
assert(e1 != UINT_MAX);
assert(u != UINT_MAX);
assert(v != UINT_MAX);
//edges that end on bollard nodes may actually be in two distinct components
InsertEdgeBasedNode(e1, u, v, (std::min(vectorOfComponentSizes[componentsIndex[u]], vectorOfComponentSizes[componentsIndex[v]]) < 1000) );
}
assert(e1 != UINT_MAX);
assert(u != UINT_MAX);
assert(v != UINT_MAX);
//edges that end on bollard nodes may actually be in two distinct components
InsertEdgeBasedNode(e1, u, v, (std::min(vectorOfComponentSizes[componentsIndex[u]], vectorOfComponentSizes[componentsIndex[v]]) < 1000) );
}
}

Expand Down Expand Up @@ -274,6 +272,7 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State
distance += speedProfile.trafficSignalPenalty;
}
unsigned penalty = 0;

TurnInstruction turnInstruction = AnalyzeTurn(u, v, w, penalty, myLuaState);
if(turnInstruction == TurnInstructions.UTurn)
distance += speedProfile.uTurnPenalty;
Expand All @@ -283,11 +282,10 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State
// }
distance += penalty;


//distance += heightPenalty;
//distance += ComputeTurnPenalty(u, v, w);
assert(edgeData1.edgeBasedNodeID != edgeData2.edgeBasedNodeID);
OriginalEdgeData oed(v,edgeData2.nameID, turnInstruction);
OriginalEdgeData oed(v,edgeData2.nameID, turnInstruction, edgeData2.mode);
original_edge_data_vector.push_back(oed);
++numberOfOriginalEdges;

Expand Down Expand Up @@ -351,13 +349,6 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID
_NodeBasedDynamicGraph::EdgeData & data1 = _nodeBasedGraph->GetEdgeData(edge1);
_NodeBasedDynamicGraph::EdgeData & data2 = _nodeBasedGraph->GetEdgeData(edge2);

if(!data1.contraFlow && data2.contraFlow) {
return TurnInstructions.EnterAgainstAllowedDirection;
}
if(data1.contraFlow && !data2.contraFlow) {
return TurnInstructions.LeaveAgainstAllowedDirection;
}

//roundabouts need to be handled explicitely
if(data1.roundabout && data2.roundabout) {
//Is a turn possible? If yes, we stay on the roundabout!
Expand All @@ -379,8 +370,8 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID
}
}

//If street names stay the same and if we are certain that it is not a roundabout, we skip it.
if( (data1.nameID == data2.nameID) && (0 != data1.nameID)) {
//If street names and modes stay the same and if we are certain that it is not a roundabout, we skip it.
if( (data1.nameID == data2.nameID) && (data1.mode == data2.mode) && (0 != data1.nameID)) {
return TurnInstructions.NoTurn;
}
if( (data1.nameID == data2.nameID) && (0 == data1.nameID) && (_nodeBasedGraph->GetOutDegree(v) <= 2) ) {
Expand Down
5 changes: 3 additions & 2 deletions Contractor/EdgeBasedGraphFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class EdgeBasedGraphFactory : boost::noncopyable {
NodeID nameID;
unsigned weight:31;
bool ignoreInGrid:1;
TravelMode mode;
};

struct SpeedProfileProperties{
Expand All @@ -91,14 +92,13 @@ class EdgeBasedGraphFactory : boost::noncopyable {
int distance;
unsigned edgeBasedNodeID;
unsigned nameID;
short type;
bool isAccessRestricted:1;
bool shortcut:1;
bool forward:1;
bool backward:1;
bool roundabout:1;
bool ignoreInGrid:1;
bool contraFlow:1;
TravelMode mode;
};

struct _EdgeBasedEdgeData {
Expand All @@ -108,6 +108,7 @@ class EdgeBasedGraphFactory : boost::noncopyable {
bool forward;
bool backward;
TurnInstruction turnInstruction;
TravelMode mode;
};

typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
Expand Down
6 changes: 4 additions & 2 deletions DataStructures/GridEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ or see http://www.gnu.org/licenses/agpl.txt.
#define GRIDEDGE_H_

#include "Coordinate.h"
#include "TravelMode.h"

struct _GridEdge {
_GridEdge(NodeID n, NodeID na, int w, _Coordinate sc, _Coordinate tc, bool bttc) : edgeBasedNode(n), nameID(na), weight(w), startCoord(sc), targetCoord(tc), belongsToTinyComponent(bttc) {}
_GridEdge() : edgeBasedNode(UINT_MAX), nameID(UINT_MAX), weight(INT_MAX), belongsToTinyComponent(false) {}
_GridEdge(NodeID n, NodeID na, int w, _Coordinate sc, _Coordinate tc, bool bttc, TravelMode _mode) : edgeBasedNode(n), nameID(na), weight(w), startCoord(sc), targetCoord(tc), belongsToTinyComponent(bttc), mode(_mode) {}
_GridEdge() : edgeBasedNode(UINT_MAX), nameID(UINT_MAX), weight(INT_MAX), belongsToTinyComponent(false), mode(0) {}
NodeID edgeBasedNode;
NodeID nameID;
int weight;
_Coordinate startCoord;
_Coordinate targetCoord;
bool belongsToTinyComponent;
TravelMode mode;

bool operator< ( const _GridEdge& right) const {
return edgeBasedNode < right.edgeBasedNode;
Expand Down
17 changes: 8 additions & 9 deletions DataStructures/ImportEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ or see http://www.gnu.org/licenses/agpl.txt.

#include <cassert>

#include "TravelMode.h"

class NodeBasedEdge {
public:

Expand All @@ -40,39 +42,36 @@ class NodeBasedEdge {
return (source() < e.source());
}

explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra, bool ig, bool ar, bool cf) :
_source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra), _ignoreInGrid(ig), _accessRestricted(ar), _contraFlow(cf) { if(ty < 0) {ERR("Type: " << ty);}; }
explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, bool ra, bool ig, bool ar, TravelMode mode) :
_source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _roundabout(ra), _ignoreInGrid(ig), _accessRestricted(ar), _mode(mode) {}

NodeID target() const {return _target; }
NodeID source() const {return _source; }
NodeID name() const { return _name; }
EdgeWeight weight() const {return _weight; }

short type() const { assert(_type >= 0); return _type; }
bool isBackward() const { return backward; }
bool isForward() const { return forward; }
bool isLocatable() const { return _type != 14; }
bool isRoundabout() const { return _roundabout; }
bool ignoreInGrid() const { return _ignoreInGrid; }
bool isAccessRestricted() const { return _accessRestricted; }
bool isContraFlow() const { return _contraFlow; }
TravelMode mode() const { return _mode; }

NodeID _source;
NodeID _target;
NodeID _name;
EdgeWeight _weight;
bool forward;
bool backward;
short _type;
bool _roundabout;
bool _ignoreInGrid;
bool _accessRestricted;
bool _contraFlow;
TravelMode _mode;

private:
/** Default constructor. target and weight are set to 0.*/
NodeBasedEdge() :
_source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _type(0), _roundabout(false), _ignoreInGrid(false), _accessRestricted(false), _contraFlow(false) { assert(false); } //shall not be used.
_source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _roundabout(false), _ignoreInGrid(false), _accessRestricted(false), _mode(0) { assert(false); } //shall not be used.

};

Expand Down Expand Up @@ -127,7 +126,7 @@ class EdgeBasedEdge {
EdgeWeight weight() const {return m_weight; }
NodeID id() const { return m_edgeID; }
bool isBackward() const { return m_backward; }
bool isForward() const { return m_forward; }
bool isForward() const { return m_forward; }
private:
NodeID m_source;
NodeID m_target;
Expand Down
Loading

0 comments on commit b03ccfa

Please sign in to comment.