示例#1
0
void Tree::constructing_trie()
{
    string line;
    ifstream names_file(this->path_nodes);
    int pointer = -1;
    int parent;
    
    this->trie.resize(this->ids.size() , vector<int>());
    this->types.resize(this->ids.size() );
    
    vector<int>::iterator it;
//    vector<int>::iterator beg = this->ids.begin();
//    vector<int>::iterator end = this->ids.end();
    
    while(getline(names_file, line ,'\t'))
    {
        pointer++;
        getline(names_file, line ,'\t');
        parent = (int)this->strTolong(line);
        cerr << ids[pointer] << endl;
        
        parent = this->id_to_index(parent);
        cerr <<  pointer << "   "<< parent  << "   id"<< endl;
        this->trie[parent].push_back(pointer);
        getline(names_file, line ,'\t');
        this->types[pointer] = line;
        
        getline(names_file, line );
        
    }
    
    
}
示例#2
0
void Tree::construct_ids_names()
{
    string line;
    ifstream names_file(path_names);

    int pointer = -1;
    bool newLine = true;
    while(getline(names_file, line ,'\t' ))
    {
        cerr << line << endl;

        
        if(newLine)
        {
            cerr << "newLine " << endl;
            pointer++;
            newLine = false;
            //cerr << pointer << endl;
            //long id = stol(line ,&sz);
            
            this->ids.push_back((int)this->strTolong(line));
            vector<string> newVec;
            this->names.push_back(newVec);
            
        }
        else
        {
            if(line[0] == '$')
            {
                cerr << line << " ggg  $\n";
                newLine = true;
                //continue;
            }
            else
                this->names[pointer].push_back(line);
        }
    }
    
    cout << " idsize and names size\n";
    cout << this->ids.size() << "   " <<this->names.size() << endl;
    
}
QueryObjectsStorage::QueryObjectsStorage(
	const std::string & hsgrPath,
	const std::string & ramIndexPath,
	const std::string & fileIndexPath,
	const std::string & nodesPath,
	const std::string & edgesPath,
	const std::string & namesPath,
	const std::string & timestampPath
) {
	if( hsgrPath.empty() ) {
		throw OSRMException("no hsgr file given in ini file");
	}
	if( ramIndexPath.empty() ) {
		throw OSRMException("no ram index file given in ini file");
	}
	if( fileIndexPath.empty() ) {
		throw OSRMException("no mem index file given in ini file");
	}
	if( nodesPath.empty() ) {
		throw OSRMException("no nodes file given in ini file");
	}
	if( edgesPath.empty() ) {
		throw OSRMException("no edges file given in ini file");
	}
	if( namesPath.empty() ) {
		throw OSRMException("no names file given in ini file");
	}

	SimpleLogger().Write() << "loading graph data";
	//Deserialize road network graph
	std::vector< QueryGraph::_StrNode> nodeList;
	std::vector< QueryGraph::_StrEdge> edgeList;
	const int n = readHSGRFromStream(
		hsgrPath,
		nodeList,
		edgeList,
		&checkSum
	);

	SimpleLogger().Write() << "Data checksum is " << checkSum;
	graph = new QueryGraph(nodeList, edgeList);
	assert(0 == nodeList.size());
	assert(0 == edgeList.size());

	if(timestampPath.length()) {
	    SimpleLogger().Write() << "Loading Timestamp";
	    std::ifstream timestampInStream(timestampPath.c_str());
	    if(!timestampInStream) {
	    	SimpleLogger().Write(logWARNING) <<  timestampPath <<  " not found";
	    }

	    getline(timestampInStream, timestamp);
	    timestampInStream.close();
	}
	if(!timestamp.length()) {
	    timestamp = "n/a";
	}
	if(25 < timestamp.length()) {
	    timestamp.resize(25);
	}

    SimpleLogger().Write() << "Loading auxiliary information";
    //Init nearest neighbor data structure
	nodeHelpDesk = new NodeInformationHelpDesk(
		ramIndexPath,
		fileIndexPath,
		nodesPath,
		edgesPath,
		n,
		checkSum
	);

	//deserialize street name list
	SimpleLogger().Write() << "Loading names index";
	boost::filesystem::path names_file(namesPath);

    if ( !boost::filesystem::exists( names_file ) ) {
        throw OSRMException("names file does not exist");
    }
    if ( 0 == boost::filesystem::file_size( names_file ) ) {
        throw OSRMException("names file is empty");
    }

	boost::filesystem::ifstream name_stream(names_file, std::ios::binary);
	unsigned size = 0;
	name_stream.read((char *)&size, sizeof(unsigned));
	BOOST_ASSERT_MSG(0 != size, "name file empty");

	char buf[1024];
	for( unsigned i = 0; i < size; ++i ) {
		unsigned size_of_string = 0;
		name_stream.read((char *)&size_of_string, sizeof(unsigned));
		buf[size_of_string] = '\0'; // instead of memset
		name_stream.read(buf, size_of_string);
		names.push_back(buf);
	}
	std::vector<std::string>(names).swap(names);
	BOOST_ASSERT_MSG(0 != names.size(), "could not load any names");
	name_stream.close();
	SimpleLogger().Write() << "All query data structures loaded";
}