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

Isochrone Plugin #2189 #2477

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
4e78329
started range analysis
roroettg Mar 17, 2016
6025b46
first implementation of routing algo with pretty json-print
roroettg Mar 17, 2016
f552336
added testing
roroettg Mar 23, 2016
e887242
started range analysis
roroettg Mar 17, 2016
f9d9d9c
first implementation of routing algo with pretty json-print
roroettg Mar 17, 2016
9059de0
added testing
roroettg Mar 23, 2016
bf036de
changes
roroettg Apr 13, 2016
358a1f7
merge
roroettg Apr 13, 2016
a8d560d
helloworld-isochrone with new API
roroettg Apr 14, 2016
ab4e259
started range analysis
roroettg Mar 17, 2016
fc1b696
first implementation of routing algo with pretty json-print
roroettg Mar 17, 2016
fddfd0b
added testing
roroettg Mar 23, 2016
2035618
started range analysis
roroettg Mar 17, 2016
be23a0d
first implementation of routing algo with pretty json-print
roroettg Mar 17, 2016
06e3161
added testing
roroettg Mar 23, 2016
7999911
changes
roroettg Apr 13, 2016
25164a8
helloworld-isochrone with new API
roroettg Apr 14, 2016
9a7d098
isochrone impl
roroettg Apr 20, 2016
26bff90
Merge branch 'develop' of https://github.com/beemogmbh/osrm-backend i…
roroettg Apr 20, 2016
0cf0608
added inline to functions to be able to use them for isochrones/avoid…
roroettg Apr 20, 2016
1440e54
working isochrone calc, TODO: find out why distances are further than…
roroettg Apr 27, 2016
1837567
merge
roroettg Apr 27, 2016
8a8bc76
Merge branch 'develop' into HEAD
roroettg Apr 27, 2016
383d1ab
merge with fork
roroettg Apr 27, 2016
6bb0a16
added graham scan
roroettg May 10, 2016
4a9f133
Merge remote-tracking branch 'upstream/master' into develop
roroettg May 10, 2016
b168f01
fixed isochrone for current version of master
roroettg May 11, 2016
36c76c8
fixed integer overflow bug in graham scan
roroettg May 11, 2016
e111424
added Andrew's monotone chain convex hull algorithm
roroettg May 11, 2016
a22d169
added distance param to grammar
roroettg May 12, 2016
a8f081d
Merge remote-tracking branch 'upstream/master' into develop
roroettg May 19, 2016
931281f
refactoring
roroettg May 19, 2016
510585a
added convexhull api param
roroettg May 19, 2016
8ce8a38
code format
roroettg May 19, 2016
9f73b69
bug fixes and tests
roroettg May 25, 2016
ec161e4
Merge remote-tracking branch 'upstream/master'
roroettg May 25, 2016
fad6726
testfixes
roroettg May 27, 2016
f574658
merge
roroettg May 27, 2016
17c06d2
implemented isochrone as plugin
roroettg May 27, 2016
e334402
refactoring
roroettg May 27, 2016
8db63a9
Merge remote-tracking branch 'upstream/master'
roroettg May 27, 2016
0ea7cde
refactoring #2
roroettg May 27, 2016
4f8daac
added isochrone by distance or duration functionality
roroettg Jun 9, 2016
8564f06
merge
roroettg Jun 10, 2016
bef74c9
Merge remote-tracking branch 'upstream/master'
roroettg Jun 10, 2016
71ed41b
concave isochrones added
roroettg Jun 23, 2016
1cf81e1
fixed mem leak
roroettg Jul 14, 2016
4ca2945
merge
roroettg Jul 20, 2016
826c165
Merge remote-tracking branch 'upstream/master'
roroettg Jul 20, 2016
baed9c7
Fixed bug multiple Requests
roroettg Jul 20, 2016
814e4d8
Style Format
roroettg Jul 28, 2016
c1679a7
merge
roroettg Jul 28, 2016
8f5d72d
Merge remote-tracking branch 'upstream/master'
roroettg Jul 28, 2016
554303d
merge
roroettg Aug 9, 2016
1408187
Merge remote-tracking branch 'upstream/master'
roroettg Aug 9, 2016
fbc5212
timing
roroettg Aug 23, 2016
279461e
Merge remote-tracking branch 'osrm-upstream/master'
roroettg Aug 23, 2016
667cc37
first docker impl
roroettg Aug 24, 2016
1fe544e
Merge remote-tracking branch 'osrm-upstream/master'
roroettg Sep 1, 2016
b694ab6
removed docker
roroettg Sep 1, 2016
8b9f1a1
Merge remote-tracking branch 'osrm-upstream/master'
roroettg Sep 8, 2016
80062ae
merge
roroettg Oct 10, 2016
547f293
merge
roroettg Oct 10, 2016
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
89 changes: 89 additions & 0 deletions include/engine/api/isochrone_api.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#ifndef ENGINE_API_ISOCHRONE_HPP
#define ENGINE_API_ISOCHRONE_HPP

#include "engine/api/base_api.hpp"
#include "engine/api/isochrone_parameters.hpp"
#include "engine/plugins/isochrone.hpp"
#include "engine/plugins/plugin_base.hpp"

namespace osrm
{
namespace engine
{
namespace api
{

class IsochroneAPI final : public BaseAPI
{

public:
const IsochroneParameters &parameters;

IsochroneAPI(const datafacade::BaseDataFacade &facade_, const IsochroneParameters &parameters_)
: BaseAPI(facade_, parameters_), parameters(parameters_)
{
}

void MakeResponse(const std::vector<engine::plugins::IsochroneNode> isochroneNodes,
const std::vector<engine::plugins::IsochroneNode> convexhull,
const std::vector<engine::plugins::IsochroneNode> concavehull,
util::json::Object &response) const
{
util::json::Array isochroneJson;
for (auto isochrone : isochroneNodes)
{
util::json::Object object;

util::json::Object source;
source.values["lat"] = static_cast<double>(util::toFloating(isochrone.node.lat));
source.values["lon"] = static_cast<double>(util::toFloating(isochrone.node.lon));
object.values["p1"] = std::move(source);

util::json::Object predecessor;
predecessor.values["lat"] =
static_cast<double>(util::toFloating(isochrone.predecessor.lat));
predecessor.values["lon"] =
static_cast<double>(util::toFloating(isochrone.predecessor.lon));
object.values["p2"] = std::move(predecessor);

util::json::Object distance;
object.values["distance_from_start"] = isochrone.distance;

util::json::Object duration;
object.values["duration_from_start"] = isochrone.duration;

isochroneJson.values.push_back(object);
}
response.values["isochrone"] = std::move(isochroneJson);

if (!convexhull.empty())
{
util::json::Array convexhullArray;
for (engine::plugins::IsochroneNode n : convexhull)
{
util::json::Object point;
point.values["lat"] = static_cast<double>(util::toFloating(n.node.lat));
point.values["lon"] = static_cast<double>(util::toFloating(n.node.lon));
convexhullArray.values.push_back(point);
}
response.values["convexhull"] = std::move(convexhullArray);
}

if (!concavehull.empty())
{
util::json::Array concavehullArray;
for (engine::plugins::IsochroneNode n : concavehull)
{
util::json::Object point;
point.values["lat"] = static_cast<double>(util::toFloating(n.node.lat));
point.values["lon"] = static_cast<double>(util::toFloating(n.node.lon));
concavehullArray.values.push_back(point);
}
response.values["concavehull"] = std::move(concavehullArray);
}
}
};
}
}
}
#endif // ENGINE_API_ISOCHRONE_HPP
26 changes: 26 additions & 0 deletions include/engine/api/isochrone_parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef ENGINE_API_ISOCHRONE_PARAMETERS_HPP
#define ENGINE_API_ISOCHRONE_PARAMETERS_HPP

#include "engine/api/base_parameters.hpp"

namespace osrm
{
namespace engine
{
namespace api
{

struct IsochroneParameters : public BaseParameters
{
unsigned int duration = 0;
double distance = 0;
bool convexhull = false;
bool concavehull = false;
double threshold = 1; // max precision

bool IsValid() const { return BaseParameters::IsValid(); }
};
}
}
}
#endif // ENGINE_API_ISOCHRONE_PARAMETERS_HPP
4 changes: 4 additions & 0 deletions include/engine/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct NearestParameters;
struct TripParameters;
struct MatchParameters;
struct TileParameters;
struct IsochroneParameters;
}
namespace plugins
{
Expand All @@ -45,6 +46,7 @@ class NearestPlugin;
class TripPlugin;
class MatchPlugin;
class TilePlugin;
class IsochronePlugin;
}
// End fwd decls

Expand All @@ -70,6 +72,7 @@ class Engine final
Status Trip(const api::TripParameters &parameters, util::json::Object &result) const;
Status Match(const api::MatchParameters &parameters, util::json::Object &result) const;
Status Tile(const api::TileParameters &parameters, std::string &result) const;
Status Isochrone(const api::IsochroneParameters &parameters, util::json::Object &result) const;

private:
std::unique_ptr<storage::SharedBarriers> lock;
Expand All @@ -80,6 +83,7 @@ class Engine final
std::unique_ptr<plugins::TripPlugin> trip_plugin;
std::unique_ptr<plugins::MatchPlugin> match_plugin;
std::unique_ptr<plugins::TilePlugin> tile_plugin;
std::unique_ptr<plugins::IsochronePlugin> isochrone_plugin;

std::shared_ptr<datafacade::BaseDataFacade> query_data_facade;
};
Expand Down
1 change: 1 addition & 0 deletions include/engine/engine_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct EngineConfig final
int max_locations_map_matching = -1;
int max_results_nearest = -1;
bool use_shared_memory = true;
bool use_isochrone = true;
};
}
}
Expand Down
99 changes: 99 additions & 0 deletions include/engine/plugins/isochrone.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#ifndef ISOCHRONE_HPP
#define ISOCHRONE_HPP

#include "engine/api/isochrone_parameters.hpp"
#include "engine/plugins/plugin_base.hpp"
#include "osrm/json_container.hpp"
#include "util/binary_heap.hpp"
#include "util/static_graph.hpp"

#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/function.hpp>
#include <tbb/parallel_sort.h>

#include <algorithm>
#include <cstdlib>
#include <utility>
#include <vector>

namespace osrm
{
namespace engine
{
namespace plugins
{
struct HeapData
{
NodeID parent;
HeapData(NodeID p) : parent(p) {}
};
struct SimpleEdgeData
{
SimpleEdgeData() : weight(INVALID_EDGE_WEIGHT), real(false) {}
SimpleEdgeData(unsigned weight_, bool real_) : weight(weight_), real(real_) {}
unsigned weight;
bool real;
};

struct IsochroneNode
{
IsochroneNode(){};
IsochroneNode(osrm::extractor::QueryNode node,
osrm::extractor::QueryNode predecessor,
double distance,
int duration)
: node(node), predecessor(predecessor), distance(distance), duration(duration)
{
}

osrm::extractor::QueryNode node;
osrm::extractor::QueryNode predecessor;
double distance;
int duration;

bool operator==(const IsochroneNode &n) const
{
if (n.node.node_id == node.node_id)
return true;
else
return false;
}
};

using SimpleGraph = util::StaticGraph<SimpleEdgeData>;
using SimpleEdge = SimpleGraph::InputEdge;
using QueryHeap = osrm::util::
BinaryHeap<NodeID, NodeID, int, HeapData, osrm::util::UnorderedMapStorage<NodeID, int>>;
typedef std::vector<IsochroneNode> IsochroneVector;

class IsochronePlugin final : public BasePlugin
{
private:
boost::filesystem::path base;
std::shared_ptr<engine::plugins::SimpleGraph> graph;
std::vector<osrm::extractor::QueryNode> coordinate_list;
std::vector<engine::plugins::SimpleEdge> graph_edge_list;
std::size_t number_of_nodes;

std::size_t loadGraph(const std::string &path,
std::vector<extractor::QueryNode> &coordinate_list,
std::vector<SimpleEdge> &graph_edge_list);

void dijkstraByDuration(IsochroneVector &set, NodeID &source, int duration);
void dijkstraByDistance(IsochroneVector &isochroneSet, NodeID &source, double distance);
void update(IsochroneVector &s, IsochroneNode node);

public:
explicit IsochronePlugin(const std::string base);

Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't compile datafacade::BaseDataFacade need to be const.

const api::IsochroneParameters &params,
util::json::Object &json_result);
};
}
}
}

#endif // ISOCHRONE_HPP
50 changes: 50 additions & 0 deletions include/engine/search_engine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef SEARCH_ENGINE_HPP
#define SEARCH_ENGINE_HPP

#include "engine/routing_algorithms/alternative_path.hpp"
#include "engine/routing_algorithms/direct_shortest_path.hpp"
#include "engine/routing_algorithms/many_to_many.hpp"
#include "engine/routing_algorithms/map_matching.hpp"
#include "engine/routing_algorithms/one_to_many.hpp"
#include "engine/routing_algorithms/shortest_path.hpp"
#include "engine/search_engine_data.hpp"

#include <type_traits>

namespace osrm
{
namespace engine
{

template <class DataFacadeT> class SearchEngine
{
private:
DataFacadeT *facade;
SearchEngineData engine_working_data;

public:
routing_algorithms::ShortestPathRouting<DataFacadeT> shortest_path;
routing_algorithms::DirectShortestPathRouting<DataFacadeT> direct_shortest_path;
routing_algorithms::AlternativeRouting<DataFacadeT> alternative_path;
routing_algorithms::ManyToManyRouting<DataFacadeT> distance_table;
routing_algorithms::MapMatching<DataFacadeT> map_matching;
routing_algorithms::OneToManyRouting<DataFacadeT> oneToMany;

explicit SearchEngine(DataFacadeT *facade)
: facade(facade), shortest_path(facade, engine_working_data),
direct_shortest_path(facade, engine_working_data),
alternative_path(facade, engine_working_data),
distance_table(facade, engine_working_data), map_matching(facade, engine_working_data),
oneToMany(facade, engine_working_data)
{
static_assert(!std::is_pointer<DataFacadeT>::value, "don't instantiate with ptr type");
static_assert(std::is_object<DataFacadeT>::value,
"don't instantiate with void, function, or reference");
}

~SearchEngine() {}
};
}
}

#endif // SEARCH_ENGINE_HPP
11 changes: 11 additions & 0 deletions include/osrm/isochrone_parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef GLOBAL_ISOCHRONE_PARAMETERS_HPP
#define GLOBAL_ISOCHRONE_PARAMETERS_HPP

#include "engine/api/isochrone_parameters.hpp"

namespace osrm
{
using engine::api::IsochroneParameters;
}

#endif // GLOBAL_ISOCHRONE_PARAMETERS_HPP
9 changes: 9 additions & 0 deletions include/osrm/osrm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using engine::api::NearestParameters;
using engine::api::TripParameters;
using engine::api::MatchParameters;
using engine::api::TileParameters;
using engine::api::IsochroneParameters;

/**
* Represents a Open Source Routing Machine with access to its services.
Expand Down Expand Up @@ -130,6 +131,14 @@ class OSRM final
*/
Status Tile(const TileParameters &parameters, std::string &result) const;

/**
* Isochrone for given distance
* \param parameters nearest query specific parameters
* \return Status indicating success for the query or failure
* \see Status, NearestParameters and json::Object
*/
Status Isochrone(const IsochroneParameters &parameters, json::Object &result) const;

private:
std::unique_ptr<engine::Engine> engine_;
};
Expand Down
1 change: 1 addition & 0 deletions include/osrm/osrm_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct NearestParameters;
struct TripParameters;
struct MatchParameters;
struct TileParameters;
struct IsochroneParameters;
} // ns api

class Engine;
Expand Down
Loading