Upgraded speed profile to the one of ORS

This commit is contained in:
Dennis Luxen 2010-07-23 22:10:57 +00:00
parent 51cc0bb209
commit 49a088ac87
2 changed files with 124 additions and 124 deletions

View File

@ -24,23 +24,23 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <cmath> #include <cmath>
/* Default Speed Profile: /* Default Speed Profile:
motorway 120 motorway 110
motorway_link 80 motorway_link 90
trunk 100 trunk 90
trunk_link 80 trunk_link 70
secondary 100 primary 70
primary_link 60
secondary 60
secondary_link 50 secondary_link 50
primary 100 tertiary 55
primary_link 50
tertiary 100
unclassified 50 unclassified 50
residential 50 residential 40
living_street 30 living_street 10
service 20 service 30
*/ */
string names[13] = { "motorway", "motorway_link", "trunk", "trunk_link", "secondary", "secondary_link", "primary", "primary_link", "tertiary", "unclassified", "residential", "living_street", "service" }; string names[13] = { "motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", "secondary_link", "tertiary", "unclassified", "residential", "living_street", "service" };
double speeds[13] = { 120, 80, 100, 80, 100, 50, 100, 50, 100, 50, 50 , 30, 20}; double speeds[13] = { 110, 90, 90, 70, 70, 60, 60, 50, 55, 50, 40 , 10, 30};
struct _Node : NodeInfo{ struct _Node : NodeInfo{
bool trafficSignal; bool trafficSignal;

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 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.
*/ */
#include <climits> #include <climits>
#include <fstream> #include <fstream>
@ -50,128 +50,128 @@ typedef http::server<StaticGraph<EdgeData> > server;
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
double time; double time;
if(argc < 2) if(argc < 2)
{ {
cerr << "Correct usage:" << endl << argv[0] << " <hsgr data> <nodes data>" << endl; cerr << "Correct usage:" << endl << argv[0] << " <hsgr data> <nodes data>" << endl;
exit(-1); exit(-1);
} }
if (argv[0] == 0) { if (argv[0] == 0) {
cerr << "Missing data files!" << endl; cerr << "Missing data files!" << endl;
return -1; return -1;
} }
ifstream in(argv[1], ios::binary); ifstream in(argv[1], ios::binary);
ifstream in2(argv[2], ios::binary); ifstream in2(argv[2], ios::binary);
NodeInformationHelpDesk * kdtreeService = new NodeInformationHelpDesk(); NodeInformationHelpDesk * kdtreeService = new NodeInformationHelpDesk();
time = get_timestamp(); time = get_timestamp();
cout << "deserializing edge data from " << argv[1] << " ..." << flush; cout << "deserializing edge data from " << argv[1] << " ..." << flush;
std::vector< GraphEdge> edgelist; std::vector< GraphEdge> edgelist;
while(!in.eof()) while(!in.eof())
{ {
GraphEdge g; GraphEdge g;
EdgeData e; EdgeData e;
int distance; int distance;
bool shortcut; bool shortcut;
bool forward; bool forward;
bool backward; bool backward;
NodeID middle; NodeID middle;
NodeID source; NodeID source;
NodeID target; NodeID target;
in.read((char *)&(distance), sizeof(int)); in.read((char *)&(distance), sizeof(int));
assert(distance > 0); assert(distance > 0);
in.read((char *)&(shortcut), sizeof(bool)); in.read((char *)&(shortcut), sizeof(bool));
in.read((char *)&(forward), sizeof(bool)); in.read((char *)&(forward), sizeof(bool));
in.read((char *)&(backward), sizeof(bool)); in.read((char *)&(backward), sizeof(bool));
in.read((char *)&(middle), sizeof(NodeID)); in.read((char *)&(middle), sizeof(NodeID));
in.read((char *)&(source), sizeof(NodeID)); in.read((char *)&(source), sizeof(NodeID));
in.read((char *)&(target), sizeof(NodeID)); in.read((char *)&(target), sizeof(NodeID));
e.backward = backward; e.distance = distance; e.forward = forward; e.middle = middle; e.shortcut = shortcut; e.backward = backward; e.distance = distance; e.forward = forward; e.middle = middle; e.shortcut = shortcut;
g.data = e; g.source = source; g.target = target; g.data = e; g.source = source; g.target = target;
edgelist.push_back(g); edgelist.push_back(g);
} }
in.close(); in.close();
cout << "in " << get_timestamp() - time << "s" << endl; cout << "in " << get_timestamp() - time << "s" << endl;
cout << "search graph has " << edgelist.size() << " edges" << endl; cout << "search graph has " << edgelist.size() << " edges" << endl;
time = get_timestamp(); time = get_timestamp();
cout << "deserializing node map and building kd-tree ..." << flush; cout << "deserializing node map and building kd-tree ..." << flush;
kdtreeService->initKDTree(in2); kdtreeService->initKDTree(in2);
cout << "in " << get_timestamp() - time << "s" << endl; cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp(); time = get_timestamp();
cout << "building search graph ..." << flush; StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(kdtreeService->getNumberOfNodes()-1, edgelist);
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(kdtreeService->getNumberOfNodes()-1, edgelist); cout << "checking data sanity ..." << flush;
cout << "checking sanity ..." << flush; NodeID numberOfNodes = graph->GetNumberOfNodes();
NodeID numberOfNodes = graph->GetNumberOfNodes(); for ( NodeID node = 0; node < numberOfNodes; ++node ) {
for ( NodeID node = 0; node < numberOfNodes; ++node ) { for ( StaticGraph<EdgeData>::EdgeIterator edge = graph->BeginEdges( node ), endEdges = graph->EndEdges( node ); edge != endEdges; ++edge ) {
for ( StaticGraph<EdgeData>::EdgeIterator edge = graph->BeginEdges( node ), endEdges = graph->EndEdges( node ); edge != endEdges; ++edge ) { const NodeID start = node;
const NodeID start = node; const NodeID target = graph->GetTarget( edge );
const NodeID target = graph->GetTarget( edge ); const EdgeData& data = graph->GetEdgeData( edge );
const EdgeData& data = graph->GetEdgeData( edge ); const NodeID middle = data.middle;
const NodeID middle = data.middle; assert(start != target);
assert(start != target); if(data.shortcut)
if(data.shortcut) {
{ if(graph->FindEdge(start, middle) == SPECIAL_EDGEID && graph->FindEdge(middle, start) == SPECIAL_EDGEID)
if(graph->FindEdge(start, middle) == SPECIAL_EDGEID && graph->FindEdge(middle, start) == SPECIAL_EDGEID) {
{ assert(false);
assert(false); cerr << "hierarchy broken" << endl; exit(-1);
cerr << "hierarchy broken" << endl; exit(-1); }
} if(graph->FindEdge(middle, target) == SPECIAL_EDGEID && graph->FindEdge(target, middle) == SPECIAL_EDGEID)
if(graph->FindEdge(middle, target) == SPECIAL_EDGEID && graph->FindEdge(target, middle) == SPECIAL_EDGEID) {
{ assert(false);
assert(false); cerr << "hierarchy broken" << endl; exit(-1);
cerr << "hierarchy broken" << endl; exit(-1); }
} }
} }
} }
} cout << "in " << get_timestamp() - time << "s" << endl;
cout << "ok" << endl; cout << "building search graph ..." << flush;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, kdtreeService); SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, kdtreeService);
cout << "in " << get_timestamp() - time << "s" << endl; cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp(); time = get_timestamp();
try { try {
// Block all signals for background thread. // Block all signals for background thread.
sigset_t new_mask; sigset_t new_mask;
sigfillset(&new_mask); sigfillset(&new_mask);
sigset_t old_mask; sigset_t old_mask;
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
cout << "starting web server ..." << flush; cout << "starting web server ..." << flush;
// Run server in background thread. // Run server in background thread.
server s("0.0.0.0", "5000", omp_get_num_procs(), sEngine); server s("0.0.0.0", "5000", omp_get_num_procs(), sEngine);
boost::thread t(boost::bind(&server::run, &s)); boost::thread t(boost::bind(&server::run, &s));
cout << "ok" << endl; cout << "ok" << endl;
// Restore previous signals. // Restore previous signals.
pthread_sigmask(SIG_SETMASK, &old_mask, 0); pthread_sigmask(SIG_SETMASK, &old_mask, 0);
// Wait for signal indicating time to shut down. // Wait for signal indicating time to shut down.
sigset_t wait_mask; sigset_t wait_mask;
sigemptyset(&wait_mask); sigemptyset(&wait_mask);
sigaddset(&wait_mask, SIGINT); sigaddset(&wait_mask, SIGINT);
sigaddset(&wait_mask, SIGQUIT); sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM); sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0); pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
int sig = 0; int sig = 0;
sigwait(&wait_mask, &sig); sigwait(&wait_mask, &sig);
// Stop the server. // Stop the server.
s.stop(); s.stop();
t.join(); t.join();
} }
catch (std::exception& e) catch (std::exception& e)
{ {
std::cerr << "exception: " << e.what() << "\n"; std::cerr << "exception: " << e.what() << "\n";
} }
cout << "graceful shutdown after " << get_timestamp() - time << "s" << endl; cout << "graceful shutdown after " << get_timestamp() - time << "s" << endl;
delete kdtreeService; delete kdtreeService;
return 0; return 0;
} }