moving common code into a single file

This commit is contained in:
Dennis Luxen 2010-09-15 13:49:26 +00:00
parent 10ea331909
commit a07efcc4b7
3 changed files with 98 additions and 125 deletions

View File

@ -16,7 +16,7 @@ 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.
*/
*/
#ifndef CREATEGRAPH_H
#define GRAPHLOADER_H
@ -42,7 +42,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
typedef google::dense_hash_map<NodeID, NodeID> ExternalNodeMap;
template<typename EdgeT>
inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) {
NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) {
NodeID n, source, target, id;
EdgeID m;
bool locatable;
@ -77,7 +77,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
if(length == 0)
{ cerr << "loaded null length edge" << endl; exit(1); }
// translate the external NodeIDs to internal IDs
// translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end())
{
@ -101,4 +101,34 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
return n;
}
template<typename EdgeT>
void readHSGRFromStream(istream &in, vector<EdgeT> * edgeList) {
while(!in.eof())
{
EdgeT g;
EdgeData e;
int distance;
bool shortcut;
bool forward;
bool backward;
NodeID middle;
NodeID source;
NodeID target;
in.read((char *)&(distance), sizeof(int));
assert(distance > 0);
in.read((char *)&(shortcut), sizeof(bool));
in.read((char *)&(forward), sizeof(bool));
in.read((char *)&(backward), sizeof(bool));
in.read((char *)&(middle), sizeof(NodeID));
in.read((char *)&(source), sizeof(NodeID));
in.read((char *)&(target), sizeof(NodeID));
e.backward = backward; e.distance = distance; e.forward = forward; e.middle = middle; e.shortcut = shortcut;
g.data = e; g.source = source; g.target = target;
edgeList->push_back(g);
}
}
#endif // CREATEGRAPH_H

View File

@ -70,7 +70,7 @@ int main (int argc, char *argv[])
cerr << "Cannot open " << argv[1] << endl; exit(-1);
}
vector<ImportEdge> edgeList;
const NodeID n = readOSMRGraphFromStream(in, edgeList, int2ExtNodeMap);
const NodeID n = readOSRMGraphFromStream(in, edgeList, int2ExtNodeMap);
in.close();
char nodeOut[1024];

View File

@ -36,6 +36,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "HttpServer/server.h"
#include "Contractor/GraphLoader.h"
#include "DataStructures/StaticGraph.h"
using namespace std;
@ -49,89 +50,31 @@ typedef http::server<StaticGraph<EdgeData> > server;
*/
int main (int argc, char *argv[])
{
double time;
if(argc < 4)
{
cerr << "Correct usage:" << endl << argv[0] << " <hsgr data> <nodes data> <ram index> <file index>" << endl;
exit(-1);
}
ifstream in(argv[1], ios::binary);
ifstream in2(argv[2], ios::binary);
ifstream hsgrInStream(argv[1], ios::binary);
ifstream nodesInStream(argv[2], ios::binary);
NodeInformationHelpDesk * nodeInfoHelper = new NodeInformationHelpDesk(argv[3], argv[4]);
time = get_timestamp();
double time = get_timestamp();
cout << "deserializing edge data from " << argv[1] << " ..." << flush;
std::vector< GridEdge> * edgeList = new std::vector< GridEdge>();
while(!in.eof())
{
GridEdge g;
EdgeData e;
int distance;
bool shortcut;
bool forward;
bool backward;
NodeID middle;
NodeID source;
NodeID target;
in.read((char *)&(distance), sizeof(int));
assert(distance > 0);
in.read((char *)&(shortcut), sizeof(bool));
in.read((char *)&(forward), sizeof(bool));
in.read((char *)&(backward), sizeof(bool));
in.read((char *)&(middle), sizeof(NodeID));
in.read((char *)&(source), sizeof(NodeID));
in.read((char *)&(target), sizeof(NodeID));
e.backward = backward; e.distance = distance; e.forward = forward; e.middle = middle; e.shortcut = shortcut;
g.data = e; g.source = source; g.target = target;
edgeList->push_back(g);
}
in.close();
readHSGRFromStream(hsgrInStream, edgeList);
hsgrInStream.close();
cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "deserializing node map and building nearest neighbor grid ..." << flush;
nodeInfoHelper->initNNGrid(in2);
nodeInfoHelper->initNNGrid(nodesInStream);
cout << "in " << get_timestamp() - time << "s" << endl;
// time = get_timestamp();
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(nodeInfoHelper->getNumberOfNodes()-1, *edgeList);
delete edgeList;
// cout << "checking data sanity ..." << flush;
// NodeID numberOfNodes = graph->GetNumberOfNodes();
// for ( NodeID node = 0; node < numberOfNodes; ++node ) {
// for ( StaticGraph<EdgeData>::EdgeIterator edge = graph->BeginEdges( node ), endEdges = graph->EndEdges( node ); edge != endEdges; ++edge ) {
// const NodeID start = node;
// const NodeID target = graph->GetTarget( edge );
// const EdgeData& data = graph->GetEdgeData( edge );
// const NodeID middle = data.middle;
// assert(start != target);
// if(data.shortcut)
// {
// if(graph->FindEdge(start, middle) == SPECIAL_EDGEID && graph->FindEdge(middle, start) == SPECIAL_EDGEID)
// {
// assert(false);
// cerr << "hierarchy broken" << endl; exit(-1);
// }
// if(graph->FindEdge(middle, target) == SPECIAL_EDGEID && graph->FindEdge(target, middle) == SPECIAL_EDGEID)
// {
// assert(false);
// cerr << "hierarchy broken" << endl; exit(-1);
// }
// }
// }
// if(graph->GetOutDegree(node) == 0)
// {
// cerr << "found node with degree 0: " << node << endl;
// }
// }
// cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "building search graph ..." << flush;
cout << "constructing search graph ..." << flush;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeInfoHelper);
cout << "in " << get_timestamp() - time << "s" << endl;