2010-07-09 05:05:40 -04:00
|
|
|
/*
|
|
|
|
open source routing machine
|
|
|
|
Copyright (C) Dennis Luxen, 2010
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU AFFERO General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
or see http://www.gnu.org/licenses/agpl.txt.
|
2010-08-31 10:00:40 -04:00
|
|
|
*/
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2011-11-09 10:12:05 -05:00
|
|
|
//g++ createHierarchy.cpp -fopenmp -Wno-deprecated -o createHierarchy -O3 -march=native -DNDEBUG -I/usr/include/libxml2 -lstxxl
|
2010-07-09 05:05:40 -04:00
|
|
|
|
|
|
|
#define VERBOSE(x) x
|
|
|
|
#define VERBOSE2(x)
|
|
|
|
|
2010-08-31 10:00:40 -04:00
|
|
|
#ifdef NDEBUG
|
|
|
|
#undef VERBOSE
|
|
|
|
#undef VERBOSE2
|
|
|
|
#endif
|
|
|
|
|
2011-11-30 13:48:01 -05:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2010-07-09 05:05:40 -04:00
|
|
|
#include <fstream>
|
|
|
|
#include <istream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2011-11-25 15:54:19 -05:00
|
|
|
#include "Util/OpenMPReplacement.h"
|
2010-07-09 05:05:40 -04:00
|
|
|
#include "typedefs.h"
|
|
|
|
#include "Contractor/Contractor.h"
|
|
|
|
#include "Contractor/ContractionCleanup.h"
|
2011-11-09 10:12:05 -05:00
|
|
|
#include "Contractor/EdgeBasedGraphFactory.h"
|
2011-01-09 16:42:27 -05:00
|
|
|
#include "DataStructures/BinaryHeap.h"
|
2011-11-09 10:12:05 -05:00
|
|
|
#include "DataStructures/ExtractorStructs.h"
|
2010-08-31 10:00:40 -04:00
|
|
|
#include "DataStructures/NNGrid.h"
|
2011-01-09 16:42:27 -05:00
|
|
|
#include "Util/BaseConfiguration.h"
|
|
|
|
#include "Util/InputFileUtil.h"
|
|
|
|
#include "Util/GraphLoader.h"
|
2011-11-26 10:42:15 -05:00
|
|
|
#include "Util/OpenMPReplacement.h"
|
2010-08-31 10:00:40 -04:00
|
|
|
|
2010-07-09 05:05:40 -04:00
|
|
|
using namespace std;
|
|
|
|
|
2011-01-14 11:54:42 -05:00
|
|
|
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
|
2010-10-01 12:30:35 -04:00
|
|
|
typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
|
2011-01-09 16:42:27 -05:00
|
|
|
typedef BaseConfiguration ContractorConfiguration;
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2011-11-25 06:02:52 -05:00
|
|
|
std::vector<NodeInfo> internalToExternaleNodeMapping;
|
|
|
|
std::vector<_Restriction> inputRestrictions;
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2011-01-14 11:54:42 -05:00
|
|
|
int main (int argc, char *argv[]) {
|
2011-11-14 13:36:31 -05:00
|
|
|
if(argc < 3) {
|
2011-11-30 13:48:01 -05:00
|
|
|
ERR("usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions>");
|
2010-07-09 05:05:40 -04:00
|
|
|
}
|
2011-11-14 13:36:31 -05:00
|
|
|
INFO("Using restrictions from file: " << argv[2]);
|
2011-11-30 14:00:05 -05:00
|
|
|
std::ifstream restrictionsInstream(argv[2], ios::binary);
|
2011-11-14 13:36:31 -05:00
|
|
|
_Restriction restriction;
|
|
|
|
unsigned usableRestrictionsCounter(0);
|
|
|
|
restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned));
|
|
|
|
for(unsigned i = 0; i < usableRestrictionsCounter; ++i) {
|
|
|
|
restrictionsInstream.read((char *)&(restriction), sizeof(_Restriction));
|
|
|
|
inputRestrictions.push_back(restriction);
|
2011-11-09 10:12:05 -05:00
|
|
|
}
|
2011-11-14 13:36:31 -05:00
|
|
|
restrictionsInstream.close();
|
|
|
|
INFO("Loaded " << inputRestrictions.size() << " restrictions from file");
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2011-03-18 06:55:18 -04:00
|
|
|
unsigned numberOfThreads = omp_get_num_procs();
|
|
|
|
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() );
|
|
|
|
}
|
|
|
|
omp_set_num_threads(numberOfThreads);
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2011-12-01 07:00:09 -05:00
|
|
|
INFO("preprocessing data from input file " << argv[1] << " using STL "
|
2011-03-14 09:40:31 -04:00
|
|
|
#ifdef _GLIBCXX_PARALLEL
|
2011-11-30 13:48:01 -05:00
|
|
|
"parallel (GCC)"
|
2011-03-14 09:40:31 -04:00
|
|
|
#else
|
2011-11-30 13:48:01 -05:00
|
|
|
"serial"
|
2011-03-14 09:40:31 -04:00
|
|
|
#endif
|
2011-11-30 13:48:01 -05:00
|
|
|
" mode");
|
2010-07-09 05:05:40 -04:00
|
|
|
ifstream in;
|
2011-09-28 11:22:03 -04:00
|
|
|
in.open (argv[1], ifstream::in | ifstream::binary);
|
2010-07-09 05:05:40 -04:00
|
|
|
if (!in.is_open()) {
|
2011-11-30 13:48:01 -05:00
|
|
|
ERR("Cannot open " << argv[1]);
|
2010-07-09 05:05:40 -04:00
|
|
|
}
|
2011-11-09 10:12:05 -05:00
|
|
|
|
2011-11-30 14:00:05 -05:00
|
|
|
char nodeOut[1024]; strcpy(nodeOut, argv[1]); strcat(nodeOut, ".nodes");
|
|
|
|
char edgeOut[1024]; strcpy(edgeOut, argv[1]); strcat(edgeOut, ".hsgr");
|
|
|
|
char ramIndexOut[1024]; strcpy(ramIndexOut, argv[1]); strcat(ramIndexOut, ".ramIndex");
|
|
|
|
char fileIndexOut[1024]; strcpy(fileIndexOut, argv[1]); strcat(fileIndexOut, ".fileIndex");
|
|
|
|
char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels");
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2011-11-25 06:02:52 -05:00
|
|
|
std::vector<ImportEdge> edgeList;
|
|
|
|
NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &internalToExternaleNodeMapping, inputRestrictions);
|
2011-11-14 13:36:31 -05:00
|
|
|
in.close();
|
|
|
|
|
2011-11-25 06:02:52 -05:00
|
|
|
EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (n, edgeList, inputRestrictions, internalToExternaleNodeMapping);
|
|
|
|
edgeList.clear();
|
|
|
|
std::vector<ImportEdge>().swap(edgeList);
|
|
|
|
|
2011-11-14 13:36:31 -05:00
|
|
|
edgeBasedGraphFactory->Run();
|
|
|
|
n = edgeBasedGraphFactory->GetNumberOfNodes();
|
|
|
|
std::vector<EdgeBasedEdge> edgeBasedEdgeList;
|
|
|
|
edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList);
|
|
|
|
|
|
|
|
std::vector<EdgeBasedGraphFactory::EdgeBasedNode> nodeBasedEdgeList;
|
|
|
|
edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList);
|
|
|
|
DELETE(edgeBasedGraphFactory);
|
|
|
|
|
|
|
|
WritableGrid * writeableGrid = new WritableGrid();
|
2011-11-30 13:48:01 -05:00
|
|
|
INFO("building grid ...");
|
2011-11-25 06:02:52 -05:00
|
|
|
writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut);
|
|
|
|
DELETE( writeableGrid );
|
2011-11-30 14:00:05 -05:00
|
|
|
nodeBasedEdgeList.clear();
|
|
|
|
std::vector<EdgeBasedGraphFactory::EdgeBasedNode>().swap(nodeBasedEdgeList);
|
2011-11-14 13:36:31 -05:00
|
|
|
|
2011-11-30 13:48:01 -05:00
|
|
|
INFO("writing node map ...");
|
|
|
|
std::ofstream mapOutFile(nodeOut, ios::binary);
|
|
|
|
BOOST_FOREACH(NodeInfo & info, internalToExternaleNodeMapping) {
|
|
|
|
mapOutFile.write((char *)&(info), sizeof(NodeInfo));
|
2011-11-14 13:36:31 -05:00
|
|
|
}
|
|
|
|
mapOutFile.close();
|
2011-11-25 06:02:52 -05:00
|
|
|
internalToExternaleNodeMapping.clear();
|
|
|
|
std::vector<NodeInfo>().swap(internalToExternaleNodeMapping);
|
|
|
|
inputRestrictions.clear();
|
|
|
|
std::vector<_Restriction>().swap(inputRestrictions);
|
2011-11-14 13:36:31 -05:00
|
|
|
|
2011-11-30 13:48:01 -05:00
|
|
|
INFO("initializing contractor");
|
2011-11-09 10:12:05 -05:00
|
|
|
Contractor* contractor = new Contractor( n, edgeBasedEdgeList );
|
|
|
|
double contractionStartedTimestamp(get_timestamp());
|
2010-07-09 05:05:40 -04:00
|
|
|
contractor->Run();
|
2011-11-09 10:12:05 -05:00
|
|
|
INFO("Contraction took " << get_timestamp() - contractionStartedTimestamp << " sec");
|
2010-07-09 05:05:40 -04:00
|
|
|
|
|
|
|
std::vector< ContractionCleanup::Edge > contractedEdges;
|
|
|
|
contractor->GetEdges( contractedEdges );
|
|
|
|
|
|
|
|
ContractionCleanup * cleanup = new ContractionCleanup(n, contractedEdges);
|
2011-03-14 09:40:31 -04:00
|
|
|
contractedEdges.clear();
|
2011-11-30 13:48:01 -05:00
|
|
|
std::vector<ContractionCleanup::Edge>().swap(contractedEdges);
|
2010-07-09 05:05:40 -04:00
|
|
|
cleanup->Run();
|
|
|
|
|
2011-01-14 11:54:42 -05:00
|
|
|
std::vector< InputEdge> cleanedEdgeList;
|
2010-07-09 05:05:40 -04:00
|
|
|
cleanup->GetData(cleanedEdgeList);
|
2011-11-25 06:02:52 -05:00
|
|
|
DELETE( cleanup );
|
2010-07-09 05:05:40 -04:00
|
|
|
|
2011-11-30 13:48:01 -05:00
|
|
|
INFO("Serializing edges ");
|
2011-03-18 06:55:18 -04:00
|
|
|
ofstream edgeOutFile(edgeOut, ios::binary);
|
|
|
|
Percent p(cleanedEdgeList.size());
|
2011-11-30 13:48:01 -05:00
|
|
|
BOOST_FOREACH(InputEdge & edge, cleanedEdgeList) {
|
2010-09-13 11:31:29 -04:00
|
|
|
p.printIncrement();
|
2011-11-30 13:48:01 -05:00
|
|
|
edgeOutFile.write((char *)&(edge.data), sizeof(EdgeData));
|
|
|
|
edgeOutFile.write((char *)&(edge.source), sizeof(NodeID));
|
|
|
|
edgeOutFile.write((char *)&(edge.target), sizeof(NodeID));
|
2010-07-09 05:05:40 -04:00
|
|
|
}
|
|
|
|
edgeOutFile.close();
|
|
|
|
cleanedEdgeList.clear();
|
|
|
|
|
2011-11-30 13:48:01 -05:00
|
|
|
INFO("finished preprocessing");
|
2011-07-21 10:30:36 -04:00
|
|
|
return 0;
|
2010-07-09 05:05:40 -04:00
|
|
|
}
|