Refactor _Restriction class
This commit is contained in:
parent
216d7dcb86
commit
916387748c
@ -118,9 +118,21 @@ private:
|
||||
|
||||
DeallocatingVector<EdgeBasedNode> edgeBasedNodes;
|
||||
public:
|
||||
TarjanSCC(int nodes, std::vector<NodeBasedEdge> & inputEdges, std::vector<NodeID> & bn, std::vector<NodeID> & tl, std::vector<_Restriction> & irs, std::vector<NodeInfo> & nI) : inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) {
|
||||
BOOST_FOREACH(_Restriction & restriction, irs) {
|
||||
std::pair<NodeID, NodeID> restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode);
|
||||
TarjanSCC(
|
||||
int nodes,
|
||||
std::vector<NodeBasedEdge> & inputEdges,
|
||||
std::vector<NodeID> & bn,
|
||||
std::vector<NodeID> & tl,
|
||||
std::vector<TurnRestriction> & irs,
|
||||
std::vector<NodeInfo> & nI
|
||||
) :
|
||||
inputNodeInfoList(nI),
|
||||
numberOfTurnRestrictions(irs.size())
|
||||
{
|
||||
BOOST_FOREACH(const TurnRestriction & restriction, irs) {
|
||||
std::pair<NodeID, NodeID> restrictionSource = std::make_pair(
|
||||
restriction.fromNode, restriction.viaNode
|
||||
);
|
||||
unsigned index;
|
||||
RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource);
|
||||
if(restrIter == _restrictionMap.end()) {
|
||||
@ -138,7 +150,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
_restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly));
|
||||
_restrictionBucketVector.at(index).push_back(
|
||||
std::make_pair(restriction.toNode, restriction.flags.isOnly)
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_FOREACH(NodeID id, bn) {
|
||||
|
@ -20,8 +20,18 @@
|
||||
|
||||
#include "EdgeBasedGraphFactory.h"
|
||||
|
||||
EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<ImportEdge> & inputEdges, std::vector<NodeID> & bn, std::vector<NodeID> & tl, std::vector<_Restriction> & irs, std::vector<NodeInfo> & nI, SpeedProfileProperties sp) : speedProfile(sp), inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) {
|
||||
BOOST_FOREACH(const _Restriction & restriction, irs) {
|
||||
EdgeBasedGraphFactory::EdgeBasedGraphFactory(
|
||||
int nodes, std::vector<ImportEdge> & inputEdges,
|
||||
std::vector<NodeID> & bn,
|
||||
std::vector<NodeID> & tl,
|
||||
std::vector<TurnRestriction> & input_restrictions_list,
|
||||
std::vector<NodeInfo> & inputNodeInfoList,
|
||||
SpeedProfileProperties speedProfile
|
||||
) : speedProfile(speedProfile),
|
||||
m_turn_restrictions_count(0),
|
||||
inputNodeInfoList(inputNodeInfoList)
|
||||
{
|
||||
BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) {
|
||||
std::pair<NodeID, NodeID> restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode);
|
||||
unsigned index;
|
||||
RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource);
|
||||
@ -36,10 +46,11 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<ImportEdge>
|
||||
continue;
|
||||
else if(restriction.flags.isOnly){
|
||||
//We are going to insert an is_only_*-restriction. There can be only one.
|
||||
m_turn_restrictions_count -= _restrictionBucketVector.at(index).size();
|
||||
_restrictionBucketVector.at(index).clear();
|
||||
}
|
||||
}
|
||||
|
||||
++m_turn_restrictions_count;
|
||||
_restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly));
|
||||
}
|
||||
|
||||
@ -48,36 +59,36 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<ImportEdge>
|
||||
|
||||
DeallocatingVector< _NodeBasedEdge > edges;
|
||||
_NodeBasedEdge edge;
|
||||
for ( std::vector< ImportEdge >::const_iterator i = inputEdges.begin(); i != inputEdges.end(); ++i ) {
|
||||
if(!i->isForward()) {
|
||||
edge.source = i->target();
|
||||
edge.target = i->source();
|
||||
edge.data.backward = i->isForward();
|
||||
edge.data.forward = i->isBackward();
|
||||
BOOST_FOREACH(const ImportEdge & import_edge, inputEdges) {
|
||||
if(!import_edge.isForward()) {
|
||||
edge.source = import_edge.target();
|
||||
edge.target = import_edge.source();
|
||||
edge.data.backward = import_edge.isForward();
|
||||
edge.data.forward = import_edge.isBackward();
|
||||
} else {
|
||||
edge.source = i->source();
|
||||
edge.target = i->target();
|
||||
edge.data.forward = i->isForward();
|
||||
edge.data.backward = i->isBackward();
|
||||
edge.source = import_edge.source();
|
||||
edge.target = import_edge.target();
|
||||
edge.data.forward = import_edge.isForward();
|
||||
edge.data.backward = import_edge.isBackward();
|
||||
}
|
||||
if(edge.source == edge.target) {
|
||||
continue;
|
||||
}
|
||||
edge.data.distance = (std::max)((int)i->weight(), 1 );
|
||||
edge.data.distance = (std::max)((int)import_edge.weight(), 1 );
|
||||
assert( edge.data.distance > 0 );
|
||||
edge.data.shortcut = false;
|
||||
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.roundabout = import_edge.isRoundabout();
|
||||
edge.data.ignoreInGrid = import_edge.ignoreInGrid();
|
||||
edge.data.nameID = import_edge.name();
|
||||
edge.data.type = import_edge.type();
|
||||
edge.data.isAccessRestricted = import_edge.isAccessRestricted();
|
||||
edge.data.edgeBasedNodeID = edges.size();
|
||||
edge.data.contraFlow = i->isContraFlow();
|
||||
edge.data.contraFlow = import_edge.isContraFlow();
|
||||
edges.push_back( edge );
|
||||
if( edge.data.backward ) {
|
||||
std::swap( edge.source, edge.target );
|
||||
edge.data.forward = i->isBackward();
|
||||
edge.data.backward = i->isForward();
|
||||
edge.data.forward = import_edge.isBackward();
|
||||
edge.data.backward = import_edge.isForward();
|
||||
edge.data.edgeBasedNodeID = edges.size();
|
||||
edges.push_back( edge );
|
||||
}
|
||||
@ -105,7 +116,10 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector<EdgeBasedNode> & node
|
||||
nodes.swap(edgeBasedNodes);
|
||||
}
|
||||
|
||||
NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const {
|
||||
NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(
|
||||
const NodeID u,
|
||||
const NodeID v
|
||||
) const {
|
||||
const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v);
|
||||
RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource);
|
||||
if (restrIter != _restrictionMap.end()) {
|
||||
|
@ -105,6 +105,25 @@ public:
|
||||
bool has_turn_penalty_function;
|
||||
} speedProfile;
|
||||
|
||||
explicit EdgeBasedGraphFactory(
|
||||
int nodes,
|
||||
std::vector<ImportEdge> & inputEdges,
|
||||
std::vector<NodeID> & _bollardNodes,
|
||||
std::vector<NodeID> & trafficLights,
|
||||
std::vector<TurnRestriction> & inputRestrictions,
|
||||
std::vector<NodeInfo> & nI,
|
||||
SpeedProfileProperties speedProfile
|
||||
);
|
||||
|
||||
void Run(const char * originalEdgeDataFilename, lua_State *myLuaState);
|
||||
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
|
||||
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
|
||||
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;
|
||||
|
||||
unsigned GetNumberOfNodes() const;
|
||||
|
||||
private:
|
||||
struct _NodeBasedEdgeData {
|
||||
int distance;
|
||||
@ -129,6 +148,8 @@ private:
|
||||
TurnInstruction turnInstruction;
|
||||
};
|
||||
|
||||
unsigned m_turn_restrictions_count;
|
||||
|
||||
typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
|
||||
typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge;
|
||||
std::vector<NodeInfo> inputNodeInfoList;
|
||||
@ -158,17 +179,6 @@ private:
|
||||
template<class CoordinateT>
|
||||
double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const;
|
||||
|
||||
public:
|
||||
explicit EdgeBasedGraphFactory(int nodes, std::vector<ImportEdge> & inputEdges, std::vector<NodeID> & _bollardNodes, std::vector<NodeID> & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector<NodeInfo> & nI, SpeedProfileProperties speedProfile);
|
||||
|
||||
void Run(const char * originalEdgeDataFilename, lua_State *myLuaState);
|
||||
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
|
||||
void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes);
|
||||
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;
|
||||
|
||||
unsigned GetNumberOfNodes() const;
|
||||
};
|
||||
|
||||
#endif /* EDGEBASEDGRAPHFACTORY_H_ */
|
||||
|
@ -23,14 +23,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef RESTRICTION_H_
|
||||
#define RESTRICTION_H_
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include <climits>
|
||||
|
||||
struct _Restriction {
|
||||
struct TurnRestriction {
|
||||
NodeID viaNode;
|
||||
NodeID fromNode;
|
||||
NodeID toNode;
|
||||
struct Bits { //mostly unused
|
||||
Bits() :
|
||||
Bits()
|
||||
:
|
||||
isOnly(false),
|
||||
unused1(false),
|
||||
unused2(false),
|
||||
@ -38,9 +40,8 @@ struct _Restriction {
|
||||
unused4(false),
|
||||
unused5(false),
|
||||
unused6(false),
|
||||
unused7(false) {
|
||||
|
||||
}
|
||||
unused7(false)
|
||||
{ }
|
||||
|
||||
bool isOnly:1;
|
||||
bool unused1:1;
|
||||
@ -52,14 +53,14 @@ struct _Restriction {
|
||||
bool unused7:1;
|
||||
} flags;
|
||||
|
||||
_Restriction(NodeID vn) :
|
||||
viaNode(vn),
|
||||
TurnRestriction(NodeID viaNode) :
|
||||
viaNode(viaNode),
|
||||
fromNode(UINT_MAX),
|
||||
toNode(UINT_MAX) {
|
||||
|
||||
}
|
||||
|
||||
_Restriction(const bool isOnly = false) :
|
||||
TurnRestriction(const bool isOnly = false) :
|
||||
viaNode(UINT_MAX),
|
||||
fromNode(UINT_MAX),
|
||||
toNode(UINT_MAX) {
|
||||
@ -68,13 +69,32 @@ struct _Restriction {
|
||||
};
|
||||
|
||||
struct _RawRestrictionContainer {
|
||||
_Restriction restriction;
|
||||
TurnRestriction restriction;
|
||||
EdgeID fromWay;
|
||||
EdgeID toWay;
|
||||
unsigned viaNode;
|
||||
|
||||
_RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaNode(vw) { restriction.viaNode = vn;}
|
||||
_RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaNode(UINT_MAX) { restriction.flags.isOnly = isOnly;}
|
||||
_RawRestrictionContainer(
|
||||
EdgeID fromWay,
|
||||
EdgeID toWay,
|
||||
NodeID vn,
|
||||
unsigned vw
|
||||
) :
|
||||
fromWay(fromWay),
|
||||
toWay(toWay),
|
||||
viaNode(vw)
|
||||
{
|
||||
restriction.viaNode = vn;
|
||||
}
|
||||
_RawRestrictionContainer(
|
||||
bool isOnly = false
|
||||
) :
|
||||
fromWay(UINT_MAX),
|
||||
toWay(UINT_MAX),
|
||||
viaNode(UINT_MAX)
|
||||
{
|
||||
restriction.flags.isOnly = isOnly;
|
||||
}
|
||||
|
||||
static _RawRestrictionContainer min_value() {
|
||||
return _RawRestrictionContainer(0, 0, 0, 0);
|
||||
|
@ -125,7 +125,7 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con
|
||||
restrictionsOutstream.write((char*)&usableRestrictionsCounter, sizeof(unsigned));
|
||||
for(restrictionsIT = restrictionsVector.begin(); restrictionsIT != restrictionsVector.end(); ++restrictionsIT) {
|
||||
if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) {
|
||||
restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(_Restriction));
|
||||
restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(TurnRestriction));
|
||||
}
|
||||
}
|
||||
restrictionsOutstream.close();
|
||||
|
@ -43,19 +43,21 @@ typedef QueryEdge::EdgeData EdgeData;
|
||||
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
|
||||
|
||||
std::vector<NodeInfo> internal_to_external_node_map;
|
||||
std::vector<_Restriction> restrictions_vector;
|
||||
std::vector<TurnRestriction> restrictions_vector;
|
||||
std::vector<NodeID> bollard_node_IDs_vector;
|
||||
std::vector<NodeID> traffic_light_node_IDs_vector;
|
||||
|
||||
int main (int argument_count, char *argument_values[]) {
|
||||
int main (int argc, char * argv[]) {
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
if(argument_count < 3) {
|
||||
std::cerr << "usage:\n" << argument_values[0] << " <osrm> <osrm.restrictions>" << std::endl;
|
||||
if(argc < 3) {
|
||||
SimpleLogger().Write(logWARNING) <<
|
||||
"usage:\n" << argv[0] << " <osrm> <osrm.restrictions>";
|
||||
return -1;
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Using restrictions from file: " << argument_values[2];
|
||||
std::ifstream restriction_ifstream(argument_values[2], std::ios::binary);
|
||||
SimpleLogger().Write() <<
|
||||
"Using restrictions from file: " << argv[2];
|
||||
std::ifstream restriction_ifstream(argv[2], std::ios::binary);
|
||||
if(!restriction_ifstream.good()) {
|
||||
throw OSRMException("Could not access <osrm-restrictions> files");
|
||||
}
|
||||
@ -68,15 +70,12 @@ int main (int argument_count, char *argument_values[]) {
|
||||
|
||||
restriction_ifstream.read(
|
||||
(char *)&(restrictions_vector[0]),
|
||||
usable_restriction_count*sizeof(_Restriction)
|
||||
usable_restriction_count*sizeof(TurnRestriction)
|
||||
);
|
||||
restriction_ifstream.close();
|
||||
|
||||
std::ifstream input_stream;
|
||||
input_stream.open(
|
||||
argument_values[1],
|
||||
std::ifstream::in | std::ifstream::binary
|
||||
);
|
||||
input_stream.open( argv[1], std::ifstream::in | std::ifstream::binary );
|
||||
|
||||
if (!input_stream.is_open()) {
|
||||
throw OSRMException("Cannot open osrm file");
|
||||
@ -115,7 +114,7 @@ int main (int argument_count, char *argument_values[]) {
|
||||
|
||||
tarjan->Run();
|
||||
|
||||
std::vector<_Restriction>().swap(restrictions_vector);
|
||||
std::vector<TurnRestriction>().swap(restrictions_vector);
|
||||
std::vector<NodeID>().swap(bollard_node_IDs_vector);
|
||||
std::vector<NodeID>().swap(traffic_light_node_IDs_vector);
|
||||
SimpleLogger().Write() << "finished component analysis";
|
||||
|
@ -60,7 +60,7 @@ NodeID readBinaryOSRMGraphFromStream(
|
||||
std::vector<NodeID> &bollardNodes,
|
||||
std::vector<NodeID> &trafficLightNodes,
|
||||
std::vector<NodeInfo> * int2ExtNodeMap,
|
||||
std::vector<_Restriction> & inputRestrictions
|
||||
std::vector<TurnRestriction> & inputRestrictions
|
||||
) {
|
||||
const UUID uuid_orig;
|
||||
UUID uuid_loaded;
|
||||
|
@ -53,7 +53,7 @@ typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
|
||||
typedef IniFile ContractorConfiguration;
|
||||
|
||||
std::vector<NodeInfo> internalToExternalNodeMapping;
|
||||
std::vector<_Restriction> inputRestrictions;
|
||||
std::vector<TurnRestriction> inputRestrictions;
|
||||
std::vector<NodeID> bollardNodes;
|
||||
std::vector<NodeID> trafficLightNodes;
|
||||
std::vector<ImportEdge> edgeList;
|
||||
@ -85,7 +85,7 @@ int main (int argc, char *argv[]) {
|
||||
"Could not access <osrm-restrictions> files" << std::endl;
|
||||
|
||||
}
|
||||
_Restriction restriction;
|
||||
TurnRestriction restriction;
|
||||
UUID uuid_loaded, uuid_orig;
|
||||
unsigned usableRestrictionsCounter(0);
|
||||
restrictionsInstream.read((char*)&uuid_loaded, sizeof(UUID));
|
||||
@ -95,9 +95,15 @@ int main (int argc, char *argv[]) {
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned));
|
||||
restrictionsInstream.read(
|
||||
(char*)&usableRestrictionsCounter,
|
||||
sizeof(unsigned)
|
||||
);
|
||||
inputRestrictions.resize(usableRestrictionsCounter);
|
||||
restrictionsInstream.read((char *)&(inputRestrictions[0]), usableRestrictionsCounter*sizeof(_Restriction));
|
||||
restrictionsInstream.read(
|
||||
(char *)&(inputRestrictions[0]),
|
||||
usableRestrictionsCounter*sizeof(TurnRestriction)
|
||||
);
|
||||
restrictionsInstream.close();
|
||||
|
||||
std::ifstream in;
|
||||
@ -190,7 +196,7 @@ int main (int argc, char *argv[]) {
|
||||
EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile);
|
||||
std::vector<ImportEdge>().swap(edgeList);
|
||||
edgeBasedGraphFactory->Run(edgeOut.c_str(), myLuaState);
|
||||
std::vector<_Restriction>().swap(inputRestrictions);
|
||||
std::vector<TurnRestriction>().swap(inputRestrictions);
|
||||
std::vector<NodeID>().swap(bollardNodes);
|
||||
std::vector<NodeID>().swap(trafficLightNodes);
|
||||
NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes();
|
||||
|
@ -46,7 +46,6 @@ int main (int argc, char *argv[]) {
|
||||
try {
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
double startup_time = get_timestamp();
|
||||
|
||||
if(argc < 2) {
|
||||
SimpleLogger().Write(logWARNING) <<
|
||||
"usage: \n" <<
|
||||
@ -59,6 +58,7 @@ int main (int argc, char *argv[]) {
|
||||
ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua"));
|
||||
|
||||
unsigned number_of_threads = omp_get_num_procs();
|
||||
|
||||
if(testDataFile("extractor.ini")) {
|
||||
IniFile extractorConfig("extractor.ini");
|
||||
unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads"));
|
||||
|
Loading…
Reference in New Issue
Block a user