Initialize scripting environment _before_ loading data.
This commit is contained in:
commit
0e3d2cf68d
@ -29,15 +29,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "../DataStructures/Coordinate.h"
|
||||
|
||||
/*This class object computes the bitvector of indicating generalized input points
|
||||
* according to the (Ramer-)Douglas-Peucker algorithm. Runtime n\log n calls to fastDistance
|
||||
* according to the (Ramer-)Douglas-Peucker algorithm.
|
||||
*
|
||||
* Input is vector of pairs. Each pair consists of the point information and a bit
|
||||
* indicating if the points is present in the generalization.
|
||||
* Note: points may also be pre-selected*/
|
||||
|
||||
//These thresholds are more or less heuristically chosen.
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
||||
static double DouglasPeuckerThresholds[19] = { 32000000, 16240000, 80240000, 40240000, 20000000, 10000000, 500000, 240000, 120000, 60000, 30000, 19000, 5000, 2000, 200, 16, 6, 3, 3 };
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
||||
static double DouglasPeuckerThresholds[19] = { 32000000., 16240000., 80240000., 40240000., 20000000., 10000000., 500000., 240000., 120000., 60000., 30000., 19000., 5000., 2000., 200, 16, 6, 3. , 3. };
|
||||
|
||||
template<class PointT>
|
||||
class DouglasPeucker {
|
||||
@ -45,57 +45,6 @@ private:
|
||||
typedef std::pair<std::size_t, std::size_t> PairOfPoints;
|
||||
//Stack to simulate the recursion
|
||||
std::stack<PairOfPoints > recursionStack;
|
||||
public:
|
||||
void Run(std::vector<PointT> & inputVector, const unsigned zoomLevel) {
|
||||
const unsigned sizeOfInputVector = inputVector.size();
|
||||
{
|
||||
assert(zoomLevel < 19);
|
||||
assert(1 < inputVector.size());
|
||||
std::size_t leftBorderOfRange = 0;
|
||||
std::size_t rightBorderOfRange = 1;
|
||||
|
||||
//Sweep linerarily over array and identify those ranges that need to be checked
|
||||
//decision points have been previously marked
|
||||
do {
|
||||
assert(inputVector[leftBorderOfRange].necessary);
|
||||
assert(inputVector.back().necessary);
|
||||
|
||||
if(inputVector[rightBorderOfRange].necessary) {
|
||||
recursionStack.push(std::make_pair(leftBorderOfRange, rightBorderOfRange));
|
||||
leftBorderOfRange = rightBorderOfRange;
|
||||
}
|
||||
++rightBorderOfRange;
|
||||
} while( rightBorderOfRange < sizeOfInputVector);
|
||||
}
|
||||
while(!recursionStack.empty()) {
|
||||
//pop next element
|
||||
const PairOfPoints pair = recursionStack.top();
|
||||
recursionStack.pop();
|
||||
assert(inputVector[pair.first].necessary);
|
||||
assert(inputVector[pair.second].necessary);
|
||||
assert(pair.second < sizeOfInputVector);
|
||||
assert(pair.first < pair.second);
|
||||
int maxDistance = INT_MIN;
|
||||
std::size_t indexOfFarthestElement = pair.second;
|
||||
//find index idx of element with maxDistance
|
||||
for(std::size_t i = pair.first+1; i < pair.second; ++i){
|
||||
const int distance = fastDistance(inputVector[i].location, inputVector[pair.first].location, inputVector[pair.second].location);
|
||||
if(distance > DouglasPeuckerThresholds[zoomLevel] && distance > maxDistance) {
|
||||
indexOfFarthestElement = i;
|
||||
maxDistance = distance;
|
||||
}
|
||||
}
|
||||
if (maxDistance > DouglasPeuckerThresholds[zoomLevel]) {
|
||||
// mark idx as necessary
|
||||
inputVector[indexOfFarthestElement].necessary = true;
|
||||
if (1 < indexOfFarthestElement - pair.first) {
|
||||
recursionStack.push(std::make_pair(pair.first, indexOfFarthestElement) );
|
||||
}
|
||||
if (1 < pair.second - indexOfFarthestElement)
|
||||
recursionStack.push(std::make_pair(indexOfFarthestElement, pair.second) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This distance computation does integer arithmetic only and is about twice as fast as
|
||||
@ -124,6 +73,57 @@ public:
|
||||
return dist;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
void Run(std::vector<PointT> & inputVector, const unsigned zoomLevel) {
|
||||
{
|
||||
assert(zoomLevel < 19);
|
||||
assert(1 < inputVector.size());
|
||||
std::size_t leftBorderOfRange = 0;
|
||||
std::size_t rightBorderOfRange = 1;
|
||||
//Sweep linerarily over array and identify those ranges that need to be checked
|
||||
// recursionStack.hint(inputVector.size());
|
||||
do {
|
||||
assert(inputVector[leftBorderOfRange].necessary);
|
||||
assert(inputVector.back().necessary);
|
||||
|
||||
if(inputVector[rightBorderOfRange].necessary) {
|
||||
recursionStack.push(std::make_pair(leftBorderOfRange, rightBorderOfRange));
|
||||
leftBorderOfRange = rightBorderOfRange;
|
||||
}
|
||||
++rightBorderOfRange;
|
||||
} while( rightBorderOfRange < inputVector.size());
|
||||
}
|
||||
while(!recursionStack.empty()) {
|
||||
//pop next element
|
||||
const PairOfPoints pair = recursionStack.top();
|
||||
recursionStack.pop();
|
||||
assert(inputVector[pair.first].necessary);
|
||||
assert(inputVector[pair.second].necessary);
|
||||
assert(pair.second < inputVector.size());
|
||||
assert(pair.first < pair.second);
|
||||
int maxDistance = INT_MIN;
|
||||
|
||||
std::size_t indexOfFarthestElement = pair.second;
|
||||
//find index idx of element with maxDistance
|
||||
for(std::size_t i = pair.first+1; i < pair.second; ++i){
|
||||
const double distance = std::fabs(fastDistance(inputVector[i].location, inputVector[pair.first].location, inputVector[pair.second].location));
|
||||
if(distance > DouglasPeuckerThresholds[zoomLevel] && distance > maxDistance) {
|
||||
indexOfFarthestElement = i;
|
||||
maxDistance = distance;
|
||||
}
|
||||
}
|
||||
if (maxDistance > DouglasPeuckerThresholds[zoomLevel]) {
|
||||
// mark idx as necessary
|
||||
inputVector[indexOfFarthestElement].necessary = true;
|
||||
if (1 < indexOfFarthestElement - pair.first) {
|
||||
recursionStack.push(std::make_pair(pair.first, indexOfFarthestElement) );
|
||||
}
|
||||
if (1 < pair.second - indexOfFarthestElement)
|
||||
recursionStack.push(std::make_pair(indexOfFarthestElement, pair.second) );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DOUGLASPEUCKER_H_ */
|
||||
|
@ -29,6 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <cfloat>
|
||||
#include <ctime>
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "TemporaryStorage.h"
|
||||
@ -178,7 +179,7 @@ public:
|
||||
std::cout << "merged " << edges.size() - edge << " edges out of " << edges.size() << std::endl;
|
||||
// edges.resize( edge );
|
||||
|
||||
_graph.reset( new _DynamicGraph( nodes, edges ) );
|
||||
_graph = boost::make_shared<_DynamicGraph>( nodes, edges );
|
||||
edges.clear();
|
||||
// unsigned maxdegree = 0;
|
||||
// NodeID highestNode = 0;
|
||||
@ -323,7 +324,7 @@ public:
|
||||
std::sort(newSetOfEdges.begin(), newSetOfEdges.end());
|
||||
|
||||
//int nodes, const ContainerT &graph
|
||||
_graph.reset( new _DynamicGraph(remainingNodes.size(), newSetOfEdges));
|
||||
_graph = boost::make_shared<_DynamicGraph>(remainingNodes.size(), newSetOfEdges);
|
||||
newSetOfEdges.clear();
|
||||
flushedContractor = true;
|
||||
|
||||
|
@ -25,6 +25,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
#include "../DataStructures/DeallocatingVector.h"
|
||||
|
||||
template< typename EdgeDataT>
|
||||
class DynamicGraph {
|
||||
public:
|
||||
@ -231,8 +233,8 @@ class DynamicGraph {
|
||||
NodeIterator m_numNodes;
|
||||
EdgeIterator m_numEdges;
|
||||
|
||||
std::vector< Node > m_nodes;
|
||||
std::vector< Edge > m_edges;
|
||||
DeallocatingVector< Node > m_nodes;
|
||||
DeallocatingVector< Edge > m_edges;
|
||||
};
|
||||
|
||||
#endif // DYNAMICGRAPH_H_INCLUDED
|
||||
|
@ -74,16 +74,16 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
double startupTime = get_timestamp();
|
||||
unsigned numberOfThreads = omp_get_num_procs();
|
||||
std::string SRTM_ROOT;
|
||||
// std::string SRTM_ROOT;
|
||||
if(testDataFile("contractor.ini")) {
|
||||
ContractorConfiguration contractorConfig("contractor.ini");
|
||||
if(atoi(contractorConfig.GetParameter("Threads").c_str()) != 0 && (unsigned)atoi(contractorConfig.GetParameter("Threads").c_str()) <= numberOfThreads)
|
||||
numberOfThreads = (unsigned)atoi( contractorConfig.GetParameter("Threads").c_str() );
|
||||
if(0 < contractorConfig.GetParameter("SRTM").size() )
|
||||
SRTM_ROOT = contractorConfig.GetParameter("SRTM");
|
||||
// if(0 < contractorConfig.GetParameter("SRTM").size() )
|
||||
// SRTM_ROOT = contractorConfig.GetParameter("SRTM");
|
||||
}
|
||||
if(0 != SRTM_ROOT.size())
|
||||
INFO("Loading SRTM from/to " << SRTM_ROOT);
|
||||
// if(0 != SRTM_ROOT.size())
|
||||
// INFO("Loading SRTM from/to " << SRTM_ROOT);
|
||||
omp_set_num_threads(numberOfThreads);
|
||||
|
||||
INFO("Using restrictions from file: " << argv[2]);
|
||||
@ -111,18 +111,10 @@ int main (int argc, char *argv[]) {
|
||||
char fileIndexOut[1024]; strcpy(fileIndexOut, argv[1]); strcat(fileIndexOut, ".fileIndex");
|
||||
char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels");
|
||||
|
||||
std::vector<ImportEdge> edgeList;
|
||||
NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions);
|
||||
in.close();
|
||||
INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights");
|
||||
if(0 == edgeList.size())
|
||||
ERR("The input data is broken. It is impossible to do any turns in this graph");
|
||||
|
||||
|
||||
/*** Setup Scripting Environment ***/
|
||||
if(!testDataFile( (argc > 3 ? argv[3] : "profile.lua") )) {
|
||||
ERR("Need profile.lua to apply traffic signal penalty");
|
||||
}
|
||||
/*** Setup Scripting Environment ***/
|
||||
|
||||
// Create a new lua state
|
||||
lua_State *myLuaState = luaL_newstate();
|
||||
@ -132,7 +124,7 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
|
||||
// Now call our function in a lua script
|
||||
INFO("Parsing speedprofile from " << (argc > 3 ? argv[3] : "profile.lua") );
|
||||
INFO("Parsing speedprofile from " << (argc > 3 ? argv[3] : "profile.lua") );
|
||||
if(0 != luaL_dofile(myLuaState, (argc > 3 ? argv[3] : "profile.lua") )) {
|
||||
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
|
||||
}
|
||||
@ -150,6 +142,15 @@ int main (int argc, char *argv[]) {
|
||||
speedProfile.uTurnPenalty = 10*lua_tointeger(myLuaState, -1);
|
||||
|
||||
|
||||
|
||||
std::vector<ImportEdge> edgeList;
|
||||
NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions);
|
||||
in.close();
|
||||
INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights");
|
||||
if(0 == edgeList.size())
|
||||
ERR("The input data is broken. It is impossible to do any turns in this graph");
|
||||
|
||||
|
||||
/***
|
||||
* Building an edge-expanded graph from node-based input an turn restrictions
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user