refactor input restrictions class

This commit is contained in:
Dennis Luxen 2013-11-13 15:23:44 -05:00
parent 5e279363e4
commit 30b2c1ad61
8 changed files with 281 additions and 215 deletions

View File

@ -73,13 +73,13 @@ struct TurnRestriction {
} }
}; };
struct _RawRestrictionContainer { struct InputRestrictionContainer {
TurnRestriction restriction;
EdgeID fromWay; EdgeID fromWay;
EdgeID toWay; EdgeID toWay;
unsigned viaNode; unsigned viaNode;
TurnRestriction restriction;
_RawRestrictionContainer( InputRestrictionContainer(
EdgeID fromWay, EdgeID fromWay,
EdgeID toWay, EdgeID toWay,
NodeID vn, NodeID vn,
@ -91,7 +91,7 @@ struct _RawRestrictionContainer {
{ {
restriction.viaNode = vn; restriction.viaNode = vn;
} }
_RawRestrictionContainer( InputRestrictionContainer(
bool isOnly = false bool isOnly = false
) : ) :
fromWay(UINT_MAX), fromWay(UINT_MAX),
@ -101,37 +101,45 @@ struct _RawRestrictionContainer {
restriction.flags.isOnly = isOnly; restriction.flags.isOnly = isOnly;
} }
static _RawRestrictionContainer min_value() { static InputRestrictionContainer min_value() {
return _RawRestrictionContainer(0, 0, 0, 0); return InputRestrictionContainer(0, 0, 0, 0);
} }
static _RawRestrictionContainer max_value() { static InputRestrictionContainer max_value() {
return _RawRestrictionContainer(UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX); return InputRestrictionContainer(UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX);
} }
}; };
struct CmpRestrictionContainerByFrom : public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> { struct CmpRestrictionContainerByFrom :
typedef _RawRestrictionContainer value_type; public std::binary_function<InputRestrictionContainer, InputRestrictionContainer, bool>
bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const { {
typedef InputRestrictionContainer value_type;
inline bool operator()(
const InputRestrictionContainer & a,
const InputRestrictionContainer & b
) const {
return a.fromWay < b.fromWay; return a.fromWay < b.fromWay;
} }
value_type max_value() { inline value_type max_value() const {
return _RawRestrictionContainer::max_value(); return InputRestrictionContainer::max_value();
} }
value_type min_value() { inline value_type min_value() const {
return _RawRestrictionContainer::min_value(); return InputRestrictionContainer::min_value();
} }
}; };
struct CmpRestrictionContainerByTo: public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> { struct CmpRestrictionContainerByTo: public std::binary_function<InputRestrictionContainer, InputRestrictionContainer, bool> {
typedef _RawRestrictionContainer value_type; typedef InputRestrictionContainer value_type;
bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const { inline bool operator ()(
const InputRestrictionContainer & a,
const InputRestrictionContainer & b
) const {
return a.toWay < b.toWay; return a.toWay < b.toWay;
} }
value_type max_value() { value_type max_value() const {
return _RawRestrictionContainer::max_value(); return InputRestrictionContainer::max_value();
} }
value_type min_value() { value_type min_value() const {
return _RawRestrictionContainer::min_value(); return InputRestrictionContainer::min_value();
} }
}; };

View File

@ -29,17 +29,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
void ExtractionContainers::PrepareData( void ExtractionContainers::PrepareData(
const std::string & output_file_name, const std::string & output_file_name,
const std::string restrictionsFileName const std::string & restrictions_file_name
) { ) {
try { try {
unsigned usedNodeCounter = 0; unsigned number_of_used_nodes = 0;
unsigned usedEdgeCounter = 0; unsigned number_of_used_edges = 0;
double time = get_timestamp(); double time = get_timestamp();
std::cout << "[extractor] Sorting used nodes ... " << std::flush; std::cout << "[extractor] Sorting used nodes ... " << std::flush;
stxxl::sort( stxxl::sort(
usedNodeIDs.begin(), used_node_id_list.begin(),
usedNodeIDs.end(), used_node_id_list.end(),
Cmp(), Cmp(),
4294967296 4294967296
); );
@ -47,15 +47,15 @@ void ExtractionContainers::PrepareData(
time = get_timestamp(); time = get_timestamp();
std::cout << "[extractor] Erasing duplicate nodes ... " << std::flush; std::cout << "[extractor] Erasing duplicate nodes ... " << std::flush;
stxxl::vector<NodeID>::iterator NewEnd = std::unique ( usedNodeIDs.begin(),usedNodeIDs.end() ) ; stxxl::vector<NodeID>::iterator NewEnd = std::unique ( used_node_id_list.begin(),used_node_id_list.end() ) ;
usedNodeIDs.resize ( NewEnd - usedNodeIDs.begin() ); used_node_id_list.resize ( NewEnd - used_node_id_list.begin() );
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
time = get_timestamp(); time = get_timestamp();
std::cout << "[extractor] Sorting all nodes ... " << std::flush; std::cout << "[extractor] Sorting all nodes ... " << std::flush;
stxxl::sort( stxxl::sort(
allNodes.begin(), all_nodes_list.begin(),
allNodes.end(), all_nodes_list.end(),
CmpNodeByID(), CmpNodeByID(),
4294967296 4294967296
); );
@ -63,41 +63,55 @@ void ExtractionContainers::PrepareData(
time = get_timestamp(); time = get_timestamp();
std::cout << "[extractor] Sorting used ways ... " << std::flush; std::cout << "[extractor] Sorting used ways ... " << std::flush;
stxxl::sort(wayStartEndVector.begin(), wayStartEndVector.end(), CmpWayByID(), stxxl::sort(
4294967296); way_start_end_id_list.begin(),
way_start_end_id_list.end(),
CmpWayByID(),
4294967296
);
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
std::cout << "[extractor] Sorting restrctns. by from... " << std::flush; std::cout << "[extractor] Sorting restrctns. by from... " << std::flush;
stxxl::sort(restrictionsVector.begin(), restrictionsVector.end(), CmpRestrictionContainerByFrom(), stxxl::sort(
4294967296); restrictions_list.begin(),
restrictions_list.end(),
CmpRestrictionContainerByFrom(),
4294967296
);
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
std::cout << "[extractor] Fixing restriction starts ... " << std::flush; std::cout << "[extractor] Fixing restriction starts ... " << std::flush;
STXXLRestrictionsVector::iterator restrictionsIT = restrictionsVector.begin(); STXXLRestrictionsVector::iterator restrictions_iterator = restrictions_list.begin();
STXXLWayIDStartEndVector::iterator wayStartAndEndEdgeIT = wayStartEndVector.begin(); STXXLWayIDStartEndVector::iterator way_start_and_end_iterator = way_start_end_id_list.begin();
while(wayStartAndEndEdgeIT != wayStartEndVector.end() && restrictionsIT != restrictionsVector.end()) { while(
if(wayStartAndEndEdgeIT->wayID < restrictionsIT->fromWay){ way_start_and_end_iterator != way_start_end_id_list.end() &&
++wayStartAndEndEdgeIT; restrictions_iterator != restrictions_list.end()
) {
if(way_start_and_end_iterator->wayID < restrictions_iterator->fromWay){
++way_start_and_end_iterator;
continue; continue;
} }
if(wayStartAndEndEdgeIT->wayID > restrictionsIT->fromWay) {
++restrictionsIT; if(way_start_and_end_iterator->wayID > restrictions_iterator->fromWay) {
++restrictions_iterator;
continue; continue;
} }
assert(wayStartAndEndEdgeIT->wayID == restrictionsIT->fromWay);
NodeID viaNode = restrictionsIT->restriction.viaNode;
if(wayStartAndEndEdgeIT->firstStart == viaNode) { BOOST_ASSERT(way_start_and_end_iterator->wayID == restrictions_iterator->fromWay);
restrictionsIT->restriction.fromNode = wayStartAndEndEdgeIT->firstTarget; NodeID via_node_id = restrictions_iterator->restriction.viaNode;
} else if(wayStartAndEndEdgeIT->firstTarget == viaNode) {
restrictionsIT->restriction.fromNode = wayStartAndEndEdgeIT->firstStart; if(way_start_and_end_iterator->firstStart == via_node_id) {
} else if(wayStartAndEndEdgeIT->lastStart == viaNode) { restrictions_iterator->restriction.fromNode = way_start_and_end_iterator->firstTarget;
restrictionsIT->restriction.fromNode = wayStartAndEndEdgeIT->lastTarget; } else if(way_start_and_end_iterator->firstTarget == via_node_id) {
} else if(wayStartAndEndEdgeIT->lastTarget == viaNode) { restrictions_iterator->restriction.fromNode = way_start_and_end_iterator->firstStart;
restrictionsIT->restriction.fromNode = wayStartAndEndEdgeIT->lastStart; } else if(way_start_and_end_iterator->lastStart == via_node_id) {
restrictions_iterator->restriction.fromNode = way_start_and_end_iterator->lastTarget;
} else if(way_start_and_end_iterator->lastTarget == via_node_id) {
restrictions_iterator->restriction.fromNode = way_start_and_end_iterator->lastStart;
} }
++restrictionsIT; ++restrictions_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
@ -105,8 +119,8 @@ void ExtractionContainers::PrepareData(
std::cout << "[extractor] Sorting restrctns. by to ... " << std::flush; std::cout << "[extractor] Sorting restrctns. by to ... " << std::flush;
stxxl::sort( stxxl::sort(
restrictionsVector.begin(), restrictions_list.begin(),
restrictionsVector.end(), restrictions_list.end(),
CmpRestrictionContainerByTo(), CmpRestrictionContainerByTo(),
4294967296 4294967296
); );
@ -115,93 +129,107 @@ void ExtractionContainers::PrepareData(
time = get_timestamp(); time = get_timestamp();
unsigned usableRestrictionsCounter(0); unsigned usableRestrictionsCounter(0);
std::cout << "[extractor] Fixing restriction ends ... " << std::flush; std::cout << "[extractor] Fixing restriction ends ... " << std::flush;
restrictionsIT = restrictionsVector.begin(); restrictions_iterator = restrictions_list.begin();
wayStartAndEndEdgeIT = wayStartEndVector.begin(); way_start_and_end_iterator = way_start_end_id_list.begin();
while(wayStartAndEndEdgeIT != wayStartEndVector.end() && restrictionsIT != restrictionsVector.end()) { while(
if(wayStartAndEndEdgeIT->wayID < restrictionsIT->toWay){ way_start_and_end_iterator != way_start_end_id_list.end() &&
++wayStartAndEndEdgeIT; restrictions_iterator != restrictions_list.end()
) {
if(way_start_and_end_iterator->wayID < restrictions_iterator->toWay){
++way_start_and_end_iterator;
continue; continue;
} }
if(wayStartAndEndEdgeIT->wayID > restrictionsIT->toWay) { if(way_start_and_end_iterator->wayID > restrictions_iterator->toWay) {
++restrictionsIT; ++restrictions_iterator;
continue; continue;
} }
NodeID viaNode = restrictionsIT->restriction.viaNode; NodeID via_node_id = restrictions_iterator->restriction.viaNode;
if(wayStartAndEndEdgeIT->lastStart == viaNode) { if(way_start_and_end_iterator->lastStart == via_node_id) {
restrictionsIT->restriction.toNode = wayStartAndEndEdgeIT->lastTarget; restrictions_iterator->restriction.toNode = way_start_and_end_iterator->lastTarget;
} else if(wayStartAndEndEdgeIT->lastTarget == viaNode) { } else if(way_start_and_end_iterator->lastTarget == via_node_id) {
restrictionsIT->restriction.toNode = wayStartAndEndEdgeIT->lastStart; restrictions_iterator->restriction.toNode = way_start_and_end_iterator->lastStart;
} else if(wayStartAndEndEdgeIT->firstStart == viaNode) { } else if(way_start_and_end_iterator->firstStart == via_node_id) {
restrictionsIT->restriction.toNode = wayStartAndEndEdgeIT->firstTarget; restrictions_iterator->restriction.toNode = way_start_and_end_iterator->firstTarget;
} else if(wayStartAndEndEdgeIT->firstTarget == viaNode) { } else if(way_start_and_end_iterator->firstTarget == via_node_id) {
restrictionsIT->restriction.toNode = wayStartAndEndEdgeIT->firstStart; restrictions_iterator->restriction.toNode = way_start_and_end_iterator->firstStart;
} }
if( if(
UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictions_iterator->restriction.fromNode &&
UINT_MAX != restrictionsIT->restriction.toNode UINT_MAX != restrictions_iterator->restriction.toNode
) { ) {
++usableRestrictionsCounter; ++usableRestrictionsCounter;
} }
++restrictionsIT; ++restrictions_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
SimpleLogger().Write() << "usable restrictions: " << usableRestrictionsCounter; SimpleLogger().Write() << "usable restrictions: " << usableRestrictionsCounter;
//serialize restrictions //serialize restrictions
std::ofstream restrictions_out_stream; std::ofstream restrictions_out_stream;
restrictions_out_stream.open(restrictionsFileName.c_str(), std::ios::binary); restrictions_out_stream.open(restrictions_file_name.c_str(), std::ios::binary);
restrictions_out_stream.write((char*)&uuid, sizeof(UUID)); restrictions_out_stream.write((char*)&uuid, sizeof(UUID));
restrictions_out_stream.write((char*)&usableRestrictionsCounter, sizeof(unsigned)); restrictions_out_stream.write(
(char*)&usableRestrictionsCounter,
sizeof(unsigned)
);
for( for(
restrictionsIT = restrictionsVector.begin(); restrictions_iterator = restrictions_list.begin();
restrictionsIT != restrictionsVector.end(); restrictions_iterator != restrictions_list.end();
++restrictionsIT ++restrictions_iterator
) { ) {
if( if(
UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictions_iterator->restriction.fromNode &&
UINT_MAX != restrictionsIT->restriction.toNode UINT_MAX != restrictions_iterator->restriction.toNode
) { ) {
restrictions_out_stream.write( restrictions_out_stream.write(
(char *)&(restrictionsIT->restriction), (char *)&(restrictions_iterator->restriction),
sizeof(TurnRestriction) sizeof(TurnRestriction)
); );
} }
} }
restrictions_out_stream.close(); restrictions_out_stream.close();
std::ofstream fout; std::ofstream file_out_stream;
fout.open(output_file_name.c_str(), std::ios::binary); file_out_stream.open(output_file_name.c_str(), std::ios::binary);
fout.write((char*)&uuid, sizeof(UUID)); file_out_stream.write((char*)&uuid, sizeof(UUID));
fout.write((char*)&usedNodeCounter, sizeof(unsigned)); file_out_stream.write((char*)&number_of_used_nodes, sizeof(unsigned));
time = get_timestamp(); time = get_timestamp();
std::cout << "[extractor] Confirming/Writing used nodes ... " << std::flush; std::cout << "[extractor] Confirming/Writing used nodes ... " << std::flush;
STXXLNodeVector::iterator nodesIT = allNodes.begin(); //identify all used nodes by a merging step of two sorted lists
STXXLNodeIDVector::iterator usedNodeIDsIT = usedNodeIDs.begin(); STXXLNodeVector::iterator node_iterator = all_nodes_list.begin();
while(usedNodeIDsIT != usedNodeIDs.end() && nodesIT != allNodes.end()) { STXXLNodeIDVector::iterator node_id_iterator = used_node_id_list.begin();
if(*usedNodeIDsIT < nodesIT->id){ while(
++usedNodeIDsIT; node_id_iterator != used_node_id_list.end() &&
node_iterator != all_nodes_list.end()
) {
if(*node_id_iterator < node_iterator->id){
++node_id_iterator;
continue; continue;
} }
if(*usedNodeIDsIT > nodesIT->id) { if(*node_id_iterator > node_iterator->id) {
++nodesIT; ++node_iterator;
continue; continue;
} }
if(*usedNodeIDsIT == nodesIT->id) { BOOST_ASSERT( *node_id_iterator == node_iterator->id);
fout.write((char*)&(*nodesIT), sizeof(ExternalMemoryNode));
++usedNodeCounter; file_out_stream.write(
++usedNodeIDsIT; (char*)&(*node_iterator),
++nodesIT; sizeof(ExternalMemoryNode)
} );
++number_of_used_nodes;
++node_id_iterator;
++node_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
std::cout << "[extractor] setting number of nodes ... " << std::flush; std::cout << "[extractor] setting number of nodes ... " << std::flush;
std::ios::pos_type positionInFile = fout.tellp(); std::ios::pos_type previous_file_position = file_out_stream.tellp();
fout.seekp(std::ios::beg+sizeof(UUID)); file_out_stream.seekp(std::ios::beg+sizeof(UUID));
fout.write((char*)&usedNodeCounter, sizeof(unsigned)); file_out_stream.write((char*)&number_of_used_nodes, sizeof(unsigned));
fout.seekp(positionInFile); file_out_stream.seekp(previous_file_position);
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;
time = get_timestamp(); time = get_timestamp();
@ -209,8 +237,8 @@ void ExtractionContainers::PrepareData(
// Sort edges by start. // Sort edges by start.
std::cout << "[extractor] Sorting edges by start ... " << std::flush; std::cout << "[extractor] Sorting edges by start ... " << std::flush;
stxxl::sort( stxxl::sort(
allEdges.begin(), all_edges_list.begin(),
allEdges.end(), all_edges_list.end(),
CmpEdgeByStartID(), CmpEdgeByStartID(),
4294967296 4294967296
); );
@ -218,24 +246,27 @@ void ExtractionContainers::PrepareData(
time = get_timestamp(); time = get_timestamp();
std::cout << "[extractor] Setting start coords ... " << std::flush; std::cout << "[extractor] Setting start coords ... " << std::flush;
fout.write((char*)&usedEdgeCounter, sizeof(unsigned)); file_out_stream.write((char*)&number_of_used_edges, sizeof(unsigned));
// Traverse list of edges and nodes in parallel and set start coord // Traverse list of edges and nodes in parallel and set start coord
nodesIT = allNodes.begin(); node_iterator = all_nodes_list.begin();
STXXLEdgeVector::iterator edgeIT = allEdges.begin(); STXXLEdgeVector::iterator edge_iterator = all_edges_list.begin();
while(edgeIT != allEdges.end() && nodesIT != allNodes.end()) { while(
if(edgeIT->start < nodesIT->id){ edge_iterator != all_edges_list.end() &&
++edgeIT; node_iterator != all_nodes_list.end()
) {
if(edge_iterator->start < node_iterator->id){
++edge_iterator;
continue; continue;
} }
if(edgeIT->start > nodesIT->id) { if(edge_iterator->start > node_iterator->id) {
nodesIT++; node_iterator++;
continue; continue;
} }
if(edgeIT->start == nodesIT->id) {
edgeIT->startCoord.lat = nodesIT->lat; BOOST_ASSERT(edge_iterator->start == node_iterator->id);
edgeIT->startCoord.lon = nodesIT->lon; edge_iterator->startCoord.lat = node_iterator->lat;
++edgeIT; edge_iterator->startCoord.lon = node_iterator->lon;
} ++edge_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
time = get_timestamp(); time = get_timestamp();
@ -243,8 +274,8 @@ void ExtractionContainers::PrepareData(
// Sort Edges by target // Sort Edges by target
std::cout << "[extractor] Sorting edges by target ... " << std::flush; std::cout << "[extractor] Sorting edges by target ... " << std::flush;
stxxl::sort( stxxl::sort(
allEdges.begin(), all_edges_list.begin(),
allEdges.end(), all_edges_list.end(),
CmpEdgeByTargetID(), CmpEdgeByTargetID(),
4294967296 4294967296
); );
@ -253,72 +284,99 @@ void ExtractionContainers::PrepareData(
std::cout << "[extractor] Setting target coords ... " << std::flush; std::cout << "[extractor] Setting target coords ... " << std::flush;
// Traverse list of edges and nodes in parallel and set target coord // Traverse list of edges and nodes in parallel and set target coord
nodesIT = allNodes.begin(); node_iterator = all_nodes_list.begin();
edgeIT = allEdges.begin(); edge_iterator = all_edges_list.begin();
while(edgeIT != allEdges.end() && nodesIT != allNodes.end()) { while(
if(edgeIT->target < nodesIT->id){ edge_iterator != all_edges_list.end() &&
++edgeIT; node_iterator != all_nodes_list.end()
) {
if(edge_iterator->target < node_iterator->id){
++edge_iterator;
continue; continue;
} }
if(edgeIT->target > nodesIT->id) { if(edge_iterator->target > node_iterator->id) {
++nodesIT; ++node_iterator;
continue; continue;
} }
if(edgeIT->target == nodesIT->id) { BOOST_ASSERT(edge_iterator->target == node_iterator->id);
if(edgeIT->startCoord.lat != INT_MIN && edgeIT->startCoord.lon != INT_MIN) { if(edge_iterator->startCoord.lat != INT_MIN && edge_iterator->startCoord.lon != INT_MIN) {
edgeIT->targetCoord.lat = nodesIT->lat; edge_iterator->targetCoord.lat = node_iterator->lat;
edgeIT->targetCoord.lon = nodesIT->lon; edge_iterator->targetCoord.lon = node_iterator->lon;
double distance = ApproximateDistance(edgeIT->startCoord.lat, edgeIT->startCoord.lon, nodesIT->lat, nodesIT->lon); const double distance = ApproximateDistance(
assert(edgeIT->speed != -1); edge_iterator->startCoord.lat,
double weight = ( distance * 10. ) / (edgeIT->speed / 3.6); edge_iterator->startCoord.lon,
int intWeight = std::max(1, (int)std::floor((edgeIT->isDurationSet ? edgeIT->speed : weight)+.5) ); node_iterator->lat,
int intDist = std::max(1, (int)distance); node_iterator->lon
short zero = 0; );
short one = 1;
fout.write((char*)&edgeIT->start, sizeof(unsigned)); BOOST_ASSERT(edge_iterator->speed != -1);
fout.write((char*)&edgeIT->target, sizeof(unsigned)); const double weight = ( distance * 10. ) / (edge_iterator->speed / 3.6);
fout.write((char*)&intDist, sizeof(int)); int integer_weight = std::max( 1, (int)std::floor((edge_iterator->isDurationSet ? edge_iterator->speed : weight)+.5) );
switch(edgeIT->direction) { int integer_distance = std::max( 1, (int)distance );
case ExtractionWay::notSure: short zero = 0;
fout.write((char*)&zero, sizeof(short)); short one = 1;
break;
case ExtractionWay::oneway:
fout.write((char*)&one, sizeof(short));
break;
case ExtractionWay::bidirectional:
fout.write((char*)&zero, sizeof(short));
break; file_out_stream.write((char*)&edge_iterator->start, sizeof(unsigned));
case ExtractionWay::opposite: file_out_stream.write((char*)&edge_iterator->target, sizeof(unsigned));
fout.write((char*)&one, sizeof(short)); file_out_stream.write((char*)&integer_distance, sizeof(int));
break; switch(edge_iterator->direction) {
default: case ExtractionWay::notSure:
std::cerr << "[error] edge with no direction: " << edgeIT->direction << std::endl; file_out_stream.write((char*)&zero, sizeof(short));
assert(false); break;
break; case ExtractionWay::oneway:
} file_out_stream.write((char*)&one, sizeof(short));
fout.write((char*)&intWeight, sizeof(int)); break;
assert(edgeIT->type >= 0); case ExtractionWay::bidirectional:
fout.write((char*)&edgeIT->type, sizeof(short)); file_out_stream.write((char*)&zero, sizeof(short));
fout.write((char*)&edgeIT->nameID, sizeof(unsigned));
fout.write((char*)&edgeIT->isRoundabout, sizeof(bool)); break;
fout.write((char*)&edgeIT->ignoreInGrid, sizeof(bool)); case ExtractionWay::opposite:
fout.write((char*)&edgeIT->isAccessRestricted, sizeof(bool)); file_out_stream.write((char*)&one, sizeof(short));
fout.write((char*)&edgeIT->isContraFlow, sizeof(bool)); break;
++usedEdgeCounter; default:
throw OSRMException("edge has broken direction");
break;
} }
++edgeIT; file_out_stream.write(
(char*)&integer_weight, sizeof(int)
);
BOOST_ASSERT(edge_iterator->type >= 0);
file_out_stream.write(
(char*)&edge_iterator->type,
sizeof(short)
);
file_out_stream.write(
(char*)&edge_iterator->nameID,
sizeof(unsigned)
);
file_out_stream.write(
(char*)&edge_iterator->isRoundabout,
sizeof(bool)
);
file_out_stream.write(
(char*)&edge_iterator->ignoreInGrid,
sizeof(bool)
);
file_out_stream.write(
(char*)&edge_iterator->isAccessRestricted,
sizeof(bool)
);
file_out_stream.write(
(char*)&edge_iterator->isContraFlow,
sizeof(bool)
);
++number_of_used_edges;
} }
++edge_iterator;
} }
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
std::cout << "[extractor] setting number of edges ... " << std::flush; std::cout << "[extractor] setting number of edges ... " << std::flush;
fout.seekp(positionInFile); file_out_stream.seekp(previous_file_position);
fout.write((char*)&usedEdgeCounter, sizeof(unsigned)); file_out_stream.write((char*)&number_of_used_edges, sizeof(unsigned));
fout.close(); file_out_stream.close();
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;
time = get_timestamp(); time = get_timestamp();
@ -335,8 +393,8 @@ void ExtractionContainers::PrepareData(
//compute total number of chars //compute total number of chars
unsigned total_number_of_chars = 0; unsigned total_number_of_chars = 0;
BOOST_FOREACH(const std::string & str, name_list) { BOOST_FOREACH(const std::string & temp_string, name_list) {
total_number_of_chars += strlen(str.c_str()); total_number_of_chars += temp_string.length();
} }
//write total number of chars //write total number of chars
name_file_stream.write( name_file_stream.write(
@ -345,12 +403,12 @@ void ExtractionContainers::PrepareData(
); );
//write prefixe sums //write prefixe sums
unsigned name_lengths_prefix_sum = 0; unsigned name_lengths_prefix_sum = 0;
BOOST_FOREACH(const std::string & str, name_list) { BOOST_FOREACH(const std::string & temp_string, name_list) {
name_file_stream.write( name_file_stream.write(
(char *)&(name_lengths_prefix_sum), (char *)&(name_lengths_prefix_sum),
sizeof(unsigned) sizeof(unsigned)
); );
name_lengths_prefix_sum += strlen(str.c_str()); name_lengths_prefix_sum += temp_string.length();
} }
//duplicate on purpose! //duplicate on purpose!
name_file_stream.write( name_file_stream.write(
@ -359,16 +417,16 @@ void ExtractionContainers::PrepareData(
); );
//write all chars consecutively //write all chars consecutively
BOOST_FOREACH(const std::string & str, name_list) { BOOST_FOREACH(const std::string & temp_string, name_list) {
const unsigned lengthOfRawString = strlen(str.c_str()); const unsigned string_length = temp_string.length();
name_file_stream.write(str.c_str(), lengthOfRawString); name_file_stream.write(temp_string.c_str(), string_length);
} }
name_file_stream.close(); name_file_stream.close();
std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl; std::cout << "ok, after " << get_timestamp() - time << "s" << std::endl;
SimpleLogger().Write() << SimpleLogger().Write() << "Processed " <<
"Processed " << usedNodeCounter << " nodes and " << usedEdgeCounter << " edges"; number_of_used_nodes << " nodes and " <<
number_of_used_edges << " edges";
} catch ( const std::exception& e ) { } catch ( const std::exception& e ) {
std::cerr << "Caught Execption:" << e.what() << std::endl; std::cerr << "Caught Execption:" << e.what() << std::endl;

View File

@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../Util/TimingUtil.h" #include "../Util/TimingUtil.h"
#include "../Util/UUID.h" #include "../Util/UUID.h"
#include <boost/assert.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -42,20 +43,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class ExtractionContainers { class ExtractionContainers {
public: public:
typedef stxxl::vector<NodeID> STXXLNodeIDVector; typedef stxxl::vector<NodeID> STXXLNodeIDVector;
typedef stxxl::vector<ExternalMemoryNode> STXXLNodeVector; typedef stxxl::vector<ExternalMemoryNode> STXXLNodeVector;
typedef stxxl::vector<InternalExtractorEdge> STXXLEdgeVector; typedef stxxl::vector<InternalExtractorEdge> STXXLEdgeVector;
typedef stxxl::vector<std::string> STXXLStringVector; typedef stxxl::vector<std::string> STXXLStringVector;
typedef stxxl::vector<_RawRestrictionContainer> STXXLRestrictionsVector; typedef stxxl::vector<InputRestrictionContainer> STXXLRestrictionsVector;
typedef stxxl::vector<_WayIDStartAndEndEdge> STXXLWayIDStartEndVector; typedef stxxl::vector<_WayIDStartAndEndEdge> STXXLWayIDStartEndVector;
STXXLNodeIDVector used_node_id_list;
STXXLNodeIDVector usedNodeIDs; STXXLNodeVector all_nodes_list;
STXXLNodeVector allNodes; STXXLEdgeVector all_edges_list;
STXXLEdgeVector allEdges;
STXXLStringVector name_list; STXXLStringVector name_list;
STXXLRestrictionsVector restrictionsVector; STXXLRestrictionsVector restrictions_list;
STXXLWayIDStartEndVector wayStartEndVector; STXXLWayIDStartEndVector way_start_end_id_list;
const UUID uuid; const UUID uuid;
ExtractionContainers() { ExtractionContainers() {
@ -65,17 +65,17 @@ public:
} }
virtual ~ExtractionContainers() { virtual ~ExtractionContainers() {
usedNodeIDs.clear(); used_node_id_list.clear();
allNodes.clear(); all_nodes_list.clear();
allEdges.clear(); all_edges_list.clear();
name_list.clear(); name_list.clear();
restrictionsVector.clear(); restrictions_list.clear();
wayStartEndVector.clear(); way_start_end_id_list.clear();
} }
void PrepareData( void PrepareData(
const std::string & output_file_name, const std::string & output_file_name,
const std::string restrictionsFileName const std::string & restrictions_file_name
); );
}; };

View File

@ -38,12 +38,12 @@ ExtractorCallbacks::~ExtractorCallbacks() { }
/** warning: caller needs to take care of synchronization! */ /** warning: caller needs to take care of synchronization! */
void ExtractorCallbacks::nodeFunction(const ExternalMemoryNode &n) { void ExtractorCallbacks::nodeFunction(const ExternalMemoryNode &n) {
if(n.lat <= 85*COORDINATE_PRECISION && n.lat >= -85*COORDINATE_PRECISION) { if(n.lat <= 85*COORDINATE_PRECISION && n.lat >= -85*COORDINATE_PRECISION) {
externalMemory->allNodes.push_back(n); externalMemory->all_nodes_list.push_back(n);
} }
} }
bool ExtractorCallbacks::restrictionFunction(const _RawRestrictionContainer &r) { bool ExtractorCallbacks::restrictionFunction(const InputRestrictionContainer &r) {
externalMemory->restrictionsVector.push_back(r); externalMemory->restrictions_list.push_back(r);
return true; return true;
} }
@ -86,7 +86,7 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) {
const bool split_bidirectional_edge = (parsed_way.backward_speed > 0) && (parsed_way.speed != parsed_way.backward_speed); const bool split_bidirectional_edge = (parsed_way.backward_speed > 0) && (parsed_way.speed != parsed_way.backward_speed);
for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) { for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) {
externalMemory->allEdges.push_back( externalMemory->all_edges_list.push_back(
InternalExtractorEdge(parsed_way.path[n], InternalExtractorEdge(parsed_way.path[n],
parsed_way.path[n+1], parsed_way.path[n+1],
parsed_way.type, parsed_way.type,
@ -99,17 +99,17 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) {
parsed_way.isAccessRestricted parsed_way.isAccessRestricted
) )
); );
externalMemory->usedNodeIDs.push_back(parsed_way.path[n]); externalMemory->used_node_id_list.push_back(parsed_way.path[n]);
} }
externalMemory->usedNodeIDs.push_back(parsed_way.path.back()); externalMemory->used_node_id_list.push_back(parsed_way.path.back());
//The following information is needed to identify start and end segments of restrictions //The following information is needed to identify start and end segments of restrictions
externalMemory->wayStartEndVector.push_back(_WayIDStartAndEndEdge(parsed_way.id, parsed_way.path[0], parsed_way.path[1], parsed_way.path[parsed_way.path.size()-2], parsed_way.path.back())); externalMemory->way_start_end_id_list.push_back(_WayIDStartAndEndEdge(parsed_way.id, parsed_way.path[0], parsed_way.path[1], parsed_way.path[parsed_way.path.size()-2], parsed_way.path.back()));
if(split_bidirectional_edge) { //Only true if the way should be split if(split_bidirectional_edge) { //Only true if the way should be split
std::reverse( parsed_way.path.begin(), parsed_way.path.end() ); std::reverse( parsed_way.path.begin(), parsed_way.path.end() );
for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) { for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) {
externalMemory->allEdges.push_back( externalMemory->all_edges_list.push_back(
InternalExtractorEdge(parsed_way.path[n], InternalExtractorEdge(parsed_way.path[n],
parsed_way.path[n+1], parsed_way.path[n+1],
parsed_way.type, parsed_way.type,
@ -124,7 +124,7 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) {
) )
); );
} }
externalMemory->wayStartEndVector.push_back(_WayIDStartAndEndEdge(parsed_way.id, parsed_way.path[0], parsed_way.path[1], parsed_way.path[parsed_way.path.size()-2], parsed_way.path.back())); externalMemory->way_start_end_id_list.push_back(_WayIDStartAndEndEdge(parsed_way.id, parsed_way.path[0], parsed_way.path[1], parsed_way.path[parsed_way.path.size()-2], parsed_way.path.back()));
} }
} }
} }

View File

@ -57,7 +57,7 @@ public:
/** warning: caller needs to take care of synchronization! */ /** warning: caller needs to take care of synchronization! */
void nodeFunction(const ExternalMemoryNode &n); void nodeFunction(const ExternalMemoryNode &n);
bool restrictionFunction(const _RawRestrictionContainer &r); bool restrictionFunction(const InputRestrictionContainer &r);
/** warning: caller needs to take care of synchronization! */ /** warning: caller needs to take care of synchronization! */
void wayFunction(ExtractionWay &w); void wayFunction(ExtractionWay &w);

View File

@ -248,7 +248,7 @@ inline void PBFParser::parseRelation(_ThreadData * threadData) {
if(isRestriction) { if(isRestriction) {
int64_t lastRef = 0; int64_t lastRef = 0;
_RawRestrictionContainer currentRestrictionContainer(isOnlyRestriction); InputRestrictionContainer currentRestrictionContainer(isOnlyRestriction);
for( for(
int rolesIndex = 0, last_role = inputRelation.roles_sid_size(); int rolesIndex = 0, last_role = inputRelation.roles_sid_size();
rolesIndex < last_role; rolesIndex < last_role;

View File

@ -74,7 +74,7 @@ bool XMLParser::Parse() {
} }
if( use_turn_restrictions ) { if( use_turn_restrictions ) {
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) { if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
_RawRestrictionContainer r = _ReadXMLRestriction(); InputRestrictionContainer r = _ReadXMLRestriction();
if(r.fromWay != UINT_MAX) { if(r.fromWay != UINT_MAX) {
if(!extractor_callbacks->restrictionFunction(r)) { if(!extractor_callbacks->restrictionFunction(r)) {
std::cerr << "[XMLParser] restriction not parsed" << std::endl; std::cerr << "[XMLParser] restriction not parsed" << std::endl;
@ -87,8 +87,8 @@ bool XMLParser::Parse() {
return true; return true;
} }
_RawRestrictionContainer XMLParser::_ReadXMLRestriction() { InputRestrictionContainer XMLParser::_ReadXMLRestriction() {
_RawRestrictionContainer restriction; InputRestrictionContainer restriction;
std::string except_tag_string; std::string except_tag_string;
if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) { if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) {

View File

@ -44,7 +44,7 @@ public:
bool Parse(); bool Parse();
private: private:
_RawRestrictionContainer _ReadXMLRestriction(); InputRestrictionContainer _ReadXMLRestriction();
ExtractionWay _ReadXMLWay(); ExtractionWay _ReadXMLWay();
ImportNode _ReadXMLNode(); ImportNode _ReadXMLNode();
xmlTextReaderPtr inputReader; xmlTextReaderPtr inputReader;