Added osrm-customizer tool
This commit is contained in:
committed by
Patrick Niklaus
parent
bc2e06502e
commit
3f6ae245f6
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace customizer
|
||||
namespace customize
|
||||
{
|
||||
|
||||
class CellCustomizer
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef OSRM_CUSTOMIZE_CUSTOMIZER_HPP
|
||||
#define OSRM_CUSTOMIZE_CUSTOMIZER_HPP
|
||||
|
||||
#include "customizer/customizer_config.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace customize
|
||||
{
|
||||
|
||||
class Customizer
|
||||
{
|
||||
public:
|
||||
int Run(const CustomizationConfig &config);
|
||||
};
|
||||
|
||||
} // namespace customize
|
||||
} // namespace osrm
|
||||
|
||||
#endif // OSRM_CUSTOMIZE_CUSTOMIZER_HPP
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef OSRM_CUSTOMIZE_CUSTOMIZER_CONFIG_HPP
|
||||
#define OSRM_CUSTOMIZE_CUSTOMIZER_CONFIG_HPP
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace customize
|
||||
{
|
||||
|
||||
struct CustomizationConfig
|
||||
{
|
||||
CustomizationConfig() : requested_num_threads(0) {}
|
||||
|
||||
void UseDefaults()
|
||||
{
|
||||
std::string basepath = base_path.string();
|
||||
|
||||
const std::string ext = ".osrm";
|
||||
const auto pos = basepath.find(ext);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
basepath.replace(pos, ext.size(), "");
|
||||
}
|
||||
else
|
||||
{
|
||||
// unknown extension
|
||||
}
|
||||
|
||||
edge_based_graph_path = basepath + ".osrm.ebg";
|
||||
mld_partition_path = basepath + ".osrm.partition";
|
||||
mld_storage_path = basepath + ".osrm.cells";
|
||||
}
|
||||
|
||||
// might be changed to the node based graph at some point
|
||||
boost::filesystem::path base_path;
|
||||
boost::filesystem::path edge_based_graph_path;
|
||||
boost::filesystem::path mld_partition_path;
|
||||
boost::filesystem::path mld_storage_path;
|
||||
|
||||
unsigned requested_num_threads;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OSRM_CUSTOMIZE_CUSTOMIZER_CONFIG_HPP
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef OSRM_UTIL_CELL_STORAGE_HPP
|
||||
#define OSRM_UTIL_CELL_STORAGE_HPP
|
||||
#ifndef OSRM_CUSTOMIZE_CELL_STORAGE_HPP
|
||||
#define OSRM_CUSTOMIZE_CELL_STORAGE_HPP
|
||||
|
||||
#include "partition/multi_level_partition.hpp"
|
||||
|
||||
@@ -177,7 +177,7 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
}
|
||||
};
|
||||
|
||||
std::size_t LevelIDToIndex(LevelID level) const { return level - 1; }
|
||||
std::size_t LevelIDToIndex(partition::LevelID level) const { return level - 1; }
|
||||
|
||||
public:
|
||||
using Cell = CellImpl<EdgeWeight>;
|
||||
@@ -186,11 +186,11 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
CellStorageImpl() {}
|
||||
|
||||
template <typename GraphT, typename = std::enable_if<!UseShareMemory>>
|
||||
CellStorageImpl(const MultiLevelPartition &partition, const GraphT &base_graph)
|
||||
CellStorageImpl(const partition::MultiLevelPartition &partition, const GraphT &base_graph)
|
||||
{
|
||||
// pre-allocate storge for CellData so we can have random access to it by cell id
|
||||
unsigned number_of_cells = 0;
|
||||
for (LevelID level = 1u; level < partition.GetNumberOfLevels(); ++level)
|
||||
for (partition::LevelID level = 1u; level < partition.GetNumberOfLevels(); ++level)
|
||||
{
|
||||
level_to_cell_offset.push_back(number_of_cells);
|
||||
number_of_cells += partition.GetNumberOfCells(level);
|
||||
@@ -198,12 +198,12 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
level_to_cell_offset.push_back(number_of_cells);
|
||||
cells.resize(number_of_cells);
|
||||
|
||||
std::vector<std::pair<CellID, NodeID>> level_source_boundary;
|
||||
std::vector<std::pair<CellID, NodeID>> level_destination_boundary;
|
||||
std::vector<std::pair<partition::CellID, NodeID>> level_source_boundary;
|
||||
std::vector<std::pair<partition::CellID, NodeID>> level_destination_boundary;
|
||||
|
||||
std::size_t number_of_unconneced = 0;
|
||||
|
||||
for (LevelID level = 1u; level < partition.GetNumberOfLevels(); ++level)
|
||||
for (partition::LevelID level = 1u; level < partition.GetNumberOfLevels(); ++level)
|
||||
{
|
||||
auto level_offset = level_to_cell_offset[LevelIDToIndex(level)];
|
||||
|
||||
@@ -212,7 +212,7 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
|
||||
for (auto node = 0u; node < base_graph.GetNumberOfNodes(); ++node)
|
||||
{
|
||||
const CellID cell_id = partition.GetCell(level, node);
|
||||
const partition::CellID cell_id = partition.GetCell(level, node);
|
||||
bool is_source_node = false;
|
||||
bool is_destination_node = false;
|
||||
bool is_boundary_node = false;
|
||||
@@ -297,7 +297,8 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
// to a different cell.
|
||||
if (number_of_unconneced > 0)
|
||||
{
|
||||
util::Log(logWARNING) << "Node needs to either have incoming or outgoing edges in cell";
|
||||
util::Log(logWARNING) << "Node needs to either have incoming or outgoing edges in cell."
|
||||
<< " Number of unconnected nodes is " << number_of_unconneced;
|
||||
}
|
||||
|
||||
// Set weight offsets and calculate total storage size
|
||||
@@ -323,7 +324,7 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
{
|
||||
}
|
||||
|
||||
ConstCell GetCell(LevelID level, CellID id) const
|
||||
ConstCell GetCell(partition::LevelID level, partition::CellID id) const
|
||||
{
|
||||
const auto level_index = LevelIDToIndex(level);
|
||||
BOOST_ASSERT(level_index < level_to_cell_offset.size());
|
||||
@@ -334,7 +335,8 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
cells[cell_index], weights.data(), source_boundary.data(), destination_boundary.data()};
|
||||
}
|
||||
|
||||
template <typename = std::enable_if<!UseShareMemory>> Cell GetCell(LevelID level, CellID id)
|
||||
template <typename = std::enable_if<!UseShareMemory>>
|
||||
Cell GetCell(partition::LevelID level, partition::CellID id)
|
||||
{
|
||||
const auto level_index = LevelIDToIndex(level);
|
||||
BOOST_ASSERT(level_index < level_to_cell_offset.size());
|
||||
@@ -359,4 +361,4 @@ template <bool UseShareMemory> class CellStorageImpl
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // OSRM_CUSTOMIZE_CELL_STORAGE_HPP
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef OSRM_PARTITION_IO_HPP
|
||||
#define OSRM_PARTITION_IO_HPP
|
||||
|
||||
#include "partition/cell_storage.hpp"
|
||||
#include "partition/multi_level_partition.hpp"
|
||||
#include "partition/cell_storage.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
|
||||
@@ -13,8 +13,17 @@ namespace partition
|
||||
namespace io
|
||||
{
|
||||
|
||||
template <>
|
||||
inline void write(const boost::filesystem::path &path, const partition::MultiLevelPartition &mlp)
|
||||
template <> inline void read(const boost::filesystem::path &path, MultiLevelPartition &mlp)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
|
||||
storage::io::FileReader reader{path, fingerprint};
|
||||
|
||||
reader.ReadInto<MultiLevelPartition::LevelData>(mlp.level_data);
|
||||
reader.DeserializeVector(mlp.partition);
|
||||
reader.DeserializeVector(mlp.cell_to_children);
|
||||
}
|
||||
|
||||
template <> inline void write(const boost::filesystem::path &path, const MultiLevelPartition &mlp)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
|
||||
storage::io::FileWriter writer{path, fingerprint};
|
||||
@@ -24,8 +33,7 @@ inline void write(const boost::filesystem::path &path, const partition::MultiLev
|
||||
writer.SerializeVector(mlp.cell_to_children);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void write(const boost::filesystem::path &path, const partition::CellStorage &storage)
|
||||
template <> inline void write(const boost::filesystem::path &path, const CellStorage &storage)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
|
||||
storage::io::FileWriter writer{path, fingerprint};
|
||||
@@ -36,6 +44,7 @@ inline void write(const boost::filesystem::path &path, const partition::CellStor
|
||||
writer.SerializeVector(storage.cells);
|
||||
writer.SerializeVector(storage.level_to_cell_offset);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,14 +33,13 @@ using MultiLevelPartitionView = detail::MultiLevelPartitionImpl<true>;
|
||||
namespace io
|
||||
{
|
||||
template <bool UseShareMemory>
|
||||
void read(const boost::filesystem::path &file,
|
||||
detail::MultiLevelPartitionImpl<UseShareMemory> &mlp);
|
||||
template <bool UseShareMemory>
|
||||
void write(const boost::filesystem::path &file,
|
||||
const detail::MultiLevelPartitionImpl<UseShareMemory> &mlp);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
}
|
||||
|
||||
using LevelID = std::uint8_t;
|
||||
using CellID = std::uint32_t;
|
||||
using PartitionID = std::uint64_t;
|
||||
@@ -141,6 +140,8 @@ template <bool UseShareMemory> class MultiLevelPartitionImpl final
|
||||
return cell_to_children[offset + cell + 1];
|
||||
}
|
||||
|
||||
friend void io::read<UseShareMemory>(const boost::filesystem::path &file,
|
||||
MultiLevelPartitionImpl &mlp);
|
||||
friend void io::write<UseShareMemory>(const boost::filesystem::path &file,
|
||||
const MultiLevelPartitionImpl &mlp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user