Add update functionality to osrm-customize

All speed file flags are compatible with osrm-contract.
This commit is contained in:
Patrick Niklaus
2017-03-10 22:35:46 +00:00
committed by Patrick Niklaus
parent c6e9cc8024
commit 907f933a54
21 changed files with 266 additions and 93 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
namespace osrm
{
namespace customize
namespace customizer
{
class CellCustomizer
+2 -2
View File
@@ -5,7 +5,7 @@
namespace osrm
{
namespace customize
namespace customizer
{
class Customizer
@@ -14,7 +14,7 @@ class Customizer
int Run(const CustomizationConfig &config);
};
} // namespace customize
} // namespace customizer
} // namespace osrm
#endif // OSRM_CUSTOMIZE_CUSTOMIZER_HPP
+10 -1
View File
@@ -1,6 +1,8 @@
#ifndef OSRM_CUSTOMIZE_CUSTOMIZER_CONFIG_HPP
#define OSRM_CUSTOMIZE_CUSTOMIZER_CONFIG_HPP
#include "updater/updater_config.hpp"
#include <boost/filesystem/path.hpp>
#include <array>
@@ -8,7 +10,7 @@
namespace osrm
{
namespace customize
namespace customizer
{
struct CustomizationConfig
@@ -33,6 +35,10 @@ struct CustomizationConfig
edge_based_graph_path = basepath + ".osrm.ebg";
mld_partition_path = basepath + ".osrm.partition";
mld_storage_path = basepath + ".osrm.cells";
mld_graph_path = basepath + ".osrm.mldgr";
updater_config.osrm_input_path = basepath + ".osrm";
updater_config.UseDefaultOutputNames();
}
// might be changed to the node based graph at some point
@@ -40,8 +46,11 @@ struct CustomizationConfig
boost::filesystem::path edge_based_graph_path;
boost::filesystem::path mld_partition_path;
boost::filesystem::path mld_storage_path;
boost::filesystem::path mld_graph_path;
unsigned requested_num_threads;
updater::UpdaterConfig updater_config;
};
}
}
+49
View File
@@ -0,0 +1,49 @@
#ifndef OSRM_CUSTOMIZE_EDGE_BASED_GRAPH_HPP
#define OSRM_CUSTOMIZE_EDGE_BASED_GRAPH_HPP
#include "extractor/edge_based_edge.hpp"
#include "partition/edge_based_graph.hpp"
#include "util/static_graph.hpp"
#include "util/typedefs.hpp"
#include <boost/filesystem/path.hpp>
namespace osrm
{
namespace customizer
{
struct StaticEdgeBasedGraph;
namespace io
{
void read(const boost::filesystem::path &path, StaticEdgeBasedGraph &graph);
void write(const boost::filesystem::path &path, const StaticEdgeBasedGraph &graph);
}
using EdgeBasedGraphEdgeData = partition::EdgeBasedGraphEdgeData;
struct StaticEdgeBasedGraph : util::StaticGraph<EdgeBasedGraphEdgeData>
{
using Base = util::StaticGraph<EdgeBasedGraphEdgeData>;
using Base::Base;
friend void io::read(const boost::filesystem::path &path, StaticEdgeBasedGraph &graph);
friend void io::write(const boost::filesystem::path &path, const StaticEdgeBasedGraph &graph);
};
struct StaticEdgeBasedGraphView : util::StaticGraph<EdgeBasedGraphEdgeData, true>
{
using Base = util::StaticGraph<EdgeBasedGraphEdgeData, true>;
using Base::Base;
};
struct StaticEdgeBasedGraphEdge : StaticEdgeBasedGraph::InputEdge
{
using Base = StaticEdgeBasedGraph::InputEdge;
using Base::Base;
};
}
}
#endif
+36
View File
@@ -0,0 +1,36 @@
#ifndef OSRM_CUSTOMIZER_IO_HPP
#define OSRM_CUSTOMIZER_IO_HPP
#include "customizer/edge_based_graph.hpp"
#include "storage/io.hpp"
namespace osrm
{
namespace customizer
{
namespace io
{
inline void read(const boost::filesystem::path &path, StaticEdgeBasedGraph &graph)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.DeserializeVector(graph.node_array);
reader.DeserializeVector(graph.edge_array);
}
inline void write(const boost::filesystem::path &path, const StaticEdgeBasedGraph &graph)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.SerializeVector(graph.node_array);
writer.SerializeVector(graph.edge_array);
}
}
}
}
#endif
@@ -8,6 +8,8 @@
#include "engine/algorithm.hpp"
#include "engine/geospatial_query.hpp"
#include "customizer/edge_based_graph.hpp"
#include "extractor/datasources.hpp"
#include "extractor/guidance/turn_instruction.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
@@ -1017,7 +1019,7 @@ class ContiguousInternalMemoryDataFacade<algorithm::MLD>
public ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>
{
private:
using QueryGraph = util::StaticGraph<EdgeData, true>;
using QueryGraph = customizer::StaticEdgeBasedGraphView;
using GraphNode = QueryGraph::NodeArrayEntry;
using GraphEdge = QueryGraph::EdgeArrayEntry;
+43
View File
@@ -0,0 +1,43 @@
#ifndef OSRM_EDGE_BASED_GRAPH_HPP
#define OSRM_EDGE_BASED_GRAPH_HPP
#include "extractor/edge_based_edge.hpp"
#include "storage/io.hpp"
#include "util/coordinate.hpp"
#include "util/dynamic_graph.hpp"
#include "util/typedefs.hpp"
#include <cstdint>
#include <algorithm>
#include <iterator>
#include <memory>
#include <vector>
namespace osrm
{
namespace partition
{
struct EdgeBasedGraphEdgeData : extractor::EdgeBasedEdge::EdgeData
{
// We need to write out the full edge based graph again.
// TODO: in case we want to modify the graph we need to store a boundary_arc flag here
};
struct DynamicEdgeBasedGraph : util::DynamicGraph<EdgeBasedGraphEdgeData>
{
using Base = util::DynamicGraph<EdgeBasedGraphEdgeData>;
using Base::Base;
};
struct DynamicEdgeBasedGraphEdge : DynamicEdgeBasedGraph::InputEdge
{
using Base = DynamicEdgeBasedGraph::InputEdge;
using Base::Base;
};
}
}
#endif
+11 -28
View File
@@ -1,6 +1,8 @@
#ifndef OSRM_EDGE_BASED_GRAPH_READER_HPP
#define OSRM_EDGE_BASED_GRAPH_READER_HPP
#include "partition/edge_based_graph.hpp"
#include "extractor/edge_based_edge.hpp"
#include "storage/io.hpp"
#include "util/coordinate.hpp"
@@ -19,25 +21,6 @@ namespace osrm
namespace partition
{
struct EdgeBasedGraphEdgeData : extractor::EdgeBasedEdge::EdgeData
{
// We need to write out the full edge based graph again.
// TODO: in case we want to modify the graph we need to store a boundary_arc flag here
};
struct EdgeBasedGraph : util::DynamicGraph<EdgeBasedGraphEdgeData>
{
using Base = util::DynamicGraph<EdgeBasedGraphEdgeData>;
using Base::Base;
};
struct EdgeBasedGraphEdge : EdgeBasedGraph::InputEdge
{
using Base = EdgeBasedGraph::InputEdge;
using Base::Base;
};
// Bidirectional (s,t) to (s,t) and (t,s)
std::vector<extractor::EdgeBasedEdge>
splitBidirectionalEdges(const std::vector<extractor::EdgeBasedEdge> &edges)
@@ -67,12 +50,12 @@ splitBidirectionalEdges(const std::vector<extractor::EdgeBasedEdge> &edges)
return directed;
}
std::vector<EdgeBasedGraphEdge>
prepareEdgesForUsageInGraph(std::vector<extractor::EdgeBasedEdge> edges)
template <typename OutputEdgeT>
std::vector<OutputEdgeT> prepareEdgesForUsageInGraph(std::vector<extractor::EdgeBasedEdge> edges)
{
std::sort(begin(edges), end(edges));
std::vector<EdgeBasedGraphEdge> graph_edges;
std::vector<OutputEdgeT> graph_edges;
graph_edges.reserve(edges.size());
for (NodeID i = 0; i < edges.size();)
@@ -87,8 +70,8 @@ prepareEdgesForUsageInGraph(std::vector<extractor::EdgeBasedEdge> edges)
continue;
}
EdgeBasedGraphEdge forward_edge;
EdgeBasedGraphEdge reverse_edge;
OutputEdgeT forward_edge;
OutputEdgeT reverse_edge;
forward_edge.source = reverse_edge.source = source;
forward_edge.target = reverse_edge.target = target;
forward_edge.data.edge_id = reverse_edge.data.edge_id = edges[i].data.edge_id;
@@ -161,7 +144,7 @@ struct EdgeBasedGraphReader
// FIXME: wrapped in unique_ptr since dynamic_graph is not move-able
std::unique_ptr<EdgeBasedGraph> BuildEdgeBasedGraph()
std::unique_ptr<DynamicEdgeBasedGraph> BuildEdgeBasedGraph()
{
// FIXME: The following is a rough adaption from:
// - adaptToContractorInput
@@ -170,9 +153,9 @@ struct EdgeBasedGraphReader
// FIXME: edges passed as a const reference, can be changed pass-by-value if can be moved
auto directed = splitBidirectionalEdges(edges);
auto tidied = prepareEdgesForUsageInGraph(std::move(directed));
auto tidied = prepareEdgesForUsageInGraph<DynamicEdgeBasedGraphEdge>(std::move(directed));
return std::make_unique<EdgeBasedGraph>(num_nodes, std::move(tidied));
return std::make_unique<DynamicEdgeBasedGraph>(num_nodes, std::move(tidied));
}
private:
@@ -180,7 +163,7 @@ struct EdgeBasedGraphReader
std::size_t num_nodes;
};
inline std::unique_ptr<EdgeBasedGraph> LoadEdgeBasedGraph(const std::string &path)
inline std::unique_ptr<DynamicEdgeBasedGraph> LoadEdgeBasedGraph(const std::string &path)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader(path, fingerprint);
+1
View File
@@ -2,6 +2,7 @@
#define OSRM_PARTITION_IO_HPP
#include "partition/cell_storage.hpp"
#include "partition/edge_based_graph.hpp"
#include "partition/multi_level_partition.hpp"
#include "storage/io.hpp"
+1 -1
View File
@@ -71,7 +71,7 @@ struct StorageConfig final
boost::filesystem::path turn_lane_description_path;
boost::filesystem::path mld_partition_path;
boost::filesystem::path mld_storage_path;
boost::filesystem::path edge_based_graph_path;
boost::filesystem::path mld_graph_path;
};
}
}
+3
View File
@@ -16,6 +16,9 @@ class Updater
public:
Updater(UpdaterConfig config_) : config(std::move(config_)) {}
using NumNodesAndEdges = std::tuple<EdgeID, std::vector<extractor::EdgeBasedEdge>>;
NumNodesAndEdges LoadAndUpdateEdgeExpandedGraph() const;
EdgeID
LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &edge_based_edge_list,
std::vector<EdgeWeight> &node_weights) const;
+6 -1
View File
@@ -52,6 +52,8 @@ template <> struct SortableEdgeWithData<void>
NodeIterator source;
NodeIterator target;
SortableEdgeWithData() = default;
SortableEdgeWithData(NodeIterator source, NodeIterator target) : source(source), target(target)
{
}
@@ -73,6 +75,8 @@ template <typename EdgeDataT> struct SortableEdgeWithData : SortableEdgeWithData
EdgeDataT data;
SortableEdgeWithData() = default;
template <typename... Ts>
SortableEdgeWithData(NodeIterator source, NodeIterator target, Ts &&... data)
: Base{source, target}, data{std::forward<Ts>(data)...}
@@ -85,6 +89,7 @@ template <typename EdgeDataT> struct SortableEdgeWithData : SortableEdgeWithData
template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
{
public:
using InputEdge = static_graph_details::SortableEdgeWithData<EdgeDataT>;
using NodeIterator = static_graph_details::NodeIterator;
using EdgeIterator = static_graph_details::EdgeIterator;
using EdgeRange = range<EdgeIterator>;
@@ -241,7 +246,7 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
const NodeArrayEntry &GetNode(const NodeID nid) const { return node_array[nid]; }
const EdgeArrayEntry &GetEdge(const EdgeID eid) const { return edge_array[eid]; }
private:
protected:
template <typename OtherEdge>
void CopyDataIfAvailable(EdgeArrayEntry &into, const OtherEdge &from, std::true_type)
{