make sure any data structure is only loaded once. saves roughly 25% of RAM and starts up 10% faster on benchmark instances.
This commit is contained in:
parent
860e73a633
commit
5f6cac9155
@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "ObjectForPluginStruct.h"
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
#include "RouteParameters.h"
|
#include "RouteParameters.h"
|
||||||
|
|
||||||
@ -33,13 +34,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
*/
|
*/
|
||||||
class LocatePlugin : public BasePlugin {
|
class LocatePlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
LocatePlugin(std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath) {
|
LocatePlugin(ObjectsForQueryStruct * objects) {
|
||||||
nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str());
|
nodeHelpDesk = objects->nodeHelpDesk;
|
||||||
ifstream nodesInStream(nodesPath.c_str(), ios::binary);
|
|
||||||
nodeHelpDesk->initNNGrid(nodesInStream);
|
|
||||||
}
|
|
||||||
~LocatePlugin() {
|
|
||||||
delete nodeHelpDesk;
|
|
||||||
}
|
}
|
||||||
std::string GetDescriptor() { return std::string("locate"); }
|
std::string GetDescriptor() { return std::string("locate"); }
|
||||||
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
||||||
|
@ -25,6 +25,9 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
#include "RouteParameters.h"
|
#include "RouteParameters.h"
|
||||||
|
|
||||||
|
#include "ObjectForPluginStruct.h"
|
||||||
|
|
||||||
#include "../DataStructures/NodeInformationHelpDesk.h"
|
#include "../DataStructures/NodeInformationHelpDesk.h"
|
||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../Util/StrIngUtil.h"
|
#include "../Util/StrIngUtil.h"
|
||||||
@ -34,17 +37,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
*/
|
*/
|
||||||
class NearestPlugin : public BasePlugin {
|
class NearestPlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
NearestPlugin(std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath) {
|
NearestPlugin(ObjectsForQueryStruct * objects) {
|
||||||
nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str());
|
nodeHelpDesk = objects->nodeHelpDesk;
|
||||||
ifstream nodesInStream(nodesPath.c_str(), ios::binary);
|
|
||||||
nodeHelpDesk->initNNGrid(nodesInStream);
|
|
||||||
descriptorTable.Set("", 0); //default descriptor
|
descriptorTable.Set("", 0); //default descriptor
|
||||||
descriptorTable.Set("kml", 0);
|
descriptorTable.Set("kml", 0);
|
||||||
descriptorTable.Set("json", 1);
|
descriptorTable.Set("json", 1);
|
||||||
}
|
}
|
||||||
~NearestPlugin() {
|
|
||||||
delete nodeHelpDesk;
|
|
||||||
}
|
|
||||||
std::string GetDescriptor() { return std::string("nearest"); }
|
std::string GetDescriptor() { return std::string("nearest"); }
|
||||||
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
std::string GetVersionString() { return std::string("0.3 (DL)"); }
|
||||||
void HandleRequest(RouteParameters routeParameters, http::Reply& reply) {
|
void HandleRequest(RouteParameters routeParameters, http::Reply& reply) {
|
||||||
|
77
Plugins/ObjectForPluginStruct.h
Normal file
77
Plugins/ObjectForPluginStruct.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
open source routing machine
|
||||||
|
Copyright (C) Dennis Luxen, others 2010
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU AFFERO General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
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 OBJECTFORPLUGINSTRUCT_H_
|
||||||
|
#define OBJECTFORPLUGINSTRUCT_H_
|
||||||
|
|
||||||
|
#include "../DataStructures/StaticGraph.h"
|
||||||
|
#include "../Util/GraphLoader.h"
|
||||||
|
|
||||||
|
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
||||||
|
typedef StaticGraph<EdgeData>::InputEdge InputEdge;
|
||||||
|
|
||||||
|
struct ObjectsForQueryStruct {
|
||||||
|
ObjectsForQueryStruct(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") {
|
||||||
|
std::cout << "[objects] loading query data structures ..." << std::flush;
|
||||||
|
//Init nearest neighbor data structure
|
||||||
|
ifstream nodesInStream(nodesPath.c_str(), ios::binary);
|
||||||
|
nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str());
|
||||||
|
nodeHelpDesk->initNNGrid(nodesInStream);
|
||||||
|
|
||||||
|
ifstream hsgrInStream(hsgrPath.c_str(), ios::binary);
|
||||||
|
//Deserialize road network graph
|
||||||
|
std::vector< InputEdge> * edgeList = new std::vector< InputEdge>();
|
||||||
|
readHSGRFromStream(hsgrInStream, edgeList);
|
||||||
|
graph = new StaticGraph<EdgeData>(nodeHelpDesk->getNumberOfNodes()-1, *edgeList);
|
||||||
|
delete edgeList;
|
||||||
|
|
||||||
|
//deserialize street name list
|
||||||
|
ifstream namesInStream(namesPath.c_str(), ios::binary);
|
||||||
|
unsigned size = 0;
|
||||||
|
namesInStream.read((char *)&size, sizeof(unsigned));
|
||||||
|
names = new std::vector<std::string>();
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
for(unsigned i = 0; i < size; i++) {
|
||||||
|
unsigned sizeOfString = 0;
|
||||||
|
namesInStream.read((char *)&sizeOfString, sizeof(unsigned));
|
||||||
|
memset(buf, 0, 1024*sizeof(char));
|
||||||
|
namesInStream.read(buf, sizeOfString);
|
||||||
|
std::string currentStreetName(buf);
|
||||||
|
names->push_back(currentStreetName);
|
||||||
|
}
|
||||||
|
hsgrInStream.close();
|
||||||
|
namesInStream.close();
|
||||||
|
std::cout << "ok" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
~ObjectsForQueryStruct() {
|
||||||
|
delete names;
|
||||||
|
delete graph;
|
||||||
|
delete nodeHelpDesk;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeInformationHelpDesk * nodeHelpDesk;
|
||||||
|
std::vector<std::string> * names;
|
||||||
|
StaticGraph<EdgeData> * graph;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* OBJECTFORPLUGINSTRUCT_H_ */
|
@ -27,6 +27,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "ObjectForPluginStruct.h"
|
||||||
|
|
||||||
#include "BaseDescriptor.h"
|
#include "BaseDescriptor.h"
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
#include "RouteParameters.h"
|
#include "RouteParameters.h"
|
||||||
@ -37,56 +39,24 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../DataStructures/StaticGraph.h"
|
#include "../DataStructures/StaticGraph.h"
|
||||||
#include "../DataStructures/SearchEngine.h"
|
#include "../DataStructures/SearchEngine.h"
|
||||||
|
|
||||||
#include "../Util/GraphLoader.h"
|
|
||||||
#include "../Util/StrIngUtil.h"
|
#include "../Util/StrIngUtil.h"
|
||||||
|
|
||||||
typedef ContractionCleanup::Edge::EdgeData EdgeData;
|
|
||||||
typedef StaticGraph<EdgeData>::InputEdge InputEdge;
|
|
||||||
|
|
||||||
class RoutePlugin : public BasePlugin {
|
class RoutePlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
RoutePlugin(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") {
|
|
||||||
//Init nearest neighbor data structure
|
|
||||||
nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str());
|
|
||||||
ifstream nodesInStream(nodesPath.c_str(), ios::binary);
|
|
||||||
ifstream hsgrInStream(hsgrPath.c_str(), ios::binary);
|
|
||||||
nodeHelpDesk->initNNGrid(nodesInStream);
|
|
||||||
|
|
||||||
//Deserialize road network graph
|
RoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "route") : pluginDescriptorString(psd) {
|
||||||
std::vector< InputEdge> * edgeList = new std::vector< InputEdge>();
|
nodeHelpDesk = objects->nodeHelpDesk;
|
||||||
readHSGRFromStream(hsgrInStream, edgeList);
|
graph = objects->graph;
|
||||||
hsgrInStream.close();
|
names = objects->names;
|
||||||
graph = new StaticGraph<EdgeData>(nodeHelpDesk->getNumberOfNodes()-1, *edgeList);
|
|
||||||
delete edgeList;
|
|
||||||
|
|
||||||
//deserialize street name list
|
|
||||||
ifstream namesInStream(namesPath.c_str(), ios::binary);
|
|
||||||
unsigned size = 0;
|
|
||||||
namesInStream.read((char *)&size, sizeof(unsigned));
|
|
||||||
names = new std::vector<std::string>();
|
|
||||||
|
|
||||||
char buf[1024];
|
|
||||||
for(unsigned i = 0; i < size; i++) {
|
|
||||||
unsigned sizeOfString = 0;
|
|
||||||
namesInStream.read((char *)&sizeOfString, sizeof(unsigned));
|
|
||||||
memset(buf, 0, 1024*sizeof(char));
|
|
||||||
namesInStream.read(buf, sizeOfString);
|
|
||||||
std::string currentStreetName(buf);
|
|
||||||
names->push_back(currentStreetName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//init complete search engine
|
|
||||||
sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names);
|
sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names);
|
||||||
descriptorTable.Set("", 0); //default descriptor
|
descriptorTable.Set("", 0); //default descriptor
|
||||||
descriptorTable.Set("kml", 0);
|
descriptorTable.Set("kml", 0);
|
||||||
descriptorTable.Set("json", 1);
|
descriptorTable.Set("json", 1);
|
||||||
pluginDescriptorString = psd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~RoutePlugin() {
|
~RoutePlugin() {
|
||||||
delete names;
|
|
||||||
delete sEngine;
|
delete sEngine;
|
||||||
delete graph;
|
|
||||||
delete nodeHelpDesk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetDescriptor() { return pluginDescriptorString; }
|
std::string GetDescriptor() { return pluginDescriptorString; }
|
||||||
|
34
routed.cpp
34
routed.cpp
@ -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 <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -30,6 +30,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "Server/ServerConfiguration.h"
|
#include "Server/ServerConfiguration.h"
|
||||||
#include "Server/ServerFactory.h"
|
#include "Server/ServerFactory.h"
|
||||||
|
|
||||||
|
#include "Plugins/ObjectForPluginStruct.h"
|
||||||
|
|
||||||
#include "Plugins/HelloWorldPlugin.h"
|
#include "Plugins/HelloWorldPlugin.h"
|
||||||
#include "Plugins/LocatePlugin.h"
|
#include "Plugins/LocatePlugin.h"
|
||||||
#include "Plugins/NearestPlugin.h"
|
#include "Plugins/NearestPlugin.h"
|
||||||
@ -59,27 +61,22 @@ int main (int argc, char *argv[])
|
|||||||
Server * s = ServerFactory::CreateServer(serverConfig);
|
Server * s = ServerFactory::CreateServer(serverConfig);
|
||||||
RequestHandler & h = s->GetRequestHandlerPtr();
|
RequestHandler & h = s->GetRequestHandlerPtr();
|
||||||
|
|
||||||
BasePlugin * helloWorld = new HelloWorldPlugin();
|
ObjectsForQueryStruct * objects = new ObjectsForQueryStruct(serverConfig.GetParameter("hsgrData"),
|
||||||
h.RegisterPlugin(helloWorld);
|
|
||||||
|
|
||||||
BasePlugin * locate = new LocatePlugin(
|
|
||||||
serverConfig.GetParameter("ramIndex"),
|
|
||||||
serverConfig.GetParameter("fileIndex"),
|
|
||||||
serverConfig.GetParameter("nodesData"));
|
|
||||||
h.RegisterPlugin(locate);
|
|
||||||
|
|
||||||
BasePlugin * nearest = new NearestPlugin(
|
|
||||||
serverConfig.GetParameter("ramIndex"),
|
|
||||||
serverConfig.GetParameter("fileIndex"),
|
|
||||||
serverConfig.GetParameter("nodesData"));
|
|
||||||
h.RegisterPlugin(nearest);
|
|
||||||
|
|
||||||
BasePlugin * route = new RoutePlugin(
|
|
||||||
serverConfig.GetParameter("hsgrData"),
|
|
||||||
serverConfig.GetParameter("ramIndex"),
|
serverConfig.GetParameter("ramIndex"),
|
||||||
serverConfig.GetParameter("fileIndex"),
|
serverConfig.GetParameter("fileIndex"),
|
||||||
serverConfig.GetParameter("nodesData"),
|
serverConfig.GetParameter("nodesData"),
|
||||||
serverConfig.GetParameter("namesData"));
|
serverConfig.GetParameter("namesData"));
|
||||||
|
|
||||||
|
BasePlugin * helloWorld = new HelloWorldPlugin();
|
||||||
|
h.RegisterPlugin(helloWorld);
|
||||||
|
|
||||||
|
BasePlugin * locate = new LocatePlugin(objects);
|
||||||
|
h.RegisterPlugin(locate);
|
||||||
|
|
||||||
|
BasePlugin * nearest = new NearestPlugin(objects);
|
||||||
|
h.RegisterPlugin(nearest);
|
||||||
|
|
||||||
|
BasePlugin * route = new RoutePlugin(objects);
|
||||||
h.RegisterPlugin(route);
|
h.RegisterPlugin(route);
|
||||||
|
|
||||||
boost::thread t(boost::bind(&Server::Run, s));
|
boost::thread t(boost::bind(&Server::Run, s));
|
||||||
@ -97,6 +94,7 @@ int main (int argc, char *argv[])
|
|||||||
s->Stop();
|
s->Stop();
|
||||||
t.join();
|
t.join();
|
||||||
delete s;
|
delete s;
|
||||||
|
delete objects;
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
std::cerr << "[fatal error] exception: " << e.what() << std::endl;
|
std::cerr << "[fatal error] exception: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user