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

Renumber graph nodes after partitioning them #4089

Merged
merged 3 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Note : the curb side depend on the `ProfileProperties::left_hand_driving`, it's a global property set once by the profile. If you are working with a planet dataset, the api will be wrong in some countries, and right in others.
- NodeJs Bindings
- new parameter `approaches` for `route`, `table`, `trip` and `nearest` requests.
- Tools
- `osrm-partition` now ensures it is called before `osrm-contract` and removes inconsitent .hsgr files automatically.
- Features
- Added conditional restriction support with `parse-conditional-restrictions=true|false` to osrm-extract. This option saves conditional turn restrictions to the .restrictions file for parsing by contract later. Added `parse-conditionals-from-now=utc time stamp` and `--time-zone-file=/path/to/file` to osrm-contract
- Files
Expand Down
14 changes: 3 additions & 11 deletions features/raster/weights.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ Feature: Raster - weights

Scenario: Weighting not based on raster sources
Given the profile "testbot"
When I run "osrm-extract {osm_file} -p {profile_file}"
And I run "osrm-contract {processed_file}"
And I route I should get
When I route I should get
| from | to | route | speed |
| a | b | ab,ab | 36 km/h |
| a | c | ab,bc,bc | 36 km/h |
Expand All @@ -44,10 +42,7 @@ Feature: Raster - weights

Scenario: Weighting based on raster sources
Given the profile "rasterbot"
When I run "osrm-extract {osm_file} -p {profile_file}"
Then stdout should contain "evaluating segment"
And I run "osrm-contract {processed_file}"
And I route I should get
When I route I should get
| from | to | route | speed |
| a | b | ab,ab | 8 km/h |
| b | a | ab,ab | 22 km/h |
Expand All @@ -63,10 +58,7 @@ Feature: Raster - weights

Scenario: Weighting based on raster sources
Given the profile "rasterbotinterp"
When I run "osrm-extract {osm_file} -p {profile_file}"
Then stdout should contain "evaluating segment"
And I run "osrm-contract {processed_file}"
And I route I should get
When I route I should get
| from | to | route | speed |
| a | b | ab,ab | 8 km/h |
| a | c | ad,dc,dc | 15 km/h |
Expand Down
2 changes: 1 addition & 1 deletion features/support/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ module.exports = function () {
processedCacheFile: this.processedCacheFile, environment: this.environment};
let queue = d3.queue(1);
queue.defer(this.extractData.bind(this), p);
queue.defer(this.contractData.bind(this), p);
queue.defer(this.partitionData.bind(this), p);
queue.defer(this.contractData.bind(this), p);
queue.defer(this.customizeData.bind(this), p);
queue.awaitAll(callback);
};
Expand Down
43 changes: 25 additions & 18 deletions include/extractor/edge_based_edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,6 @@ namespace extractor
struct EdgeBasedEdge
{
public:
EdgeBasedEdge();

template <class EdgeT> explicit EdgeBasedEdge(const EdgeT &other);

EdgeBasedEdge(const NodeID source,
const NodeID target,
const NodeID edge_id,
const EdgeWeight weight,
const EdgeWeight duration,
const bool forward,
const bool backward);

bool operator<(const EdgeBasedEdge &other) const;

NodeID source;
NodeID target;

struct EdgeData
{
EdgeData() : turn_id(0), weight(0), duration(0), forward(false), backward(false) {}
Expand All @@ -51,7 +34,24 @@ struct EdgeBasedEdge
std::uint32_t backward : 1;

auto is_unidirectional() const { return !forward || !backward; }
} data;
};

EdgeBasedEdge();
template <class EdgeT> explicit EdgeBasedEdge(const EdgeT &other);
EdgeBasedEdge(const NodeID source,
const NodeID target,
const NodeID edge_id,
const EdgeWeight weight,
const EdgeWeight duration,
const bool forward,
const bool backward);
EdgeBasedEdge(const NodeID source, const NodeID target, const EdgeBasedEdge::EdgeData &data);

bool operator<(const EdgeBasedEdge &other) const;

NodeID source;
NodeID target;
EdgeData data;
};
static_assert(sizeof(extractor::EdgeBasedEdge) == 20,
"Size of extractor::EdgeBasedEdge type is "
Expand All @@ -73,6 +73,13 @@ inline EdgeBasedEdge::EdgeBasedEdge(const NodeID source,
{
}

inline EdgeBasedEdge::EdgeBasedEdge(const NodeID source,
const NodeID target,
const EdgeBasedEdge::EdgeData &data)
: source(source), target(target), data{data}
{
}

inline bool EdgeBasedEdge::operator<(const EdgeBasedEdge &other) const
{
const auto unidirectional = data.is_unidirectional();
Expand Down
4 changes: 0 additions & 4 deletions include/extractor/extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ class Extractor
std::vector<util::Coordinate> &coordinates,
extractor::PackedOSMIDs &osm_node_ids);

void WriteEdgeBasedGraph(const std::string &output_file_filename,
const EdgeID max_edge_id,
util::DeallocatingVector<EdgeBasedEdge> const &edge_based_edge_list);

void WriteIntersectionClassificationData(
const std::string &output_file_name,
const std::vector<std::uint32_t> &node_based_intersection_classes,
Expand Down
27 changes: 27 additions & 0 deletions include/extractor/files.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef OSRM_EXTRACTOR_FILES_HPP
#define OSRM_EXTRACTOR_FILES_HPP

#include "extractor/edge_based_edge.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/node_data_container.hpp"
#include "extractor/serialization.hpp"
Expand All @@ -19,6 +20,32 @@ namespace extractor
namespace files
{

template <typename EdgeBasedEdgeVector>
void writeEdgeBasedGraph(const boost::filesystem::path &path,
EdgeID const max_edge_id,
const EdgeBasedEdgeVector &edge_based_edge_list)
{
static_assert(std::is_same<typename EdgeBasedEdgeVector::value_type, EdgeBasedEdge>::value, "");

storage::io::FileWriter writer(path, storage::io::FileWriter::GenerateFingerprint);

writer.WriteElementCount64(max_edge_id);
storage::serialization::write(writer, edge_based_edge_list);
}

template <typename EdgeBasedEdgeVector>
void readEdgeBasedGraph(const boost::filesystem::path &path,
EdgeID &max_edge_id,
EdgeBasedEdgeVector &edge_based_edge_list)
{
static_assert(std::is_same<typename EdgeBasedEdgeVector::value_type, EdgeBasedEdge>::value, "");

storage::io::FileReader reader(path, storage::io::FileReader::VerifyFingerprint);

max_edge_id = reader.ReadElementCount64();
storage::serialization::read(reader, edge_based_edge_list);
}

// reads .osrm.nodes
template <typename CoordinatesT, typename PackedOSMIDsT>
inline void readNodes(const boost::filesystem::path &path,
Expand Down
12 changes: 12 additions & 0 deletions include/extractor/node_data_container.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef OSRM_EXTRACTOR_NODE_DATA_CONTAINER_HPP
#define OSRM_EXTRACTOR_NODE_DATA_CONTAINER_HPP

#include "extractor/travel_mode.hpp"

#include "storage/io_fwd.hpp"
#include "storage/shared_memory_ownership.hpp"

#include "util/permutation.hpp"
#include "util/typedefs.hpp"
#include "util/vector_view.hpp"

Expand Down Expand Up @@ -81,6 +84,15 @@ template <storage::Ownership Ownership> class EdgeBasedNodeDataContainerImpl
serialization::write<Ownership>(storage::io::FileWriter &writer,
const EdgeBasedNodeDataContainerImpl &ebn_data_container);

template <typename = std::enable_if<Ownership == storage::Ownership::Container>>
void Renumber(const std::vector<std::uint32_t> &permutation)
{
util::inplacePermutation(geometry_ids.begin(), geometry_ids.end(), permutation);
util::inplacePermutation(name_ids.begin(), name_ids.end(), permutation);
util::inplacePermutation(component_ids.begin(), component_ids.end(), permutation);
util::inplacePermutation(travel_modes.begin(), travel_modes.end(), permutation);
}

private:
Vector<GeometryID> geometry_ids;
Vector<NameID> name_ids;
Expand Down
10 changes: 8 additions & 2 deletions include/partition/edge_based_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ namespace partition

struct EdgeBasedGraphEdgeData : extractor::EdgeBasedEdge::EdgeData
{
// We need to write out the full edge based graph again.
using Base = extractor::EdgeBasedEdge::EdgeData;
using Base::Base;

// TODO: in case we want to modify the graph we need to store a boundary_arc flag here
EdgeBasedGraphEdgeData(const EdgeBasedGraphEdgeData &) = default;
EdgeBasedGraphEdgeData(EdgeBasedGraphEdgeData &&) = default;
EdgeBasedGraphEdgeData &operator=(const EdgeBasedGraphEdgeData &) = default;
EdgeBasedGraphEdgeData &operator=(EdgeBasedGraphEdgeData &&) = default;
EdgeBasedGraphEdgeData(const Base &base) : Base(base) {}
EdgeBasedGraphEdgeData() : Base() {}
};

struct DynamicEdgeBasedGraph : util::DynamicGraph<EdgeBasedGraphEdgeData>
Expand Down
Loading