some refactoring
This commit is contained in:
		
							parent
							
								
									63d8abe32f
								
							
						
					
					
						commit
						74729a372b
					
				@ -20,7 +20,7 @@
 | 
			
		||||
 | 
			
		||||
#include "ExtractionContainers.h"
 | 
			
		||||
 | 
			
		||||
void ExtractionContainers::PrepareData(const std::string & outputFileName, const std::string restrictionsFileName, const unsigned amountOfRAM) {
 | 
			
		||||
void ExtractionContainers::PrepareData(const std::string & output_file_name, const std::string restrictionsFileName, const unsigned amountOfRAM) {
 | 
			
		||||
    try {
 | 
			
		||||
        unsigned usedNodeCounter = 0;
 | 
			
		||||
        unsigned usedEdgeCounter = 0;
 | 
			
		||||
@ -130,7 +130,7 @@ void ExtractionContainers::PrepareData(const std::string & outputFileName, const
 | 
			
		||||
        restrictionsOutstream.close();
 | 
			
		||||
 | 
			
		||||
        std::ofstream fout;
 | 
			
		||||
        fout.open(outputFileName.c_str(), std::ios::binary);
 | 
			
		||||
        fout.open(output_file_name.c_str(), std::ios::binary);
 | 
			
		||||
        fout.write((char*)&usedNodeCounter, sizeof(unsigned));
 | 
			
		||||
        time = get_timestamp();
 | 
			
		||||
        std::cout << "[extractor] Confirming/Writing used nodes     ... " << std::flush;
 | 
			
		||||
@ -271,7 +271,7 @@ void ExtractionContainers::PrepareData(const std::string & outputFileName, const
 | 
			
		||||
        std::cout << "ok" << std::endl;
 | 
			
		||||
        time = get_timestamp();
 | 
			
		||||
        std::cout << "[extractor] writing street name index ... " << std::flush;
 | 
			
		||||
        std::string nameOutFileName = (outputFileName + ".names");
 | 
			
		||||
        std::string nameOutFileName = (output_file_name + ".names");
 | 
			
		||||
        std::ofstream nameOutFile(nameOutFileName.c_str(), std::ios::binary);
 | 
			
		||||
        unsigned sizeOfNameIndex = nameVector.size();
 | 
			
		||||
        nameOutFile.write((char *)&(sizeOfNameIndex), sizeof(unsigned));
 | 
			
		||||
 | 
			
		||||
@ -55,7 +55,7 @@ public:
 | 
			
		||||
        wayStartEndVector.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void PrepareData( const std::string & outputFileName, const std::string restrictionsFileName, const unsigned amountOfRAM);
 | 
			
		||||
    void PrepareData( const std::string & output_file_name, const std::string restrictionsFileName, const unsigned amountOfRAM);
 | 
			
		||||
 | 
			
		||||
    STXXLNodeIDVector           usedNodeIDs;
 | 
			
		||||
    STXXLNodeVector             allNodes;
 | 
			
		||||
 | 
			
		||||
@ -63,14 +63,14 @@ int main (int argc, char *argv[]) {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        double startupTime = get_timestamp();
 | 
			
		||||
        unsigned numberOfThreads = omp_get_num_procs();
 | 
			
		||||
        unsigned number_of_threads = omp_get_num_procs();
 | 
			
		||||
        if(testDataFile("contractor.ini")) {
 | 
			
		||||
            ContractorConfiguration contractorConfig("contractor.ini");
 | 
			
		||||
            unsigned rawNumber = stringToInt(contractorConfig.GetParameter("Threads"));
 | 
			
		||||
            if(rawNumber != 0 && rawNumber <= numberOfThreads)
 | 
			
		||||
                numberOfThreads = rawNumber;
 | 
			
		||||
            if(rawNumber != 0 && rawNumber <= number_of_threads)
 | 
			
		||||
                number_of_threads = rawNumber;
 | 
			
		||||
        }
 | 
			
		||||
        omp_set_num_threads(numberOfThreads);
 | 
			
		||||
        omp_set_num_threads(number_of_threads);
 | 
			
		||||
 | 
			
		||||
        INFO("Using restrictions from file: " << argv[2]);
 | 
			
		||||
        std::ifstream restrictionsInstream(argv[2], std::ios::binary);
 | 
			
		||||
 | 
			
		||||
@ -31,17 +31,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
 | 
			
		||||
#include "typedefs.h"
 | 
			
		||||
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
typedef BaseConfiguration ExtractorConfiguration;
 | 
			
		||||
 | 
			
		||||
ExtractorCallbacks * extractCallBacks;
 | 
			
		||||
 | 
			
		||||
int main (int argc, char *argv[]) {
 | 
			
		||||
    double earliestTime = get_timestamp();
 | 
			
		||||
    double startup_time = get_timestamp();
 | 
			
		||||
 | 
			
		||||
    if(argc < 2) {
 | 
			
		||||
        ERR("usage: \n" << argv[0] << " <file.osm/.osm.bz2/.osm.pbf> [<profile.lua>]");
 | 
			
		||||
@ -50,36 +48,37 @@ int main (int argc, char *argv[]) {
 | 
			
		||||
    /*** Setup Scripting Environment ***/
 | 
			
		||||
    ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua"));
 | 
			
		||||
 | 
			
		||||
    unsigned numberOfThreads = omp_get_num_procs();
 | 
			
		||||
    unsigned number_of_threads = omp_get_num_procs();
 | 
			
		||||
    if(testDataFile("extractor.ini")) {
 | 
			
		||||
        ExtractorConfiguration extractorConfig("extractor.ini");
 | 
			
		||||
        BaseConfiguration extractorConfig("extractor.ini");
 | 
			
		||||
        unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads"));
 | 
			
		||||
        if( rawNumber != 0 && rawNumber <= numberOfThreads)
 | 
			
		||||
            numberOfThreads = rawNumber;
 | 
			
		||||
        if( rawNumber != 0 && rawNumber <= number_of_threads) {
 | 
			
		||||
            number_of_threads = rawNumber;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    omp_set_num_threads(numberOfThreads);
 | 
			
		||||
    omp_set_num_threads(number_of_threads);
 | 
			
		||||
 | 
			
		||||
    INFO("extracting data from input file " << argv[1]);
 | 
			
		||||
    bool isPBF(false);
 | 
			
		||||
    std::string outputFileName(argv[1]);
 | 
			
		||||
    bool file_has_pbf_format(false);
 | 
			
		||||
    std::string output_file_name(argv[1]);
 | 
			
		||||
    std::string restrictionsFileName(argv[1]);
 | 
			
		||||
    std::string::size_type pos = outputFileName.find(".osm.bz2");
 | 
			
		||||
    std::string::size_type pos = output_file_name.find(".osm.bz2");
 | 
			
		||||
    if(pos==std::string::npos) {
 | 
			
		||||
        pos = outputFileName.find(".osm.pbf");
 | 
			
		||||
        pos = output_file_name.find(".osm.pbf");
 | 
			
		||||
        if(pos!=std::string::npos) {
 | 
			
		||||
            isPBF = true;
 | 
			
		||||
            file_has_pbf_format = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(pos!=std::string::npos) {
 | 
			
		||||
        outputFileName.replace(pos, 8, ".osrm");
 | 
			
		||||
        output_file_name.replace(pos, 8, ".osrm");
 | 
			
		||||
        restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
 | 
			
		||||
    } else {
 | 
			
		||||
        pos=outputFileName.find(".osm");
 | 
			
		||||
        pos=output_file_name.find(".osm");
 | 
			
		||||
        if(pos!=std::string::npos) {
 | 
			
		||||
            outputFileName.replace(pos, 5, ".osrm");
 | 
			
		||||
            output_file_name.replace(pos, 5, ".osrm");
 | 
			
		||||
            restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
 | 
			
		||||
        } else {
 | 
			
		||||
            outputFileName.append(".osrm");
 | 
			
		||||
            output_file_name.append(".osrm");
 | 
			
		||||
            restrictionsFileName.append(".osrm.restrictions");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@ -96,7 +95,7 @@ int main (int argc, char *argv[]) {
 | 
			
		||||
    stringMap[""] = 0;
 | 
			
		||||
    extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
 | 
			
		||||
    BaseParser* parser;
 | 
			
		||||
    if(isPBF) {
 | 
			
		||||
    if(file_has_pbf_format) {
 | 
			
		||||
        parser = new PBFParser(argv[1], extractCallBacks, scriptingEnvironment);
 | 
			
		||||
    } else {
 | 
			
		||||
        parser = new XMLParser(argv[1], extractCallBacks, scriptingEnvironment);
 | 
			
		||||
@ -106,18 +105,22 @@ int main (int argc, char *argv[]) {
 | 
			
		||||
        ERR("Parser not initialized!");
 | 
			
		||||
    }
 | 
			
		||||
    INFO("Parsing in progress..");
 | 
			
		||||
    double time = get_timestamp();
 | 
			
		||||
    double parsing_start_time = get_timestamp();
 | 
			
		||||
    parser->Parse();
 | 
			
		||||
    INFO("Parsing finished after " << get_timestamp() - time << " seconds");
 | 
			
		||||
    INFO("Parsing finished after " <<
 | 
			
		||||
        (get_timestamp() - parsing_start_time) <<
 | 
			
		||||
        " seconds"
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    externalMemory.PrepareData(outputFileName, restrictionsFileName, amountOfRAM);
 | 
			
		||||
    externalMemory.PrepareData(output_file_name, restrictionsFileName, amountOfRAM);
 | 
			
		||||
 | 
			
		||||
    stringMap.clear();
 | 
			
		||||
    delete parser;
 | 
			
		||||
    delete extractCallBacks;
 | 
			
		||||
    INFO("finished after " << get_timestamp() - earliestTime << "s");
 | 
			
		||||
 | 
			
		||||
    INFO("extraction finished after " << get_timestamp() - startup_time << "s");
 | 
			
		||||
 | 
			
		||||
    std::cout << "\nRun:\n"
 | 
			
		||||
                   "./osrm-prepare " << outputFileName << " " << restrictionsFileName << std::endl;
 | 
			
		||||
        << "./osrm-prepare " << output_file_name << " " << restrictionsFileName
 | 
			
		||||
        << std::endl;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user