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 new JSON generator #1029

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
faf9c96
fix regression in debug build
DennisOSRM May 12, 2014
4f37270
Simple fix that improves runtime of edge based egde generation by 26%
TheMarex May 12, 2014
529997d
Add atan based on lookup table. Again 6% improvement.
TheMarex May 13, 2014
37dd05a
Merge branch 'TheMarex-atan-perf' into develop
DennisOSRM May 13, 2014
1816e66
remove boost::thread from Server
DennisOSRM May 13, 2014
c6a07ac
use std::packaged_task and std::future to simulate boost::thread::tim…
DennisOSRM May 13, 2014
2164564
minor reformatting
DennisOSRM May 13, 2014
2720f4d
add parantheses to fix compiler warning
DennisOSRM May 13, 2014
111dea8
use std::abs instead of hand-rolled substitute
DennisOSRM May 13, 2014
981941e
leave early to reduce scope nesting
DennisOSRM May 13, 2014
b2adb22
remove whitespace
DennisOSRM May 13, 2014
9b68821
move common code into its own header
DennisOSRM May 13, 2014
e769821
use range based for loops to traverse graphs
DennisOSRM May 13, 2014
9a28bdb
reorder some includes
DennisOSRM May 14, 2014
3ae1776
rename variables
DennisOSRM May 14, 2014
3968349
deactivate LTO on debug build
DennisOSRM May 16, 2014
bddad0c
add test for roundabout with oneone links
May 20, 2014
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
2 changes: 1 addition & 1 deletion Algorithms/BFSComponentExplorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ template <typename GraphT> class BFSComponentExplorer
const NodeID to_node_of_only_restriction =
m_restriction_map.CheckForEmanatingIsOnlyTurn(u, v);

for (auto e2 = m_graph.BeginEdges(v); e2 < m_graph.EndEdges(v); ++e2)
for (auto e2 : m_graph.GetAdjacentEdgeRange(v))
{
const NodeID w = m_graph.GetTarget(e2);

Expand Down
12 changes: 11 additions & 1 deletion Algorithms/DouglasPeucker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "DouglasPeucker.h"
#include "../DataStructures/SegmentInformation.h"
#include "../Util/SimpleLogger.h"

#include <boost/assert.hpp>

Expand Down Expand Up @@ -62,19 +63,28 @@ DouglasPeucker::DouglasPeucker()

void DouglasPeucker::Run(std::vector<SegmentInformation> &input_geometry, const unsigned zoom_level)
{
input_geometry.front().necessary = true;
input_geometry.back().necessary = true;

BOOST_ASSERT_MSG(!input_geometry.empty(), "geometry invalid");
if (input_geometry.size() <= 2)
if (input_geometry.size() < 2)
{
return;
}

SimpleLogger().Write() << "input_geometry.size()=" << input_geometry.size();

{
BOOST_ASSERT_MSG(zoom_level < 19, "unsupported zoom level");
unsigned left_border = 0;
unsigned right_border = 1;
// Sweep over array and identify those ranges that need to be checked
do
{
if (!input_geometry[left_border].necessary)
{
SimpleLogger().Write() << "broken interval [" << left_border << "," << right_border << "]";
}
BOOST_ASSERT_MSG(input_geometry[left_border].necessary,
"left border must be necessary");
BOOST_ASSERT_MSG(input_geometry.back().necessary, "right border must be necessary");
Expand Down
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_ */
Loading