Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
CRC32 of data is written to file and loaded into NodeInfoHelpDesk.
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM committed Feb 17, 2012
1 parent ac41c3b commit e034733
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
7 changes: 6 additions & 1 deletion DataStructures/NodeInformationHelpDesk.h
Expand Up @@ -31,7 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt.

class NodeInformationHelpDesk{
public:
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes) : numberOfNodes(_numberOfNodes) {
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) {
readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
coordinateVector.reserve(numberOfNodes);
assert(0 == coordinateVector.size());
Expand Down Expand Up @@ -72,10 +72,15 @@ class NodeInformationHelpDesk{
readOnlyGrid->FindNearestPointOnEdge(input, output);
}

inline unsigned GetCheckSum() const {
return checkSum;
}

private:
std::vector<_Coordinate> coordinateVector;
ReadOnlyGrid * readOnlyGrid;
unsigned numberOfNodes;
unsigned checkSum;
};

#endif /*NODEINFORMATIONHELPDESK_H_*/
6 changes: 4 additions & 2 deletions Plugins/ObjectForPluginStruct.h
Expand Up @@ -36,21 +36,23 @@ struct ObjectsForQueryStruct {
NodeInformationHelpDesk * nodeHelpDesk;
std::vector<std::string> * names;
QueryGraph * graph;
unsigned checkSum;

ObjectsForQueryStruct(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") {
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);
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);
nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n, checkSum);
nodeHelpDesk->initNNGrid(nodesInStream);

//deserialize street name list
Expand Down
3 changes: 2 additions & 1 deletion Util/GraphLoader.h
Expand Up @@ -361,8 +361,9 @@ NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
}

template<typename NodeT, typename EdgeT>
unsigned readHSGRFromStream(istream &in, vector<NodeT>& nodeList, vector<EdgeT> & edgeList) {
unsigned readHSGRFromStream(istream &in, vector<NodeT>& nodeList, vector<EdgeT> & edgeList, unsigned * checkSum) {
unsigned numberOfNodes = 0;
in.read((char*) checkSum, sizeof(unsigned));
in.read((char*) & numberOfNodes, sizeof(unsigned));
nodeList.resize(numberOfNodes + 1);
NodeT currentNode;
Expand Down
17 changes: 12 additions & 5 deletions createHierarchy.cpp
Expand Up @@ -37,6 +37,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <string>
#include <vector>

#include "Algorithms/CRC32.h"
#include "Util/OpenMPReplacement.h"
#include "typedefs.h"
#include "Contractor/Contractor.h"
Expand Down Expand Up @@ -129,27 +130,32 @@ int main (int argc, char *argv[]) {
std::vector<EdgeBasedGraphFactory::EdgeBasedNode> nodeBasedEdgeList;
edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList);
DELETE(edgeBasedGraphFactory);

double expansionHasFinishedTime = get_timestamp() - startupTime;

WritableGrid * writeableGrid = new WritableGrid();
INFO("building grid ...");
writeableGrid->ConstructGrid(nodeBasedEdgeList, ramIndexOut, fileIndexOut);
DELETE( writeableGrid );
CRC32 crc32;
unsigned crc32OfNodeBasedEdgeList = crc32((char *)&(nodeBasedEdgeList[0]), nodeBasedEdgeList.size()*sizeof(EdgeBasedGraphFactory::EdgeBasedNode));
// INFO("CRC32 of data is " << crc32OfNodeBasedEdgeList);

nodeBasedEdgeList.clear();
std::vector<EdgeBasedGraphFactory::EdgeBasedNode>().swap(nodeBasedEdgeList);

INFO("writing node map ...");
std::ofstream mapOutFile(nodeOut, ios::binary);
BOOST_FOREACH(NodeInfo & info, internalToExternaleNodeMapping) {
mapOutFile.write((char *)&(info), sizeof(NodeInfo));
}
mapOutFile.write((char *)&(internalToExternaleNodeMapping[0]), internalToExternaleNodeMapping.size()*sizeof(NodeInfo));
mapOutFile.close();
internalToExternaleNodeMapping.clear();


std::vector<NodeInfo>().swap(internalToExternaleNodeMapping);
inputRestrictions.clear();
std::vector<_Restriction>().swap(inputRestrictions);

// unsigned crc32OfNodeBasedEdgeList = crc32((char*)&edgeBasedEdgeList[0], edgeBasedEdgeList.size());
// INFO("CRC32 of data is " << crc32OfNodeBasedEdgeList);

INFO("initializing contractor");
Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList );
double contractionStartedTimestamp(get_timestamp());
Expand Down Expand Up @@ -199,6 +205,7 @@ int main (int argc, char *argv[]) {
position += edge - lastEdge; //remove
}
//Serialize numberOfNodes, nodes
edgeOutFile.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned));
edgeOutFile.write((char*) &numberOfNodes, sizeof(unsigned));
edgeOutFile.write((char*) &_nodes[0], sizeof(StaticGraph<EdgeData>::_StrNode)*(numberOfNodes+1));

Expand Down

0 comments on commit e034733

Please sign in to comment.