QueryObjectsStorage::QueryObjectsStorage(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string edgesPath, std::string namesPath, std::string timestampPath) {
	INFO("loading graph data");
	std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary);
    if(!hsgrInStream) { ERR(hsgrPath <<  " not found"); }
	//Deserialize road network graph
	std::vector< QueryGraph::_StrNode> nodeList;
	std::vector< QueryGraph::_StrEdge> edgeList;
	const int n = readHSGRFromStream(hsgrInStream, nodeList, edgeList, &checkSum);

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

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

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

    INFO("Loading auxiliary information");
    //Init nearest neighbor data structure
	std::ifstream nodesInStream(nodesPath.c_str(), std::ios::binary);
	if(!nodesInStream) { ERR(nodesPath <<  " not found"); }
    std::ifstream edgesInStream(edgesPath.c_str(), std::ios::binary);
    if(!edgesInStream) { ERR(edgesPath <<  " not found"); }
	nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n, checkSum, graph);
	nodeHelpDesk->initNNGrid(nodesInStream, edgesInStream);

	//deserialize street name list
	INFO("Loading names index");
	std::ifstream namesInStream(namesPath.c_str(), std::ios::binary);
    if(!namesInStream) { ERR(namesPath <<  " not found"); }
	unsigned size(0);
	namesInStream.read((char *)&size, sizeof(unsigned));
	//        names = new std::vector<std::string>();

	char buf[1024];
	for(unsigned i = 0; i < size; ++i) {
		unsigned sizeOfString = 0;
		namesInStream.read((char *)&sizeOfString, sizeof(unsigned));
		buf[sizeOfString] = '\0'; // instead of memset
		namesInStream.read(buf, sizeOfString);
		names.push_back(buf);
	}
	std::vector<std::string>(names).swap(names);
	hsgrInStream.close();
	namesInStream.close();
	INFO("All query data structures loaded");
}
QueryObjectsStorage::QueryObjectsStorage(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd) {
	INFO("loading graph data");
	std::ifstream hsgrInStream(hsgrPath.c_str(), ios::binary);
	//Deserialize road network graph
	std::vector< QueryGraph::_StrNode> nodeList;
	std::vector< QueryGraph::_StrEdge> edgeList;
	const int n = readHSGRFromStream(hsgrInStream, nodeList, edgeList, &checkSum);

	INFO("Data checksum is " << checkSum);
	graph = new QueryGraph(nodeList, edgeList);
	assert(0 == nodeList.size());
	assert(0 == edgeList.size());
	INFO("Loading nearest neighbor indices");
	//Init nearest neighbor data structure
	std::ifstream nodesInStream(nodesPath.c_str(), ios::binary);
	nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n, checkSum);
	nodeHelpDesk->initNNGrid(nodesInStream);

	//deserialize street name list
	INFO("Loading names index");
	std::ifstream namesInStream(namesPath.c_str(), ios::binary);
	unsigned size(0);
	namesInStream.read((char *)&size, sizeof(unsigned));
	//        names = new std::vector<std::string>();

	char buf[1024];
	for(unsigned i = 0; i < size; ++i) {
		unsigned sizeOfString = 0;
		namesInStream.read((char *)&sizeOfString, sizeof(unsigned));
		buf[sizeOfString] = '\0'; // instead of memset
		namesInStream.read(buf, sizeOfString);
		names.push_back(buf);
	}
	std::vector<std::string>(names).swap(names);
	hsgrInStream.close();
	namesInStream.close();
	INFO("All query data structures loaded");
}
Esempio n. 3
0
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";
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    LogPolicy::GetInstance().Unmute();
    try
    {
        if (argc != 2)
        {
            SimpleLogger().Write(logWARNING) << "usage: " << argv[0] << " <file.hsgr>";
            return 1;
        }

        boost::filesystem::path hsgr_path(argv[1]);

        std::vector<QueryGraph::NodeArrayEntry> node_list;
        std::vector<QueryGraph::EdgeArrayEntry> edge_list;
        SimpleLogger().Write() << "loading graph from " << hsgr_path.string();

        unsigned m_check_sum = 0;
        unsigned m_number_of_nodes =
            readHSGRFromStream(hsgr_path, node_list, edge_list, &m_check_sum);
        SimpleLogger().Write() << "expecting " << m_number_of_nodes
                               << " nodes, checksum: " << m_check_sum;
        BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty");
        SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size()
                               << " edges";
        auto m_query_graph = std::make_shared<QueryGraph>(node_list, edge_list);

        BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed");
        BOOST_ASSERT_MSG(0 == edge_list.size(), "edge list not flushed");

        Percent progress(m_query_graph->GetNumberOfNodes());
        for (const auto node_u : osrm::irange(0u, m_query_graph->GetNumberOfNodes()))
        {
            for (const auto eid : m_query_graph->GetAdjacentEdgeRange(node_u))
            {
                const EdgeData &data = m_query_graph->GetEdgeData(eid);
                if (!data.shortcut)
                {
                    continue;
                }
                const unsigned node_v = m_query_graph->GetTarget(eid);
                const EdgeID edge_id_1 = m_query_graph->FindEdgeInEitherDirection(node_u, data.id);
                if (SPECIAL_EDGEID == edge_id_1)
                {
                    throw osrm::exception("cannot find first segment of edge (" +
                                        std::to_string(node_u) + "," + std::to_string(data.id) +
                                        "," + std::to_string(node_v) + "), eid: " +
                                        std::to_string(eid));
                }
                const EdgeID edge_id_2 = m_query_graph->FindEdgeInEitherDirection(data.id, node_v);
                if (SPECIAL_EDGEID == edge_id_2)
                {
                    throw osrm::exception("cannot find second segment of edge (" +
                                        std::to_string(node_u) + "," + std::to_string(data.id) +
                                        "," + std::to_string(node_v) + "), eid: " +
                                        std::to_string(eid));
                }
            }
            progress.printStatus(node_u);
        }
        m_query_graph.reset();
        SimpleLogger().Write() << "Data file " << argv[0] << " appears to be OK";
    }
    catch (const std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
    }
    return 0;
}