Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distance tables and JSON generator #1030

Merged
merged 36 commits into from
May 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
acab77f
add simple isValid() function to PhantomNodes
DennisOSRM May 16, 2014
a80815d
implements output generation through a dedicated JSON container:
DennisOSRM May 16, 2014
2d498cb
adapt JSON parsing in tests to allow for omitted fields
DennisOSRM May 16, 2014
d2f1935
remove some debug output
DennisOSRM May 16, 2014
e36e9fd
make comparsion explicitly unsigned
DennisOSRM May 16, 2014
f4c23f3
fix comparison
DennisOSRM May 16, 2014
a69b353
fix typo
DennisOSRM May 16, 2014
da5eec1
refactor route name extraction into its own class, fix name extraction
DennisOSRM May 18, 2014
ef206eb
clean up code a bit
DennisOSRM May 18, 2014
a47467f
store facade ptr in c'tor, save a param in sub-sequent function calls
DennisOSRM May 18, 2014
8983c0f
move GetBearing(.) function into FixedPointCoordinate
DennisOSRM May 18, 2014
c970cd1
flip bearings by 180
DennisOSRM May 18, 2014
bc951de
use trig functions from std namespace
DennisOSRM May 18, 2014
8fe09c8
move atan2 lookup into trig header
DennisOSRM May 18, 2014
a122a1e
remove comment
DennisOSRM May 18, 2014
75a2d4d
minor code refactoring, wip
DennisOSRM May 18, 2014
d028a30
fixes issue #1019:
DennisOSRM May 19, 2014
e490c4a
use consistent typedef'ed types
DennisOSRM May 19, 2014
0574a60
replace boost::unordered_map, move hash function for pairs into its o…
DennisOSRM May 19, 2014
4fc329a
remove superflous way in test setup
DennisOSRM May 19, 2014
4ec9f2c
fix #1021, always check if files exist
DennisOSRM May 20, 2014
b8acbae
fix #1021, always check if files exist
DennisOSRM May 20, 2014
bf6ca22
fix #1021, always check if files exist
DennisOSRM May 20, 2014
e28e45f
remove unused variable
DennisOSRM May 20, 2014
d53eb88
revert to old boost based regex as GCC does not properly implement it…
DennisOSRM May 20, 2014
69ad3f3
add curly braces to one line if
DennisOSRM May 20, 2014
9a2d701
fix issue #1025:
DennisOSRM May 20, 2014
1802839
add approximator for perpendicular distance
DennisOSRM May 20, 2014
4aa7420
remove unneeded includes
DennisOSRM May 20, 2014
812cf36
use floats instead of doubles for distance computations
DennisOSRM May 20, 2014
9117b45
move more distance calculations to float
DennisOSRM May 21, 2014
6a95418
add a leg to roundabout to remove edge case
DennisOSRM May 21, 2014
c2a750a
use 100 locations at max for dist table
DennisOSRM May 21, 2014
a8ff323
reduce debug verbosity
DennisOSRM May 21, 2014
493b133
move geographical distance computation to floats
DennisOSRM May 21, 2014
35c9021
reduce debug verbosity in RestrictionMap
DennisOSRM May 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions Algorithms/ExtractRouteNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*

Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef EXTRACT_ROUTE_NAMES_H
#define EXTRACT_ROUTE_NAMES_H

#include <boost/assert.hpp>

#include <algorithm>
#include <string>
#include <vector>

struct RouteNames
{
std::string shortest_path_name_1;
std::string shortest_path_name_2;
std::string alternative_path_name_1;
std::string alternative_path_name_2;
};

// construct routes names
template <class DataFacadeT, class SegmentT> struct ExtractRouteNames
{
RouteNames operator()(std::vector<SegmentT> &shortest_path_segments,
std::vector<SegmentT> &alternative_path_segments,
const DataFacadeT *facade)
{
RouteNames route_names;

SegmentT shortest_segment_1, shortest_segment_2;
SegmentT alternative_segment_1, alternative_segment_2;

auto length_comperator = [](SegmentT a, SegmentT b)
{ return a.length > b.length; };
auto name_id_comperator = [](SegmentT a, SegmentT b)
{ return a.name_id < b.name_id; };

if (shortest_path_segments.empty())
{
return route_names;
}

std::sort(shortest_path_segments.begin(), shortest_path_segments.end(), length_comperator);
shortest_segment_1 = shortest_path_segments[0];
if (!alternative_path_segments.empty())
{
std::sort(alternative_path_segments.begin(),
alternative_path_segments.end(),
length_comperator);
alternative_segment_1 = alternative_path_segments[0];
}
std::vector<SegmentT> shortest_path_set_difference(shortest_path_segments.size());
std::vector<SegmentT> alternative_path_set_difference(alternative_path_segments.size());
std::set_difference(shortest_path_segments.begin(),
shortest_path_segments.end(),
alternative_path_segments.begin(),
alternative_path_segments.end(),
shortest_path_set_difference.begin(),
name_id_comperator);
int size_of_difference = shortest_path_set_difference.size();
if (size_of_difference)
{
int i = 0;
while (i < size_of_difference &&
shortest_path_set_difference[i].name_id == shortest_path_segments[0].name_id)
{
++i;
}
if (i < size_of_difference)
{
shortest_segment_2 = shortest_path_set_difference[i];
}
}

std::set_difference(alternative_path_segments.begin(),
alternative_path_segments.end(),
shortest_path_segments.begin(),
shortest_path_segments.end(),
alternative_path_set_difference.begin(),
name_id_comperator);
size_of_difference = alternative_path_set_difference.size();
if (size_of_difference)
{
int i = 0;
while (i < size_of_difference &&
alternative_path_set_difference[i].name_id ==
alternative_path_segments[0].name_id)
{
++i;
}
if (i < size_of_difference)
{
alternative_segment_2 = alternative_path_set_difference[i];
}
}
if (shortest_segment_1.position > shortest_segment_2.position)
{
std::swap(shortest_segment_1, shortest_segment_2);
}
if (alternative_segment_1.position > alternative_segment_2.position)
{
std::swap(alternative_segment_1, alternative_segment_2);
}
route_names.shortest_path_name_1 =
facade->GetEscapedNameForNameID(shortest_segment_1.name_id);
route_names.shortest_path_name_2 =
facade->GetEscapedNameForNameID(shortest_segment_2.name_id);

route_names.alternative_path_name_1 =
facade->GetEscapedNameForNameID(alternative_segment_1.name_id);
route_names.alternative_path_name_2 =
facade->GetEscapedNameForNameID(alternative_segment_2.name_id);

return route_names;
}
};

#endif // EXTRACT_ROUTE_NAMES_H
89 changes: 39 additions & 50 deletions Algorithms/PolylineCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "PolylineCompressor.h"
#include "../Util/StringUtil.h"

//TODO: return vector of start indices for each leg

void PolylineCompressor::encodeVectorSignedNumber(std::vector<int> &numbers, std::string &output)
const
Expand All @@ -39,9 +42,9 @@ void PolylineCompressor::encodeVectorSignedNumber(std::vector<int> &numbers, std
numbers[i] = ~(numbers[i]);
}
}
for (unsigned i = 0; i < end; ++i)
for (const int number: numbers)
{
encodeNumber(numbers[i], output);
encodeNumber(number, output);
}
}

Expand All @@ -66,37 +69,36 @@ void PolylineCompressor::encodeNumber(int number_to_encode, std::string &output)
}
}

void PolylineCompressor::printEncodedString(const std::vector<SegmentInformation> &polyline,
std::string &output) const
JSON::String PolylineCompressor::printEncodedString(const std::vector<SegmentInformation> &polyline) const
{
std::string output;
std::vector<int> delta_numbers;
output += "\"";
if (!polyline.empty())
{
FixedPointCoordinate last_coordinate = polyline[0].location;
delta_numbers.emplace_back(last_coordinate.lat);
delta_numbers.emplace_back(last_coordinate.lon);
for (unsigned i = 1; i < polyline.size(); ++i)
for (const auto & segment : polyline)
{
if (polyline[i].necessary)
if (segment.necessary)
{
int lat_diff = polyline[i].location.lat - last_coordinate.lat;
int lon_diff = polyline[i].location.lon - last_coordinate.lon;
int lat_diff = segment.location.lat - last_coordinate.lat;
int lon_diff = segment.location.lon - last_coordinate.lon;
delta_numbers.emplace_back(lat_diff);
delta_numbers.emplace_back(lon_diff);
last_coordinate = polyline[i].location;
last_coordinate = segment.location;
}
}
encodeVectorSignedNumber(delta_numbers, output);
}
output += "\"";
JSON::String return_value(output);
return return_value;
}

void PolylineCompressor::printEncodedString(const std::vector<FixedPointCoordinate> &polyline,
std::string &output) const
JSON::String PolylineCompressor::printEncodedString(const std::vector<FixedPointCoordinate> &polyline) const
{
std::string output;
std::vector<int> delta_numbers(2 * polyline.size());
output += "\"";
if (!polyline.empty())
{
delta_numbers[0] = polyline[0].lat;
Expand All @@ -110,53 +112,40 @@ void PolylineCompressor::printEncodedString(const std::vector<FixedPointCoordina
}
encodeVectorSignedNumber(delta_numbers, output);
}
output += "\"";
JSON::String return_value(output);
return return_value;
}

void PolylineCompressor::printUnencodedString(const std::vector<FixedPointCoordinate> &polyline,
std::string &output) const

JSON::Array PolylineCompressor::printUnencodedString(const std::vector<FixedPointCoordinate> &polyline) const
{
output += "[";
std::string tmp;
for (unsigned i = 0; i < polyline.size(); i++)
JSON::Array json_geometry_array;
for( const auto & coordinate : polyline)
{
FixedPointCoordinate::convertInternalLatLonToString(polyline[i].lat, tmp);
output += "[";
output += tmp;
FixedPointCoordinate::convertInternalLatLonToString(polyline[i].lon, tmp);
output += ", ";
std::string tmp, output;
FixedPointCoordinate::convertInternalLatLonToString(coordinate.lat, tmp);
output += (tmp + ",");
FixedPointCoordinate::convertInternalLatLonToString(coordinate.lon, tmp);
output += tmp;
output += "]";
if (i < polyline.size() - 1)
{
output += ",";
}
json_geometry_array.values.push_back(output);
}
output += "]";
return json_geometry_array;
}

void PolylineCompressor::printUnencodedString(const std::vector<SegmentInformation> &polyline,
std::string &output) const
JSON::Array PolylineCompressor::printUnencodedString(const std::vector<SegmentInformation> &polyline) const
{
output += "[";
std::string tmp;
for (unsigned i = 0; i < polyline.size(); i++)
JSON::Array json_geometry_array;
for( const auto & segment : polyline)
{
if (!polyline[i].necessary)
{
continue;
}
FixedPointCoordinate::convertInternalLatLonToString(polyline[i].location.lat, tmp);
output += "[";
output += tmp;
FixedPointCoordinate::convertInternalLatLonToString(polyline[i].location.lon, tmp);
output += ", ";
output += tmp;
output += "]";
if (i < polyline.size() - 1)
if (segment.necessary)
{
output += ",";
std::string tmp, output;
FixedPointCoordinate::convertInternalLatLonToString(segment.location.lat, tmp);
output += (tmp + ",");
FixedPointCoordinate::convertInternalLatLonToString(segment.location.lon, tmp);
output += tmp;
json_geometry_array.values.push_back(output);
}
}
output += "]";
return json_geometry_array;
}
14 changes: 5 additions & 9 deletions Algorithms/PolylineCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef POLYLINECOMPRESSOR_H_
#define POLYLINECOMPRESSOR_H_

#include "../DataStructures/JSONContainer.h"
#include "../DataStructures/SegmentInformation.h"
#include "../Util/StringUtil.h"

#include <string>
#include <vector>
Expand All @@ -42,17 +42,13 @@ class PolylineCompressor
void encodeNumber(int number_to_encode, std::string &output) const;

public:
void printEncodedString(const std::vector<SegmentInformation> &polyline,
std::string &output) const;
JSON::String printEncodedString(const std::vector<SegmentInformation> &polyline) const;

void printEncodedString(const std::vector<FixedPointCoordinate> &polyline,
std::string &output) const;
JSON::String printEncodedString(const std::vector<FixedPointCoordinate> &polyline) const;

void printUnencodedString(const std::vector<FixedPointCoordinate> &polyline,
std::string &output) const;
JSON::Array printUnencodedString(const std::vector<FixedPointCoordinate> &polyline) const;

void printUnencodedString(const std::vector<SegmentInformation> &polyline,
std::string &output) const;
JSON::Array printUnencodedString(const std::vector<SegmentInformation> &polyline) const;
};

#endif /* POLYLINECOMPRESSOR_H_ */
31 changes: 12 additions & 19 deletions Algorithms/StronglyConnectedComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../DataStructures/TurnInstructions.h"

#include "../Util/SimpleLogger.h"
#include "../Util/StdHashExtensions.h"

#include <osrm/Coordinate.h>

Expand All @@ -60,17 +61,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unordered_set>
#include <vector>

namespace std
{
template <> struct hash<std::pair<NodeID, NodeID>>
{
size_t operator()(const std::pair<NodeID, NodeID> &pair) const
{
return std::hash<int>()(pair.first) ^ std::hash<int>()(pair.second);
}
};
}

class TarjanSCC
{
private:
Expand Down Expand Up @@ -339,14 +329,17 @@ class TarjanSCC
<< " many components, marking small components";

// TODO/C++11: prime candidate for lambda function
unsigned size_one_counter = 0;
for (unsigned i = 0, end = component_size_vector.size(); i < end; ++i)
{
if (1 == component_size_vector[i])
{
++size_one_counter;
}
}
// unsigned size_one_counter = 0;
// for (unsigned i = 0, end = component_size_vector.size(); i < end; ++i)
// {
// if (1 == component_size_vector[i])
// {
// ++size_one_counter;
// }
// }
unsigned size_one_counter = std::count_if(component_size_vector.begin(),
component_size_vector.end(),
[] (unsigned value) { return 1 == value;});

SimpleLogger().Write() << "identified " << size_one_counter << " SCCs of size 1";

Expand Down
8 changes: 7 additions & 1 deletion Contractor/EdgeBasedGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ void EdgeBasedGraphFactory::CompressGeometry()
continue;
}

// check if v is a via node for a turn restriction, i.e. a 'directed' barrier node
if (m_restriction_map->IsNodeAViaNode(v))
{
continue;
}

const bool reverse_edge_order =
!(m_node_based_graph->GetEdgeData(m_node_based_graph->BeginEdges(v)).forward);
const EdgeID forward_e2 = m_node_based_graph->BeginEdges(v) + reverse_edge_order;
Expand Down Expand Up @@ -722,7 +728,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u,
if (data1.roundabout && data2.roundabout)
{
// Is a turn possible? If yes, we stay on the roundabout!
if (1 == m_node_based_graph->GetOutDegree(v))
if (1 == m_node_based_graph->GetDirectedOutDegree(v))
{
// No turn possible.
return TurnInstruction::NoTurn;
Expand Down
Loading