moving common code into a single file
This commit is contained in:
parent
10ea331909
commit
a07efcc4b7
@ -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
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CREATEGRAPH_H
|
#ifndef CREATEGRAPH_H
|
||||||
#define GRAPHLOADER_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;
|
typedef google::dense_hash_map<NodeID, NodeID> ExternalNodeMap;
|
||||||
|
|
||||||
template<typename EdgeT>
|
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;
|
NodeID n, source, target, id;
|
||||||
EdgeID m;
|
EdgeID m;
|
||||||
bool locatable;
|
bool locatable;
|
||||||
@ -77,13 +77,13 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
|
|||||||
if(length == 0)
|
if(length == 0)
|
||||||
{ cerr << "loaded null length edge" << endl; exit(1); }
|
{ 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);
|
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
|
||||||
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end())
|
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end())
|
||||||
{
|
{
|
||||||
cerr << "after " << edgeList.size() << " edges" << endl;
|
cerr << "after " << edgeList.size() << " edges" << endl;
|
||||||
cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl;
|
cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl;
|
||||||
cerr << "unresolved source NodeID: " << source << endl; exit(0);
|
cerr << "unresolved source NodeID: " << source << endl; exit(0);
|
||||||
}
|
}
|
||||||
source = intNodeID->second;
|
source = intNodeID->second;
|
||||||
intNodeID = ext2IntNodeMap.find(target);
|
intNodeID = ext2IntNodeMap.find(target);
|
||||||
@ -101,4 +101,34 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
|
|||||||
return n;
|
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
|
#endif // CREATEGRAPH_H
|
||||||
|
@ -70,7 +70,7 @@ int main (int argc, char *argv[])
|
|||||||
cerr << "Cannot open " << argv[1] << endl; exit(-1);
|
cerr << "Cannot open " << argv[1] << endl; exit(-1);
|
||||||
}
|
}
|
||||||
vector<ImportEdge> edgeList;
|
vector<ImportEdge> edgeList;
|
||||||
const NodeID n = readOSMRGraphFromStream(in, edgeList, int2ExtNodeMap);
|
const NodeID n = readOSRMGraphFromStream(in, edgeList, int2ExtNodeMap);
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
char nodeOut[1024];
|
char nodeOut[1024];
|
||||||
|
179
routed.cpp
179
routed.cpp
@ -36,6 +36,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include "HttpServer/server.h"
|
#include "HttpServer/server.h"
|
||||||
|
#include "Contractor/GraphLoader.h"
|
||||||
#include "DataStructures/StaticGraph.h"
|
#include "DataStructures/StaticGraph.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -49,131 +50,73 @@ typedef http::server<StaticGraph<EdgeData> > server;
|
|||||||
*/
|
*/
|
||||||
int main (int argc, char *argv[])
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
if(argc < 4)
|
ifstream hsgrInStream(argv[1], ios::binary);
|
||||||
{
|
ifstream nodesInStream(argv[2], ios::binary);
|
||||||
cerr << "Correct usage:" << endl << argv[0] << " <hsgr data> <nodes data> <ram index> <file index>" << endl;
|
NodeInformationHelpDesk * nodeInfoHelper = new NodeInformationHelpDesk(argv[3], argv[4]);
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ifstream in(argv[1], ios::binary);
|
double time = get_timestamp();
|
||||||
ifstream in2(argv[2], ios::binary);
|
cout << "deserializing edge data from " << argv[1] << " ..." << flush;
|
||||||
NodeInformationHelpDesk * nodeInfoHelper = new NodeInformationHelpDesk(argv[3], argv[4]);
|
|
||||||
|
|
||||||
time = get_timestamp();
|
std::vector< GridEdge> * edgeList = new std::vector< GridEdge>();
|
||||||
cout << "deserializing edge data from " << argv[1] << " ..." << flush;
|
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(nodesInStream);
|
||||||
|
cout << "in " << get_timestamp() - time << "s" << endl;
|
||||||
|
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(nodeInfoHelper->getNumberOfNodes()-1, *edgeList);
|
||||||
|
delete edgeList;
|
||||||
|
time = get_timestamp();
|
||||||
|
cout << "constructing search graph ..." << flush;
|
||||||
|
|
||||||
std::vector< GridEdge> * edgeList = new std::vector< GridEdge>();
|
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeInfoHelper);
|
||||||
while(!in.eof())
|
cout << "in " << get_timestamp() - time << "s" << endl;
|
||||||
{
|
|
||||||
GridEdge g;
|
|
||||||
EdgeData e;
|
|
||||||
|
|
||||||
int distance;
|
time = get_timestamp();
|
||||||
bool shortcut;
|
|
||||||
bool forward;
|
|
||||||
bool backward;
|
|
||||||
NodeID middle;
|
|
||||||
NodeID source;
|
|
||||||
NodeID target;
|
|
||||||
|
|
||||||
in.read((char *)&(distance), sizeof(int));
|
try {
|
||||||
assert(distance > 0);
|
// Block all signals for background thread.
|
||||||
in.read((char *)&(shortcut), sizeof(bool));
|
sigset_t new_mask;
|
||||||
in.read((char *)&(forward), sizeof(bool));
|
sigfillset(&new_mask);
|
||||||
in.read((char *)&(backward), sizeof(bool));
|
sigset_t old_mask;
|
||||||
in.read((char *)&(middle), sizeof(NodeID));
|
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
|
||||||
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);
|
cout << "starting web server ..." << flush;
|
||||||
}
|
// Run server in background thread.
|
||||||
|
server s("0.0.0.0", "5000", omp_get_num_procs(), sEngine);
|
||||||
|
boost::thread t(boost::bind(&server::run, &s));
|
||||||
|
cout << "ok" << endl;
|
||||||
|
|
||||||
in.close();
|
// Restore previous signals.
|
||||||
cout << "in " << get_timestamp() - time << "s" << endl;
|
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
|
||||||
time = get_timestamp();
|
|
||||||
cout << "deserializing node map and building nearest neighbor grid ..." << flush;
|
|
||||||
nodeInfoHelper->initNNGrid(in2);
|
|
||||||
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;
|
|
||||||
|
|
||||||
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeInfoHelper);
|
// Wait for signal indicating time to shut down.
|
||||||
cout << "in " << get_timestamp() - time << "s" << endl;
|
sigset_t wait_mask;
|
||||||
|
sigemptyset(&wait_mask);
|
||||||
time = get_timestamp();
|
sigaddset(&wait_mask, SIGINT);
|
||||||
|
sigaddset(&wait_mask, SIGQUIT);
|
||||||
try {
|
sigaddset(&wait_mask, SIGTERM);
|
||||||
// Block all signals for background thread.
|
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
|
||||||
sigset_t new_mask;
|
int sig = 0;
|
||||||
sigfillset(&new_mask);
|
sigwait(&wait_mask, &sig);
|
||||||
sigset_t old_mask;
|
// Stop the server.
|
||||||
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
|
s.stop();
|
||||||
|
t.join();
|
||||||
cout << "starting web server ..." << flush;
|
}
|
||||||
// Run server in background thread.
|
catch (std::exception& e)
|
||||||
server s("0.0.0.0", "5000", omp_get_num_procs(), sEngine);
|
{
|
||||||
boost::thread t(boost::bind(&server::run, &s));
|
std::cerr << "exception: " << e.what() << "\n";
|
||||||
cout << "ok" << endl;
|
}
|
||||||
|
cout << "graceful shutdown after " << get_timestamp() - time << "s" << endl;
|
||||||
// Restore previous signals.
|
delete sEngine;
|
||||||
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
|
delete graph;
|
||||||
|
delete nodeInfoHelper;
|
||||||
// Wait for signal indicating time to shut down.
|
return 0;
|
||||||
sigset_t wait_mask;
|
|
||||||
sigemptyset(&wait_mask);
|
|
||||||
sigaddset(&wait_mask, SIGINT);
|
|
||||||
sigaddset(&wait_mask, SIGQUIT);
|
|
||||||
sigaddset(&wait_mask, SIGTERM);
|
|
||||||
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
|
|
||||||
int sig = 0;
|
|
||||||
sigwait(&wait_mask, &sig);
|
|
||||||
// Stop the server.
|
|
||||||
s.stop();
|
|
||||||
t.join();
|
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
|
||||||
{
|
|
||||||
std::cerr << "exception: " << e.what() << "\n";
|
|
||||||
}
|
|
||||||
cout << "graceful shutdown after " << get_timestamp() - time << "s" << endl;
|
|
||||||
delete sEngine;
|
|
||||||
delete graph;
|
|
||||||
delete nodeInfoHelper;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user