This is a large update that brings many internal and architectural changes. The most obvious change to the user is the presence of configuration files for extractLargeNetwork and routed. Optimistically speaking, it should not break anything. Thanks to rskr for support patches and suggestions.

This commit is contained in:
Dennis Luxen
2011-01-09 21:42:27 +00:00
parent f45af2ba72
commit bfd2a8aee2
34 changed files with 2214 additions and 1655 deletions
+68
View File
@@ -0,0 +1,68 @@
/*
* BaseConfiguration.h
*
* Created on: 26.11.2010
* Author: dennis
*/
#ifndef BASECONFIGURATION_H_
#define BASECONFIGURATION_H_
#include <iostream>
#include <string>
#include <set>
#include <sstream>
#include <exception>
#include <fstream>
#include <boost/config.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include "../DataStructures/HashTable.h"
class BaseConfiguration {
public:
BaseConfiguration(const char * configFile) {
std::ifstream config( configFile );
if(!config) {
std::cerr << "[config] .ini not found" << std::endl;
return;
}
//parameters
options.insert("*");
try {
for (boost::program_options::detail::config_file_iterator i(config, options), e ; i != e; ++i) {
std::cout << "[config] " << i->string_key << " = " << i->value[0] << std::endl;
parameters.Add(i->string_key, i->value[0]);
}
} catch(std::exception& e) {
std::cerr << "[config] .ini not found -> Exception: " <<e.what() << std::endl;
}
}
std::string GetParameter(const char * key){
return GetParameter(std::string(key));
}
std::string GetParameter(std::string key) {
return parameters.Find(key);
}
void SetParameter(const char* key, const char* value) {
SetParameter(std::string(key), std::string(value));
}
void SetParameter(std::string key, std::string value) {
parameters.Set(key, value);
}
private:
std::set<std::string> options;
HashTable<std::string, std::string> parameters;
//Speichert alle Einträge aus INI Datei
};
#endif /* BASECONFIGURATION_H_ */
+142
View File
@@ -0,0 +1,142 @@
/*
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 CREATEGRAPH_H
#define GRAPHLOADER_H
#include <cassert>
#include <cmath>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <google/dense_hash_map>
#ifdef _GLIBCXX_PARALLEL
#include <parallel/algorithm>
#else
#include <algorithm>
#endif
#include "../DataStructures/ImportEdge.h"
#include "../typedefs.h"
typedef google::dense_hash_map<NodeID, NodeID> ExternalNodeMap;
template<typename EdgeT>
NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) {
NodeID n, source, target, id;
EdgeID m;
short locatable;
int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap;
ext2IntNodeMap.set_empty_key(UINT_MAX);
in >> n;
VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;)
for (NodeID i=0; i<n;i++) {
in >> id >> ycoord >> xcoord;
int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id));
ext2IntNodeMap.insert(make_pair(id, i));
}
in >> m;
VERBOSE(cout << " and " << m << " edges ..." << flush;)
edgeList.reserve(m);
for (EdgeID i=0; i<m; i++) {
EdgeWeight weight;
short type;
NodeID nameID;
int length;
in >> source >> target >> length >> dir >> weight >> type >> nameID;
assert(length > 0);
assert(weight > 0);
assert(0<=dir && dir<=2);
bool forward = true;
bool backward = true;
if (dir == 1) backward = false;
if (dir == 2) forward = false;
if(length == 0)
{ cerr << "loaded null length edge" << endl; exit(1); }
// translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end())
{
cerr << "after " << edgeList.size() << " edges" << endl;
cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl;
cerr << "unresolved source NodeID: " << source << endl; exit(0);
}
source = intNodeID->second;
intNodeID = ext2IntNodeMap.find(target);
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { cerr << "unresolved target NodeID : " << target << endl; exit(0); }
target = intNodeID->second;
if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); }
EdgeT inputEdge(source, target, nameID, weight, forward, backward, type );
edgeList.push_back(inputEdge);
}
ext2IntNodeMap.clear();
vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
cout << "ok" << endl;
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;
bool forwardTurn;
bool backwardTurn;
short type;
NodeID middle;
NodeID source;
NodeID target;
in.read((char *)&(distance), sizeof(int));
assert(distance > 0);
in.read((char *)&(forwardTurn), sizeof(bool));
in.read((char *)&(backwardTurn), sizeof(bool));
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 *)&(type), sizeof(short));
in.read((char *)&(source), sizeof(NodeID));
in.read((char *)&(target), sizeof(NodeID));
e.backward = backward; e.distance = distance; e.forward = forward; e.middleName.middle = middle; e.shortcut = shortcut; e.type = type;
e.forwardTurn = forwardTurn; e.backwardTurn = backwardTurn;
g.data = e; g.source = source; g.target = target;
edgeList->push_back(g);
}
}
#endif // CREATEGRAPH_H
+43
View File
@@ -0,0 +1,43 @@
/*
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 INPUTFILEUTIL_H_
#define INPUTFILEUTIL_H_
#include <fstream>
// Check if file exists and if it can be opened for reading with ifstream an object
bool testDataFile(const char *filename){
std::ifstream in(filename, std::ios::binary);
if(in.fail()) {
std::cerr << "[error] Failed to open file " << filename << " for reading." << std::endl;
return false;
}
return true;
}
bool testDataFiles(int argc, char *argv[]){
for(int i = 0; i < argc; ++i) {
if(testDataFile(argv[i])==false)
return false;
}
return true;
}
#endif /* INPUTFILEUTIL_H_ */
+82
View File
@@ -0,0 +1,82 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, 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 STRINGUTIL_H_
#define STRINGUTIL_H_
// precision: position after decimal point
// length: maximum number of digits including comma and decimals
template< int length, int precision >
inline char* printInt( char* buffer, int value )
{
bool minus = false;
if ( value < 0 ) {
minus = true;
value = -value;
}
buffer += length - 1;
for ( int i = 0; i < precision; i++ ) {
*buffer = '0' + ( value % 10 );
value /= 10;
buffer--;
}
*buffer = '.';
buffer--;
for ( int i = precision + 1; i < length; i++ ) {
*buffer = '0' + ( value % 10 );
value /= 10;
if ( value == 0 ) break;
buffer--;
}
if ( minus ) {
buffer--;
*buffer = '-';
}
return buffer;
}
inline void intToString(const int value, std::string & output)
{
// The largest 32-bit integer is 4294967295, that is 10 chars
// On the safe side, add 1 for sign, and 1 for trailing zero
char buffer[12] ;
sprintf(buffer, "%i", value) ;
output = buffer ;
}
inline void convertLatLon(const int value, std::string & output)
{
char buffer[100];
buffer[10] = 0; // Nullterminierung
char* string = printInt< 10, 5 >( buffer, value );
output = string;
}
/* used to be boosts lexical cast, but this was too slow */
inline void doubleToString(const double value, std::string & output)
{
// The largest 32-bit integer is 4294967295, that is 10 chars
// On the safe side, add 1 for sign, and 1 for trailing zero
char buffer[12] ;
sprintf(buffer, "%f", value) ;
output = buffer ;
}
#endif /* STRINGUTIL_H_ */