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>
/* Default Speed Profile:
motorway 120
motorway_link 80
trunk 100
trunk_link 80
secondary 100
motorway 110
motorway_link 90
trunk 90
trunk_link 70
primary 70
primary_link 60
secondary 60
secondary_link 50
primary 100
primary_link 50
tertiary 100
tertiary 55
unclassified 50
residential 50
living_street 30
service 20
residential 40
living_street 10
service 30
*/
string names[13] = { "motorway", "motorway_link", "trunk", "trunk_link", "secondary", "secondary_link", "primary", "primary_link", "tertiary", "unclassified", "residential", "living_street", "service" };
double speeds[13] = { 120, 80, 100, 80, 100, 50, 100, 50, 100, 50, 50 , 30, 20};
string names[13] = { "motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", "secondary_link", "tertiary", "unclassified", "residential", "living_street", "service" };
double speeds[13] = { 110, 90, 90, 70, 70, 60, 60, 50, 55, 50, 40 , 10, 30};
struct _Node : NodeInfo{
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
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
*/
#include <climits>
#include <fstream>
@ -50,128 +50,128 @@ typedef http::server<StaticGraph<EdgeData> > server;
int main (int argc, char *argv[])
{
double time;
double time;
if(argc < 2)
{
cerr << "Correct usage:" << endl << argv[0] << " <hsgr data> <nodes data>" << endl;
exit(-1);
}
if(argc < 2)
{
cerr << "Correct usage:" << endl << argv[0] << " <hsgr data> <nodes data>" << endl;
exit(-1);
}
if (argv[0] == 0) {
cerr << "Missing data files!" << endl;
return -1;
}
ifstream in(argv[1], ios::binary);
ifstream in2(argv[2], ios::binary);
NodeInformationHelpDesk * kdtreeService = new NodeInformationHelpDesk();
if (argv[0] == 0) {
cerr << "Missing data files!" << endl;
return -1;
}
ifstream in(argv[1], ios::binary);
ifstream in2(argv[2], ios::binary);
NodeInformationHelpDesk * kdtreeService = new NodeInformationHelpDesk();
time = get_timestamp();
cout << "deserializing edge data from " << argv[1] << " ..." << flush;
time = get_timestamp();
cout << "deserializing edge data from " << argv[1] << " ..." << flush;
std::vector< GraphEdge> edgelist;
while(!in.eof())
{
GraphEdge g;
EdgeData e;
std::vector< GraphEdge> edgelist;
while(!in.eof())
{
GraphEdge g;
EdgeData e;
int distance;
bool shortcut;
bool forward;
bool backward;
NodeID middle;
NodeID source;
NodeID target;
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;
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);
}
edgelist.push_back(g);
}
in.close();
cout << "in " << get_timestamp() - time << "s" << endl;
cout << "search graph has " << edgelist.size() << " edges" << endl;
time = get_timestamp();
cout << "deserializing node map and building kd-tree ..." << flush;
kdtreeService->initKDTree(in2);
cout << "in " << get_timestamp() - time << "s" << endl;
in.close();
cout << "in " << get_timestamp() - time << "s" << endl;
cout << "search graph has " << edgelist.size() << " edges" << endl;
time = get_timestamp();
cout << "deserializing node map and building kd-tree ..." << flush;
kdtreeService->initKDTree(in2);
cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "building search graph ..." << flush;
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(kdtreeService->getNumberOfNodes()-1, edgelist);
cout << "checking 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);
}
}
}
}
cout << "ok" << endl;
time = get_timestamp();
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(kdtreeService->getNumberOfNodes()-1, 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);
}
}
}
}
cout << "in " << get_timestamp() - time << "s" << endl;
cout << "building search graph ..." << flush;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, kdtreeService);
cout << "in " << get_timestamp() - time << "s" << endl;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, kdtreeService);
cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
try {
// Block all signals for background thread.
sigset_t new_mask;
sigfillset(&new_mask);
sigset_t old_mask;
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
time = get_timestamp();
try {
// Block all signals for background thread.
sigset_t new_mask;
sigfillset(&new_mask);
sigset_t old_mask;
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
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;
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;
// Restore previous signals.
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
// Restore previous signals.
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
// Wait for signal indicating time to shut down.
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 kdtreeService;
return 0;
// Wait for signal indicating time to shut down.
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 kdtreeService;
return 0;
}