refactor and migrate root directory
This commit is contained in:
parent
fdd0c8470f
commit
c924b2067c
385
datastore.cpp
385
datastore.cpp
@ -53,7 +53,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int main( const int argc, const char * argv[] )
|
||||
int main(const int argc, const char *argv[])
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
SharedBarriers barrier;
|
||||
@ -66,108 +66,111 @@ int main( const int argc, const char * argv[] )
|
||||
}
|
||||
#endif
|
||||
|
||||
try {
|
||||
try {
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::named_mutex
|
||||
> pending_lock(barrier.pending_update_mutex);
|
||||
} catch(...) {
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> pending_lock(
|
||||
barrier.pending_update_mutex);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// hard unlock in case of any exception.
|
||||
barrier.pending_update_mutex.unlock();
|
||||
}
|
||||
} catch(const std::exception & e) {
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Checking input parameters";
|
||||
|
||||
ServerPaths server_paths;
|
||||
if(
|
||||
!GenerateDataStoreOptions(
|
||||
argc,
|
||||
argv,
|
||||
server_paths
|
||||
)
|
||||
) {
|
||||
if (!GenerateDataStoreOptions(argc, argv, server_paths))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if( server_paths.find("hsgrdata") == server_paths.end() ) {
|
||||
if (server_paths.find("hsgrdata") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no hsgr file found");
|
||||
}
|
||||
if( server_paths.find("ramindex") == server_paths.end() ) {
|
||||
if (server_paths.find("ramindex") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no ram index file found");
|
||||
}
|
||||
if( server_paths.find("fileindex") == server_paths.end() ) {
|
||||
if (server_paths.find("fileindex") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no leaf index file found");
|
||||
}
|
||||
if( server_paths.find("nodesdata") == server_paths.end() ) {
|
||||
if (server_paths.find("nodesdata") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no nodes file found");
|
||||
}
|
||||
if( server_paths.find("edgesdata") == server_paths.end() ) {
|
||||
if (server_paths.find("edgesdata") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no edges file found");
|
||||
}
|
||||
if( server_paths.find("namesdata") == server_paths.end() ) {
|
||||
if (server_paths.find("namesdata") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no names file found");
|
||||
}
|
||||
if( server_paths.find("geometry") == server_paths.end() ) {
|
||||
if (server_paths.find("geometry") == server_paths.end())
|
||||
{
|
||||
throw OSRMException("no geometry file found");
|
||||
}
|
||||
|
||||
ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||
const boost::filesystem::path & hsgr_path = paths_iterator->second;
|
||||
const boost::filesystem::path &hsgr_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("timestamp");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||
const boost::filesystem::path & timestamp_path = paths_iterator->second;
|
||||
const boost::filesystem::path ×tamp_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("ramindex");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||
const boost::filesystem::path & ram_index_path = paths_iterator->second;
|
||||
const boost::filesystem::path &ram_index_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("fileindex");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||
const boost::filesystem::path index_file_path_absolute = boost::filesystem::portable_canonical(paths_iterator->second);
|
||||
const std::string & file_index_file_name = index_file_path_absolute.string();
|
||||
const boost::filesystem::path index_file_path_absolute =
|
||||
boost::filesystem::portable_canonical(paths_iterator->second);
|
||||
const std::string &file_index_file_name = index_file_path_absolute.string();
|
||||
paths_iterator = server_paths.find("nodesdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||
const boost::filesystem::path & nodes_data_path = paths_iterator->second;
|
||||
const boost::filesystem::path &nodes_data_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("edgesdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||
const boost::filesystem::path & edges_data_path = paths_iterator->second;
|
||||
const boost::filesystem::path &edges_data_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("namesdata");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||
const boost::filesystem::path & names_data_path = paths_iterator->second;
|
||||
const boost::filesystem::path &names_data_path = paths_iterator->second;
|
||||
paths_iterator = server_paths.find("geometry");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||
const boost::filesystem::path & geometries_data_path = paths_iterator->second;
|
||||
const boost::filesystem::path &geometries_data_path = paths_iterator->second;
|
||||
|
||||
// get the shared memory segment to use
|
||||
bool use_first_segment = SharedMemory::RegionExists( LAYOUT_2 );
|
||||
SharedDataType LAYOUT = ( use_first_segment ? LAYOUT_1 : LAYOUT_2 );
|
||||
SharedDataType DATA = ( use_first_segment ? DATA_1 : DATA_2 );
|
||||
bool use_first_segment = SharedMemory::RegionExists(LAYOUT_2);
|
||||
SharedDataType LAYOUT = (use_first_segment ? LAYOUT_1 : LAYOUT_2);
|
||||
SharedDataType DATA = (use_first_segment ? DATA_1 : DATA_2);
|
||||
|
||||
// Allocate a memory layout in shared memory, deallocate previous
|
||||
SharedMemory * layout_memory = SharedMemoryFactory::Get(
|
||||
LAYOUT,
|
||||
sizeof(SharedDataLayout)
|
||||
);
|
||||
SharedDataLayout * shared_layout_ptr = static_cast<SharedDataLayout *>(
|
||||
layout_memory->Ptr()
|
||||
);
|
||||
shared_layout_ptr = new(layout_memory->Ptr()) SharedDataLayout();
|
||||
SharedMemory *layout_memory = SharedMemoryFactory::Get(LAYOUT, sizeof(SharedDataLayout));
|
||||
SharedDataLayout *shared_layout_ptr = static_cast<SharedDataLayout *>(layout_memory->Ptr());
|
||||
shared_layout_ptr = new (layout_memory->Ptr()) SharedDataLayout();
|
||||
|
||||
std::copy(
|
||||
file_index_file_name.begin(),
|
||||
(file_index_file_name.length() <= 1024 ? file_index_file_name.end() : file_index_file_name.begin()+1023),
|
||||
shared_layout_ptr->ram_index_file_name
|
||||
);
|
||||
std::copy(file_index_file_name.begin(),
|
||||
(file_index_file_name.length() <= 1024 ? file_index_file_name.end()
|
||||
: file_index_file_name.begin() + 1023),
|
||||
shared_layout_ptr->ram_index_file_name);
|
||||
// add zero termination
|
||||
unsigned end_of_string_index = std::min((std::size_t)1023, file_index_file_name.length());
|
||||
shared_layout_ptr->ram_index_file_name[end_of_string_index] = '\0';
|
||||
@ -175,38 +178,28 @@ int main( const int argc, const char * argv[] )
|
||||
// collect number of elements to store in shared memory object
|
||||
SimpleLogger().Write() << "load names from: " << names_data_path;
|
||||
// number of entries in name index
|
||||
boost::filesystem::ifstream name_stream(
|
||||
names_data_path, std::ios::binary
|
||||
);
|
||||
boost::filesystem::ifstream name_stream(names_data_path, std::ios::binary);
|
||||
unsigned name_index_size = 0;
|
||||
name_stream.read((char *)&name_index_size, sizeof(unsigned));
|
||||
shared_layout_ptr->name_index_list_size = name_index_size;
|
||||
SimpleLogger().Write() << "size: " << name_index_size;
|
||||
// SimpleLogger().Write() << "name index size: " << shared_layout_ptr->name_index_list_size;
|
||||
BOOST_ASSERT_MSG(0 != shared_layout_ptr->name_index_list_size, "name file broken");
|
||||
|
||||
unsigned number_of_chars = 0;
|
||||
name_stream.read((char *)&number_of_chars, sizeof(unsigned));
|
||||
shared_layout_ptr->name_char_list_size = number_of_chars;
|
||||
// SimpleLogger().Write() << "name char size: " << shared_layout_ptr->name_char_list_size;
|
||||
|
||||
//Loading information for original edges
|
||||
boost::filesystem::ifstream edges_input_stream(
|
||||
edges_data_path,
|
||||
std::ios::binary
|
||||
);
|
||||
// Loading information for original edges
|
||||
boost::filesystem::ifstream edges_input_stream(edges_data_path, std::ios::binary);
|
||||
unsigned number_of_original_edges = 0;
|
||||
edges_input_stream.read((char*)&number_of_original_edges, sizeof(unsigned));
|
||||
edges_input_stream.read((char *)&number_of_original_edges, sizeof(unsigned));
|
||||
|
||||
shared_layout_ptr->via_node_list_size = number_of_original_edges;
|
||||
shared_layout_ptr->name_id_list_size = number_of_original_edges;
|
||||
shared_layout_ptr->turn_instruction_list_size = number_of_original_edges;
|
||||
shared_layout_ptr->geometries_indicators = number_of_original_edges;
|
||||
|
||||
boost::filesystem::ifstream hsgr_input_stream(
|
||||
hsgr_path,
|
||||
std::ios::binary
|
||||
);
|
||||
boost::filesystem::ifstream hsgr_input_stream(hsgr_path, std::ios::binary);
|
||||
|
||||
UUID uuid_loaded, uuid_orig;
|
||||
hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID));
|
||||
@ -222,135 +215,111 @@ int main( const int argc, const char * argv[] )
|
||||
|
||||
// load checksum
|
||||
unsigned checksum = 0;
|
||||
hsgr_input_stream.read((char*)&checksum, sizeof(unsigned) );
|
||||
hsgr_input_stream.read((char *)&checksum, sizeof(unsigned));
|
||||
shared_layout_ptr->checksum = checksum;
|
||||
// load graph node size
|
||||
unsigned number_of_graph_nodes = 0;
|
||||
hsgr_input_stream.read(
|
||||
(char*) &number_of_graph_nodes,
|
||||
sizeof(unsigned)
|
||||
);
|
||||
hsgr_input_stream.read((char *)&number_of_graph_nodes, sizeof(unsigned));
|
||||
|
||||
BOOST_ASSERT_MSG(
|
||||
(0 != number_of_graph_nodes),
|
||||
"number of nodes is zero"
|
||||
);
|
||||
BOOST_ASSERT_MSG((0 != number_of_graph_nodes), "number of nodes is zero");
|
||||
shared_layout_ptr->graph_node_list_size = number_of_graph_nodes;
|
||||
|
||||
// load graph edge size
|
||||
unsigned number_of_graph_edges = 0;
|
||||
hsgr_input_stream.read( (char*) &number_of_graph_edges, sizeof(unsigned) );
|
||||
BOOST_ASSERT_MSG(
|
||||
0 != number_of_graph_edges,
|
||||
"number of graph edges is zero"
|
||||
);
|
||||
hsgr_input_stream.read((char *)&number_of_graph_edges, sizeof(unsigned));
|
||||
BOOST_ASSERT_MSG(0 != number_of_graph_edges, "number of graph edges is zero");
|
||||
shared_layout_ptr->graph_edge_list_size = number_of_graph_edges;
|
||||
|
||||
// load rsearch tree size
|
||||
boost::filesystem::ifstream tree_node_file(
|
||||
ram_index_path,
|
||||
std::ios::binary
|
||||
);
|
||||
boost::filesystem::ifstream tree_node_file(ram_index_path, std::ios::binary);
|
||||
|
||||
uint32_t tree_size = 0;
|
||||
tree_node_file.read((char*)&tree_size, sizeof(uint32_t));
|
||||
tree_node_file.read((char *)&tree_size, sizeof(uint32_t));
|
||||
shared_layout_ptr->r_search_tree_size = tree_size;
|
||||
|
||||
//load timestamp size
|
||||
// load timestamp size
|
||||
std::string m_timestamp;
|
||||
if( boost::filesystem::exists(timestamp_path) ) {
|
||||
boost::filesystem::ifstream timestampInStream( timestamp_path );
|
||||
if(!timestampInStream) {
|
||||
SimpleLogger().Write(logWARNING) <<
|
||||
timestamp_path << " not found. setting to default";
|
||||
} else {
|
||||
getline(timestampInStream, m_timestamp);
|
||||
timestampInStream.close();
|
||||
if (boost::filesystem::exists(timestamp_path))
|
||||
{
|
||||
boost::filesystem::ifstream timestamp_stream(timestamp_path);
|
||||
if (!timestamp_stream)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << timestamp_path
|
||||
<< " not found. setting to default";
|
||||
}
|
||||
else
|
||||
{
|
||||
getline(timestamp_stream, m_timestamp);
|
||||
timestamp_stream.close();
|
||||
}
|
||||
}
|
||||
if(m_timestamp.empty()) {
|
||||
if (m_timestamp.empty())
|
||||
{
|
||||
m_timestamp = "n/a";
|
||||
}
|
||||
if(25 < m_timestamp.length()) {
|
||||
if (25 < m_timestamp.length())
|
||||
{
|
||||
m_timestamp.resize(25);
|
||||
}
|
||||
shared_layout_ptr->timestamp_length = m_timestamp.length();
|
||||
|
||||
//load coordinate size
|
||||
boost::filesystem::ifstream nodes_input_stream(
|
||||
nodes_data_path,
|
||||
std::ios::binary
|
||||
);
|
||||
// load coordinate size
|
||||
boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary);
|
||||
unsigned coordinate_list_size = 0;
|
||||
nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned));
|
||||
shared_layout_ptr->coordinate_list_size = coordinate_list_size;
|
||||
|
||||
|
||||
// load geometries sizes
|
||||
std::ifstream geometry_input_stream(
|
||||
geometries_data_path.c_str(),
|
||||
std::ios::binary
|
||||
);
|
||||
std::ifstream geometry_input_stream(geometries_data_path.c_str(), std::ios::binary);
|
||||
unsigned number_of_geometries_indices = 0;
|
||||
unsigned number_of_compressed_geometries = 0;
|
||||
|
||||
geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned));
|
||||
shared_layout_ptr->geometries_index_list_size = number_of_geometries_indices;
|
||||
boost::iostreams::seek(geometry_input_stream, number_of_geometries_indices*sizeof(unsigned), BOOST_IOS::cur);
|
||||
geometry_input_stream.read( (char *)&number_of_compressed_geometries, sizeof(unsigned));
|
||||
boost::iostreams::seek(
|
||||
geometry_input_stream, number_of_geometries_indices * sizeof(unsigned), BOOST_IOS::cur);
|
||||
geometry_input_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned));
|
||||
shared_layout_ptr->geometries_list_size = number_of_compressed_geometries;
|
||||
|
||||
// allocate shared memory block
|
||||
SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes";
|
||||
SharedMemory * shared_memory = SharedMemoryFactory::Get(
|
||||
DATA,
|
||||
shared_layout_ptr->GetSizeOfLayout()
|
||||
);
|
||||
char * shared_memory_ptr = static_cast<char *>(shared_memory->Ptr());
|
||||
SimpleLogger().Write() << "allocating shared memory of "
|
||||
<< shared_layout_ptr->GetSizeOfLayout() << " bytes";
|
||||
SharedMemory *shared_memory =
|
||||
SharedMemoryFactory::Get(DATA, shared_layout_ptr->GetSizeOfLayout());
|
||||
char *shared_memory_ptr = static_cast<char *>(shared_memory->Ptr());
|
||||
|
||||
// read actual data into shared memory object //
|
||||
// Loading street names
|
||||
unsigned * name_index_ptr = (unsigned*)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetNameIndexOffset()
|
||||
);
|
||||
unsigned *name_index_ptr =
|
||||
(unsigned *)(shared_memory_ptr + shared_layout_ptr->GetNameIndexOffset());
|
||||
|
||||
name_stream.read(
|
||||
(char*)name_index_ptr,
|
||||
shared_layout_ptr->name_index_list_size*sizeof(unsigned)
|
||||
);
|
||||
name_stream.read((char *)name_index_ptr,
|
||||
shared_layout_ptr->name_index_list_size * sizeof(unsigned));
|
||||
|
||||
char * name_char_ptr = shared_memory_ptr + shared_layout_ptr->GetNameListOffset();
|
||||
name_stream.read(
|
||||
name_char_ptr,
|
||||
shared_layout_ptr->name_char_list_size*sizeof(char)
|
||||
);
|
||||
char *name_char_ptr = shared_memory_ptr + shared_layout_ptr->GetNameListOffset();
|
||||
name_stream.read(name_char_ptr, shared_layout_ptr->name_char_list_size * sizeof(char));
|
||||
name_stream.close();
|
||||
|
||||
//load original edge information
|
||||
NodeID * via_node_ptr = (NodeID *)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetViaNodeListOffset()
|
||||
);
|
||||
// load original edge information
|
||||
NodeID *via_node_ptr =
|
||||
(NodeID *)(shared_memory_ptr + shared_layout_ptr->GetViaNodeListOffset());
|
||||
|
||||
unsigned * name_id_ptr = (unsigned *)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetNameIDListOffset()
|
||||
);
|
||||
unsigned *name_id_ptr =
|
||||
(unsigned *)(shared_memory_ptr + shared_layout_ptr->GetNameIDListOffset());
|
||||
|
||||
TurnInstruction * turn_instructions_ptr = (TurnInstruction *)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetTurnInstructionListOffset()
|
||||
);
|
||||
TurnInstruction *turn_instructions_ptr =
|
||||
(TurnInstruction *)(shared_memory_ptr +
|
||||
shared_layout_ptr->GetTurnInstructionListOffset());
|
||||
|
||||
unsigned * geometries_indicator_ptr = (unsigned *)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetGeometriesIndicatorOffset()
|
||||
);
|
||||
unsigned *geometries_indicator_ptr =
|
||||
(unsigned *)(shared_memory_ptr + shared_layout_ptr->GetGeometriesIndicatorOffset());
|
||||
|
||||
OriginalEdgeData current_edge_data;
|
||||
for(unsigned i = 0; i < number_of_original_edges; ++i) {
|
||||
edges_input_stream.read(
|
||||
(char*)&(current_edge_data),
|
||||
sizeof(OriginalEdgeData)
|
||||
);
|
||||
for (unsigned i = 0; i < number_of_original_edges; ++i)
|
||||
{
|
||||
edges_input_stream.read((char *)&(current_edge_data), sizeof(OriginalEdgeData));
|
||||
via_node_ptr[i] = current_edge_data.via_node;
|
||||
name_id_ptr[i] = current_edge_data.name_id;
|
||||
name_id_ptr[i] = current_edge_data.name_id;
|
||||
turn_instructions_ptr[i] = current_edge_data.turn_instruction;
|
||||
|
||||
const unsigned bucket = i / 32;
|
||||
@ -365,125 +334,117 @@ int main( const int argc, const char * argv[] )
|
||||
|
||||
// load compressed geometry
|
||||
unsigned temporary_value;
|
||||
unsigned * geometries_index_ptr = (unsigned *)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetGeometriesIndexListOffset()
|
||||
);
|
||||
unsigned *geometries_index_ptr =
|
||||
(unsigned *)(shared_memory_ptr + shared_layout_ptr->GetGeometriesIndexListOffset());
|
||||
geometry_input_stream.seekg(0, geometry_input_stream.beg);
|
||||
geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned));
|
||||
BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_index_list_size);
|
||||
|
||||
geometry_input_stream.read(
|
||||
(char *)geometries_index_ptr,
|
||||
shared_layout_ptr->geometries_index_list_size*sizeof(unsigned)
|
||||
);
|
||||
geometry_input_stream.read((char *)geometries_index_ptr,
|
||||
shared_layout_ptr->geometries_index_list_size *
|
||||
sizeof(unsigned));
|
||||
|
||||
unsigned * geometries_list_ptr = (unsigned *)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetGeometryListOffset()
|
||||
);
|
||||
unsigned *geometries_list_ptr =
|
||||
(unsigned *)(shared_memory_ptr + shared_layout_ptr->GetGeometryListOffset());
|
||||
|
||||
geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned));
|
||||
BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_list_size);
|
||||
|
||||
geometry_input_stream.read(
|
||||
(char *)geometries_list_ptr,
|
||||
shared_layout_ptr->geometries_list_size*sizeof(unsigned)
|
||||
);
|
||||
geometry_input_stream.read((char *)geometries_list_ptr,
|
||||
shared_layout_ptr->geometries_list_size * sizeof(unsigned));
|
||||
|
||||
// Loading list of coordinates
|
||||
FixedPointCoordinate * coordinates_ptr = (FixedPointCoordinate *)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetCoordinateListOffset()
|
||||
);
|
||||
FixedPointCoordinate *coordinates_ptr =
|
||||
(FixedPointCoordinate *)(shared_memory_ptr +
|
||||
shared_layout_ptr->GetCoordinateListOffset());
|
||||
|
||||
NodeInfo current_node;
|
||||
for(unsigned i = 0; i < coordinate_list_size; ++i) {
|
||||
for (unsigned i = 0; i < coordinate_list_size; ++i)
|
||||
{
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo));
|
||||
coordinates_ptr[i] = FixedPointCoordinate(current_node.lat, current_node.lon);
|
||||
}
|
||||
nodes_input_stream.close();
|
||||
|
||||
//store timestamp
|
||||
char * timestamp_ptr = static_cast<char *>(
|
||||
shared_memory_ptr + shared_layout_ptr->GetTimeStampOffset()
|
||||
);
|
||||
std::copy(
|
||||
m_timestamp.c_str(),
|
||||
m_timestamp.c_str()+m_timestamp.length(),
|
||||
timestamp_ptr
|
||||
);
|
||||
// store timestamp
|
||||
char *timestamp_ptr =
|
||||
static_cast<char *>(shared_memory_ptr + shared_layout_ptr->GetTimeStampOffset());
|
||||
std::copy(m_timestamp.c_str(), m_timestamp.c_str() + m_timestamp.length(), timestamp_ptr);
|
||||
|
||||
// store search tree portion of rtree
|
||||
char * rtree_ptr = static_cast<char *>(
|
||||
shared_memory_ptr + shared_layout_ptr->GetRSearchTreeOffset()
|
||||
);
|
||||
char *rtree_ptr =
|
||||
static_cast<char *>(shared_memory_ptr + shared_layout_ptr->GetRSearchTreeOffset());
|
||||
|
||||
tree_node_file.read(rtree_ptr, sizeof(RTreeNode)*tree_size);
|
||||
tree_node_file.read(rtree_ptr, sizeof(RTreeNode) * tree_size);
|
||||
tree_node_file.close();
|
||||
|
||||
// load the nodes of the search graph
|
||||
QueryGraph::NodeArrayEntry * graph_node_list_ptr = (QueryGraph::NodeArrayEntry*)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetGraphNodeListOffset()
|
||||
);
|
||||
hsgr_input_stream.read(
|
||||
(char*) graph_node_list_ptr,
|
||||
shared_layout_ptr->graph_node_list_size*sizeof(QueryGraph::NodeArrayEntry)
|
||||
);
|
||||
QueryGraph::NodeArrayEntry *graph_node_list_ptr =
|
||||
(QueryGraph::NodeArrayEntry *)(shared_memory_ptr +
|
||||
shared_layout_ptr->GetGraphNodeListOffset());
|
||||
hsgr_input_stream.read((char *)graph_node_list_ptr,
|
||||
shared_layout_ptr->graph_node_list_size *
|
||||
sizeof(QueryGraph::NodeArrayEntry));
|
||||
|
||||
// load the edges of the search graph
|
||||
QueryGraph::EdgeArrayEntry * graph_edge_list_ptr = (QueryGraph::EdgeArrayEntry *)(
|
||||
shared_memory_ptr + shared_layout_ptr->GetGraphEdgeListOffset()
|
||||
);
|
||||
hsgr_input_stream.read(
|
||||
(char*) graph_edge_list_ptr,
|
||||
shared_layout_ptr->graph_edge_list_size*sizeof(QueryGraph::EdgeArrayEntry)
|
||||
);
|
||||
QueryGraph::EdgeArrayEntry *graph_edge_list_ptr =
|
||||
(QueryGraph::EdgeArrayEntry *)(shared_memory_ptr +
|
||||
shared_layout_ptr->GetGraphEdgeListOffset());
|
||||
hsgr_input_stream.read((char *)graph_edge_list_ptr,
|
||||
shared_layout_ptr->graph_edge_list_size *
|
||||
sizeof(QueryGraph::EdgeArrayEntry));
|
||||
hsgr_input_stream.close();
|
||||
|
||||
// acquire lock
|
||||
SharedMemory * data_type_memory = SharedMemoryFactory::Get(
|
||||
CURRENT_REGIONS,
|
||||
sizeof(SharedDataTimestamp),
|
||||
true,
|
||||
false
|
||||
);
|
||||
SharedDataTimestamp * data_timestamp_ptr = static_cast<SharedDataTimestamp*>(
|
||||
data_type_memory->Ptr()
|
||||
);
|
||||
SharedMemory *data_type_memory =
|
||||
SharedMemoryFactory::Get(CURRENT_REGIONS, sizeof(SharedDataTimestamp), true, false);
|
||||
SharedDataTimestamp *data_timestamp_ptr =
|
||||
static_cast<SharedDataTimestamp *>(data_type_memory->Ptr());
|
||||
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::named_mutex
|
||||
> query_lock(barrier.query_mutex);
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
|
||||
barrier.query_mutex);
|
||||
|
||||
// notify all processes that were waiting for this condition
|
||||
if (0 < barrier.number_of_queries) {
|
||||
if (0 < barrier.number_of_queries)
|
||||
{
|
||||
barrier.no_running_queries_condition.wait(query_lock);
|
||||
}
|
||||
|
||||
data_timestamp_ptr->layout = LAYOUT;
|
||||
data_timestamp_ptr->data = DATA;
|
||||
data_timestamp_ptr->timestamp +=1;
|
||||
if(use_first_segment) {
|
||||
BOOST_ASSERT( DATA == DATA_1 );
|
||||
BOOST_ASSERT( LAYOUT == LAYOUT_1 );
|
||||
if( !SharedMemory::Remove(DATA_2) ) {
|
||||
data_timestamp_ptr->timestamp += 1;
|
||||
if (use_first_segment)
|
||||
{
|
||||
BOOST_ASSERT(DATA == DATA_1);
|
||||
BOOST_ASSERT(LAYOUT == LAYOUT_1);
|
||||
if (!SharedMemory::Remove(DATA_2))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "could not delete DATA_2";
|
||||
}
|
||||
if( !SharedMemory::Remove(LAYOUT_2) ) {
|
||||
if (!SharedMemory::Remove(LAYOUT_2))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "could not delete LAYOUT_2";
|
||||
}
|
||||
} else {
|
||||
BOOST_ASSERT( DATA == DATA_2 );
|
||||
BOOST_ASSERT( LAYOUT == LAYOUT_2 );
|
||||
if( !SharedMemory::Remove(DATA_1) ) {
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ASSERT(DATA == DATA_2);
|
||||
BOOST_ASSERT(LAYOUT == LAYOUT_2);
|
||||
if (!SharedMemory::Remove(DATA_1))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "could not delete DATA_1";
|
||||
}
|
||||
if( !SharedMemory::Remove(LAYOUT_1) ) {
|
||||
if (!SharedMemory::Remove(LAYOUT_1))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "could not delete LAYOUT_1";
|
||||
}
|
||||
}
|
||||
SimpleLogger().Write() << "all data loaded";
|
||||
|
||||
shared_layout_ptr->PrintInformation();
|
||||
} catch(const std::exception & e) {
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
||||
}
|
||||
|
||||
|
146
extractor.cpp
146
extractor.cpp
@ -49,38 +49,46 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
ExtractorCallbacks * extractCallBacks;
|
||||
ExtractorCallbacks *extractor_callbacks;
|
||||
UUID uuid;
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
try {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
std::chrono::time_point<std::chrono::steady_clock> startup_time = std::chrono::steady_clock::now();
|
||||
std::chrono::time_point<std::chrono::steady_clock> startup_time =
|
||||
std::chrono::steady_clock::now();
|
||||
|
||||
boost::filesystem::path config_file_path, input_path, profile_path;
|
||||
int requested_num_threads;
|
||||
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
generic_options.add_options()
|
||||
("version,v", "Show version")
|
||||
("help,h", "Show this help message")
|
||||
("config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)->default_value("extractor.ini"),
|
||||
"Path to a configuration file.");
|
||||
generic_options.add_options()("version,v", "Show version")("help,h",
|
||||
"Show this help message")(
|
||||
"config,c",
|
||||
boost::program_options::value<boost::filesystem::path>(&config_file_path)
|
||||
->default_value("extractor.ini"),
|
||||
"Path to a configuration file.");
|
||||
|
||||
// declare a group of options that will be allowed both on command line and in config file
|
||||
boost::program_options::options_description config_options("Configuration");
|
||||
config_options.add_options()
|
||||
("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"),
|
||||
"Path to LUA routing profile")
|
||||
("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
|
||||
"Number of threads to use");
|
||||
config_options.add_options()("profile,p",
|
||||
boost::program_options::value<boost::filesystem::path>(
|
||||
&profile_path)->default_value("profile.lua"),
|
||||
"Path to LUA routing profile")(
|
||||
"threads,t",
|
||||
boost::program_options::value<int>(&requested_num_threads)->default_value(8),
|
||||
"Number of threads to use");
|
||||
|
||||
// hidden options, will be allowed both on command line and in config file, but will not be shown to the user
|
||||
// hidden options, will be allowed both on command line and in config file, but will not be
|
||||
// shown to the user
|
||||
boost::program_options::options_description hidden_options("Hidden options");
|
||||
hidden_options.add_options()
|
||||
("input,i", boost::program_options::value<boost::filesystem::path>(&input_path),
|
||||
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
||||
hidden_options.add_options()(
|
||||
"input,i",
|
||||
boost::program_options::value<boost::filesystem::path>(&input_path),
|
||||
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
||||
|
||||
// positional option
|
||||
boost::program_options::positional_options_description positional_options;
|
||||
@ -93,21 +101,25 @@ int main (int argc, char *argv[]) {
|
||||
boost::program_options::options_description config_file_options;
|
||||
config_file_options.add(config_options).add(hidden_options);
|
||||
|
||||
boost::program_options::options_description visible_options(boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
|
||||
boost::program_options::options_description visible_options(
|
||||
boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
|
||||
visible_options.add(generic_options).add(config_options);
|
||||
|
||||
// parse command line options
|
||||
boost::program_options::variables_map option_variables;
|
||||
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
|
||||
options(cmdline_options).positional(positional_options).run(), option_variables);
|
||||
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
||||
.options(cmdline_options)
|
||||
.positional(positional_options)
|
||||
.run(),
|
||||
option_variables);
|
||||
|
||||
if(option_variables.count("version"))
|
||||
if (option_variables.count("version"))
|
||||
{
|
||||
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(option_variables.count("help"))
|
||||
if (option_variables.count("help"))
|
||||
{
|
||||
SimpleLogger().Write() << visible_options;
|
||||
return 0;
|
||||
@ -116,37 +128,40 @@ int main (int argc, char *argv[]) {
|
||||
boost::program_options::notify(option_variables);
|
||||
|
||||
// parse config file
|
||||
if(boost::filesystem::is_regular_file(config_file_path))
|
||||
if (boost::filesystem::is_regular_file(config_file_path))
|
||||
{
|
||||
SimpleLogger().Write() << "Reading options from: " << config_file_path.string();
|
||||
std::string config_str;
|
||||
PrepareConfigFile(config_file_path.c_str(), config_str);
|
||||
std::stringstream config_stream( config_str );
|
||||
boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables);
|
||||
std::stringstream config_stream(config_str);
|
||||
boost::program_options::store(parse_config_file(config_stream, config_file_options),
|
||||
option_variables);
|
||||
boost::program_options::notify(option_variables);
|
||||
}
|
||||
|
||||
if(!option_variables.count("input"))
|
||||
if (!option_variables.count("input"))
|
||||
{
|
||||
SimpleLogger().Write() << visible_options;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(1 > requested_num_threads)
|
||||
if (1 > requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!boost::filesystem::is_regular_file(input_path))
|
||||
if (!boost::filesystem::is_regular_file(input_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string() << " not found!";
|
||||
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string()
|
||||
<< " not found!";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!boost::filesystem::is_regular_file(profile_path))
|
||||
if (!boost::filesystem::is_regular_file(profile_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string() << " not found!";
|
||||
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string()
|
||||
<< " not found!";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -154,29 +169,30 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
SimpleLogger().Write() << "Input file: " << input_path.filename().string();
|
||||
SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
|
||||
SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested " << requested_num_threads << ")";
|
||||
SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested "
|
||||
<< requested_num_threads << ")";
|
||||
|
||||
/*** Setup Scripting Environment ***/
|
||||
ScriptingEnvironment scriptingEnvironment(profile_path.c_str());
|
||||
ScriptingEnvironment scripting_environment(profile_path.c_str());
|
||||
|
||||
omp_set_num_threads(real_num_threads);
|
||||
|
||||
bool file_has_pbf_format(false);
|
||||
std::string output_file_name = input_path.string();
|
||||
std::string restrictionsFileName = input_path.string();
|
||||
std::string restriction_fileName = input_path.string();
|
||||
std::string::size_type pos = output_file_name.find(".osm.bz2");
|
||||
if(pos==std::string::npos)
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
pos = output_file_name.find(".osm.pbf");
|
||||
if (pos!=std::string::npos)
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
file_has_pbf_format = true;
|
||||
}
|
||||
}
|
||||
if (pos==std::string::npos)
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
pos = output_file_name.find(".pbf");
|
||||
if (pos!=std::string::npos)
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
file_has_pbf_format = true;
|
||||
}
|
||||
@ -187,67 +203,73 @@ int main (int argc, char *argv[]) {
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
output_file_name.append(".osrm");
|
||||
restrictionsFileName.append(".osrm.restrictions");
|
||||
restriction_fileName.append(".osrm.restrictions");
|
||||
}
|
||||
else
|
||||
{
|
||||
output_file_name.replace(pos, 5, ".osrm");
|
||||
restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
|
||||
restriction_fileName.replace(pos, 5, ".osrm.restrictions");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output_file_name.replace(pos, 8, ".osrm");
|
||||
restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
|
||||
restriction_fileName.replace(pos, 8, ".osrm.restrictions");
|
||||
}
|
||||
|
||||
boost::unordered_map<std::string, NodeID> stringMap;
|
||||
ExtractionContainers externalMemory;
|
||||
boost::unordered_map<std::string, NodeID> string_map;
|
||||
ExtractionContainers extraction_containers;
|
||||
|
||||
stringMap[""] = 0;
|
||||
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
|
||||
BaseParser* parser;
|
||||
if(file_has_pbf_format)
|
||||
string_map[""] = 0;
|
||||
extractor_callbacks = new ExtractorCallbacks(&extraction_containers, &string_map);
|
||||
BaseParser *parser;
|
||||
if (file_has_pbf_format)
|
||||
{
|
||||
parser = new PBFParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
|
||||
parser = new PBFParser(input_path.c_str(), extractor_callbacks, scripting_environment);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser = new XMLParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
|
||||
parser = new XMLParser(input_path.c_str(), extractor_callbacks, scripting_environment);
|
||||
}
|
||||
|
||||
if(!parser->ReadHeader())
|
||||
if (!parser->ReadHeader())
|
||||
{
|
||||
throw OSRMException("Parser not initialized!");
|
||||
}
|
||||
SimpleLogger().Write() << "Parsing in progress..";
|
||||
std::chrono::time_point<std::chrono::steady_clock> parsing_start_time = std::chrono::steady_clock::now();
|
||||
std::chrono::time_point<std::chrono::steady_clock> parsing_start_time =
|
||||
std::chrono::steady_clock::now();
|
||||
|
||||
parser->Parse();
|
||||
std::chrono::duration<double> parsing_duration = std::chrono::steady_clock::now() - parsing_start_time;
|
||||
SimpleLogger().Write() << "Parsing finished after " << parsing_duration.count() << " seconds";
|
||||
std::chrono::duration<double> parsing_duration =
|
||||
std::chrono::steady_clock::now() - parsing_start_time;
|
||||
SimpleLogger().Write() << "Parsing finished after " << parsing_duration.count()
|
||||
<< " seconds";
|
||||
|
||||
if (externalMemory.all_edges_list.empty())
|
||||
if (extraction_containers.all_edges_list.empty())
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
externalMemory.PrepareData(output_file_name, restrictionsFileName);
|
||||
extraction_containers.PrepareData(output_file_name, restriction_fileName);
|
||||
|
||||
delete parser;
|
||||
delete extractCallBacks;
|
||||
delete extractor_callbacks;
|
||||
|
||||
std::chrono::duration<double> extraction_duration = std::chrono::steady_clock::now() - startup_time;
|
||||
SimpleLogger().Write() << "extraction finished after " << extraction_duration.count() << "s";
|
||||
SimpleLogger().Write() << "To prepare the data for routing, run: " << "./osrm-prepare " << output_file_name << std::endl;
|
||||
std::chrono::duration<double> extraction_duration =
|
||||
std::chrono::steady_clock::now() - startup_time;
|
||||
SimpleLogger().Write() << "extraction finished after " << extraction_duration.count()
|
||||
<< "s";
|
||||
SimpleLogger().Write() << "To prepare the data for routing, run: "
|
||||
<< "./osrm-prepare " << output_file_name << std::endl;
|
||||
}
|
||||
catch(boost::program_options::too_many_positional_options_error& e)
|
||||
catch (boost::program_options::too_many_positional_options_error &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Only one input file can be specified";
|
||||
return 1;
|
||||
}
|
||||
catch(std::exception & e)
|
||||
catch (std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what();
|
||||
return 1;
|
||||
|
436
prepare.cpp
436
prepare.cpp
@ -56,43 +56,53 @@ typedef QueryEdge::EdgeData EdgeData;
|
||||
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
|
||||
typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
|
||||
|
||||
std::vector<NodeInfo> internalToExternalNodeMapping;
|
||||
std::vector<TurnRestriction> inputRestrictions;
|
||||
std::vector<NodeID> bollardNodes;
|
||||
std::vector<NodeID> trafficLightNodes;
|
||||
std::vector<ImportEdge> edgeList;
|
||||
std::vector<NodeInfo> internal_to_external_node_map;
|
||||
std::vector<TurnRestriction> restriction_list;
|
||||
std::vector<NodeID> barrier_node_list;
|
||||
std::vector<NodeID> traffic_light_list;
|
||||
std::vector<ImportEdge> edge_list;
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
try {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
std::chrono::time_point<std::chrono::steady_clock> startupTime = std::chrono::steady_clock::now();
|
||||
std::chrono::time_point<std::chrono::steady_clock> startup_time =
|
||||
std::chrono::steady_clock::now();
|
||||
|
||||
boost::filesystem::path config_file_path, input_path, restrictions_path, profile_path;
|
||||
int requested_num_threads;
|
||||
|
||||
// declare a group of options that will be allowed only on command line
|
||||
boost::program_options::options_description generic_options("Options");
|
||||
generic_options.add_options()
|
||||
("version,v", "Show version")
|
||||
("help,h", "Show this help message")
|
||||
("config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)->default_value("contractor.ini"),
|
||||
"Path to a configuration file.");
|
||||
generic_options.add_options()("version,v", "Show version")("help,h",
|
||||
"Show this help message")(
|
||||
"config,c",
|
||||
boost::program_options::value<boost::filesystem::path>(&config_file_path)
|
||||
->default_value("contractor.ini"),
|
||||
"Path to a configuration file.");
|
||||
|
||||
// declare a group of options that will be allowed both on command line and in config file
|
||||
boost::program_options::options_description config_options("Configuration");
|
||||
config_options.add_options()
|
||||
("restrictions,r", boost::program_options::value<boost::filesystem::path>(&restrictions_path),
|
||||
"Restrictions file in .osrm.restrictions format")
|
||||
("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"),
|
||||
"Path to LUA routing profile")
|
||||
("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
|
||||
"Number of threads to use");
|
||||
config_options.add_options()(
|
||||
"restrictions,r",
|
||||
boost::program_options::value<boost::filesystem::path>(&restrictions_path),
|
||||
"Restrictions file in .osrm.restrictions format")(
|
||||
"profile,p",
|
||||
boost::program_options::value<boost::filesystem::path>(&profile_path)
|
||||
->default_value("profile.lua"),
|
||||
"Path to LUA routing profile")(
|
||||
"threads,t",
|
||||
boost::program_options::value<int>(&requested_num_threads)->default_value(8),
|
||||
"Number of threads to use");
|
||||
|
||||
// hidden options, will be allowed both on command line and in config file, but will not be shown to the user
|
||||
// hidden options, will be allowed both on command line and in config file, but will not be
|
||||
// shown to the user
|
||||
boost::program_options::options_description hidden_options("Hidden options");
|
||||
hidden_options.add_options()
|
||||
("input,i", boost::program_options::value<boost::filesystem::path>(&input_path),
|
||||
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
||||
hidden_options.add_options()(
|
||||
"input,i",
|
||||
boost::program_options::value<boost::filesystem::path>(&input_path),
|
||||
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
||||
|
||||
// positional option
|
||||
boost::program_options::positional_options_description positional_options;
|
||||
@ -105,46 +115,59 @@ int main (int argc, char *argv[]) {
|
||||
boost::program_options::options_description config_file_options;
|
||||
config_file_options.add(config_options).add(hidden_options);
|
||||
|
||||
boost::program_options::options_description visible_options("Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]");
|
||||
boost::program_options::options_description visible_options(
|
||||
"Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]");
|
||||
visible_options.add(generic_options).add(config_options);
|
||||
|
||||
// parse command line options
|
||||
boost::program_options::variables_map option_variables;
|
||||
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
|
||||
options(cmdline_options).positional(positional_options).run(), option_variables);
|
||||
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
||||
.options(cmdline_options)
|
||||
.positional(positional_options)
|
||||
.run(),
|
||||
option_variables);
|
||||
|
||||
if(option_variables.count("version")) {
|
||||
if (option_variables.count("version"))
|
||||
{
|
||||
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(option_variables.count("help")) {
|
||||
if (option_variables.count("help"))
|
||||
{
|
||||
SimpleLogger().Write() << "\n" << visible_options;
|
||||
return 0;
|
||||
}
|
||||
|
||||
boost::program_options::notify(option_variables);
|
||||
|
||||
if(!option_variables.count("restrictions")) {
|
||||
if (!option_variables.count("restrictions"))
|
||||
{
|
||||
restrictions_path = std::string(input_path.string() + ".restrictions");
|
||||
}
|
||||
|
||||
if(!option_variables.count("input")) {
|
||||
if (!option_variables.count("input"))
|
||||
{
|
||||
SimpleLogger().Write() << "\n" << visible_options;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!boost::filesystem::is_regular_file(input_path)) {
|
||||
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string() << " not found!";
|
||||
if (!boost::filesystem::is_regular_file(input_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string()
|
||||
<< " not found!";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!boost::filesystem::is_regular_file(profile_path)) {
|
||||
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string() << " not found!";
|
||||
if (!boost::filesystem::is_regular_file(profile_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string()
|
||||
<< " not found!";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(1 > requested_num_threads) {
|
||||
if (1 > requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
||||
return 1;
|
||||
}
|
||||
@ -154,286 +177,305 @@ int main (int argc, char *argv[]) {
|
||||
SimpleLogger().Write() << "Input file: " << input_path.filename().string();
|
||||
SimpleLogger().Write() << "Restrictions file: " << restrictions_path.filename().string();
|
||||
SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
|
||||
SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested " << requested_num_threads << ")";
|
||||
SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested "
|
||||
<< requested_num_threads << ")";
|
||||
|
||||
omp_set_num_threads(real_num_threads);
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
boost::filesystem::ifstream restrictionsInstream(restrictions_path, std::ios::binary);
|
||||
boost::filesystem::ifstream restriction_stream(restrictions_path, std::ios::binary);
|
||||
TurnRestriction restriction;
|
||||
UUID uuid_loaded, uuid_orig;
|
||||
unsigned usableRestrictionsCounter(0);
|
||||
restrictionsInstream.read((char*)&uuid_loaded, sizeof(UUID));
|
||||
if( !uuid_loaded.TestPrepare(uuid_orig) ) {
|
||||
SimpleLogger().Write(logWARNING) <<
|
||||
".restrictions was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning.";
|
||||
unsigned number_of_usable_restrictions = 0;
|
||||
restriction_stream.read((char *)&uuid_loaded, sizeof(UUID));
|
||||
if (!uuid_loaded.TestPrepare(uuid_orig))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << ".restrictions was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
restrictionsInstream.read(
|
||||
(char*)&usableRestrictionsCounter,
|
||||
sizeof(unsigned)
|
||||
);
|
||||
inputRestrictions.resize(usableRestrictionsCounter);
|
||||
restrictionsInstream.read(
|
||||
(char *)&(inputRestrictions[0]),
|
||||
usableRestrictionsCounter*sizeof(TurnRestriction)
|
||||
);
|
||||
restrictionsInstream.close();
|
||||
restriction_stream.read((char *)&number_of_usable_restrictions, sizeof(unsigned));
|
||||
restriction_list.resize(number_of_usable_restrictions);
|
||||
restriction_stream.read((char *)&(restriction_list[0]),
|
||||
number_of_usable_restrictions * sizeof(TurnRestriction));
|
||||
restriction_stream.close();
|
||||
|
||||
boost::filesystem::ifstream in;
|
||||
in.open(input_path, std::ios::in|std::ios::binary);
|
||||
in.open(input_path, std::ios::in | std::ios::binary);
|
||||
|
||||
const std::string nodeOut = input_path.string() + ".nodes";
|
||||
const std::string edgeOut = input_path.string() + ".edges";
|
||||
const std::string node_filename = input_path.string() + ".nodes";
|
||||
const std::string edge_out = input_path.string() + ".edges";
|
||||
const std::string geometry_filename = input_path.string() + ".geometry";
|
||||
const std::string graphOut = input_path.string() + ".hsgr";
|
||||
const std::string rtree_nodes_path = input_path.string() + ".ramIndex";
|
||||
const std::string rtree_leafs_path = input_path.string() + ".fileIndex";
|
||||
const std::string graphOut = input_path.string() + ".hsgr";
|
||||
const std::string rtree_nodes_path = input_path.string() + ".ramIndex";
|
||||
const std::string rtree_leafs_path = input_path.string() + ".fileIndex";
|
||||
|
||||
/*** Setup Scripting Environment ***/
|
||||
|
||||
// Create a new lua state
|
||||
lua_State *myLuaState = luaL_newstate();
|
||||
lua_State *lua_state = luaL_newstate();
|
||||
|
||||
// Connect LuaBind to this lua state
|
||||
luabind::open(myLuaState);
|
||||
luabind::open(lua_state);
|
||||
|
||||
//open utility libraries string library;
|
||||
luaL_openlibs(myLuaState);
|
||||
// open utility libraries string library;
|
||||
luaL_openlibs(lua_state);
|
||||
|
||||
//adjust lua load path
|
||||
luaAddScriptFolderToLoadPath( myLuaState, profile_path.c_str() );
|
||||
// adjust lua load path
|
||||
luaAddScriptFolderToLoadPath(lua_state, profile_path.c_str());
|
||||
|
||||
// Now call our function in a lua script
|
||||
if(0 != luaL_dofile(myLuaState, profile_path.c_str() )) {
|
||||
std::cerr <<
|
||||
lua_tostring(myLuaState,-1) <<
|
||||
" occured in scripting block" <<
|
||||
std::endl;
|
||||
}
|
||||
|
||||
EdgeBasedGraphFactory::SpeedProfileProperties speedProfile;
|
||||
|
||||
if(0 != luaL_dostring( myLuaState, "return traffic_signal_penalty\n")) {
|
||||
std::cerr << lua_tostring(myLuaState,-1) << " occured in scripting block" << std::endl;
|
||||
if (0 != luaL_dofile(lua_state, profile_path.c_str()))
|
||||
{
|
||||
std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
speedProfile.trafficSignalPenalty = 10*lua_tointeger(myLuaState, -1);
|
||||
SimpleLogger().Write(logDEBUG) << "traffic_signal_penalty: " << speedProfile.trafficSignalPenalty;
|
||||
|
||||
if(0 != luaL_dostring( myLuaState, "return u_turn_penalty\n")) {
|
||||
std::cerr <<
|
||||
lua_tostring(myLuaState,-1) <<
|
||||
" occured in scripting block" <<
|
||||
std::endl;
|
||||
EdgeBasedGraphFactory::SpeedProfileProperties speed_profile;
|
||||
|
||||
if (0 != luaL_dostring(lua_state, "return traffic_signal_penalty\n"))
|
||||
{
|
||||
std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
speedProfile.uTurnPenalty = 10*lua_tointeger(myLuaState, -1);
|
||||
speed_profile.trafficSignalPenalty = 10 * lua_tointeger(lua_state, -1);
|
||||
SimpleLogger().Write(logDEBUG)
|
||||
<< "traffic_signal_penalty: " << speed_profile.trafficSignalPenalty;
|
||||
|
||||
speedProfile.has_turn_penalty_function = lua_function_exists( myLuaState, "turn_function" );
|
||||
if (0 != luaL_dostring(lua_state, "return u_turn_penalty\n"))
|
||||
{
|
||||
std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
speed_profile.uTurnPenalty = 10 * lua_tointeger(lua_state, -1);
|
||||
|
||||
std::vector<ImportEdge> edgeList;
|
||||
NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions);
|
||||
speed_profile.has_turn_penalty_function = lua_function_exists(lua_state, "turn_function");
|
||||
|
||||
std::vector<ImportEdge> edge_list;
|
||||
NodeID number_of_node_based_nodes = readBinaryOSRMGraphFromStream(in,
|
||||
edge_list,
|
||||
barrier_node_list,
|
||||
traffic_light_list,
|
||||
&internal_to_external_node_map,
|
||||
restriction_list);
|
||||
in.close();
|
||||
|
||||
if( edgeList.empty() ) {
|
||||
if (edge_list.empty())
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
SimpleLogger().Write() <<
|
||||
inputRestrictions.size() << " restrictions, " <<
|
||||
bollardNodes.size() << " bollard nodes, " <<
|
||||
trafficLightNodes.size() << " traffic lights";
|
||||
SimpleLogger().Write() << restriction_list.size() << " restrictions, "
|
||||
<< barrier_node_list.size() << " bollard nodes, "
|
||||
<< traffic_light_list.size() << " traffic lights";
|
||||
|
||||
/***
|
||||
* Building an edge-expanded graph from node-based input and turn restrictions
|
||||
*/
|
||||
|
||||
SimpleLogger().Write() << "Generating edge-expanded graph representation";
|
||||
EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile);
|
||||
std::vector<ImportEdge>().swap(edgeList);
|
||||
edgeBasedGraphFactory->Run(edgeOut,geometry_filename, myLuaState);
|
||||
std::vector<TurnRestriction>().swap(inputRestrictions);
|
||||
std::vector<NodeID>().swap(bollardNodes);
|
||||
std::vector<NodeID>().swap(trafficLightNodes);
|
||||
unsigned edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfEdgeBasedNodes();
|
||||
BOOST_ASSERT(
|
||||
edgeBasedNodeNumber != std::numeric_limits<unsigned>::max()
|
||||
);
|
||||
DeallocatingVector<EdgeBasedEdge> edgeBasedEdgeList;
|
||||
edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList);
|
||||
std::vector<EdgeBasedNode> nodeBasedEdgeList;
|
||||
edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList);
|
||||
delete edgeBasedGraphFactory;
|
||||
EdgeBasedGraphFactory *edge_based_graph_factor =
|
||||
new EdgeBasedGraphFactory(number_of_node_based_nodes,
|
||||
edge_list,
|
||||
barrier_node_list,
|
||||
traffic_light_list,
|
||||
restriction_list,
|
||||
internal_to_external_node_map,
|
||||
speed_profile);
|
||||
edge_list.clear();
|
||||
edge_list.shrink_to_fit();
|
||||
|
||||
std::chrono::duration<double> expansionHasFinishedTime = std::chrono::steady_clock::now() - startupTime;
|
||||
edge_based_graph_factor->Run(edge_out, geometry_filename, lua_state);
|
||||
|
||||
restriction_list.clear();
|
||||
restriction_list.shrink_to_fit();
|
||||
barrier_node_list.clear();
|
||||
barrier_node_list.shrink_to_fit();
|
||||
traffic_light_list.clear();
|
||||
traffic_light_list.shrink_to_fit();
|
||||
|
||||
unsigned number_of_edge_based_nodes = edge_based_graph_factor->GetNumberOfEdgeBasedNodes();
|
||||
BOOST_ASSERT(number_of_edge_based_nodes != std::numeric_limits<unsigned>::max());
|
||||
DeallocatingVector<EdgeBasedEdge> edgeBasedEdgeList;
|
||||
edge_based_graph_factor->GetEdgeBasedEdges(edgeBasedEdgeList);
|
||||
std::vector<EdgeBasedNode> node_based_edge_list;
|
||||
edge_based_graph_factor->GetEdgeBasedNodes(node_based_edge_list);
|
||||
delete edge_based_graph_factor;
|
||||
|
||||
std::chrono::duration<double> end_of_expansion_time =
|
||||
std::chrono::steady_clock::now() - startup_time;
|
||||
|
||||
// Building grid-like nearest-neighbor data structure
|
||||
SimpleLogger().Write() << "building r-tree ...";
|
||||
StaticRTree<EdgeBasedNode> * rtree =
|
||||
new StaticRTree<EdgeBasedNode>(
|
||||
nodeBasedEdgeList,
|
||||
rtree_nodes_path.c_str(),
|
||||
rtree_leafs_path.c_str(),
|
||||
internalToExternalNodeMapping
|
||||
);
|
||||
StaticRTree<EdgeBasedNode> *rtree =
|
||||
new StaticRTree<EdgeBasedNode>(node_based_edge_list,
|
||||
rtree_nodes_path.c_str(),
|
||||
rtree_leafs_path.c_str(),
|
||||
internal_to_external_node_map);
|
||||
delete rtree;
|
||||
IteratorbasedCRC32<std::vector<EdgeBasedNode> > crc32;
|
||||
unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() );
|
||||
nodeBasedEdgeList.clear();
|
||||
std::vector<EdgeBasedNode>(nodeBasedEdgeList).swap(nodeBasedEdgeList);
|
||||
SimpleLogger().Write() << "CRC32: " << crc32OfNodeBasedEdgeList;
|
||||
IteratorbasedCRC32<std::vector<EdgeBasedNode>> crc32;
|
||||
unsigned node_based_edge_list_CRC32 =
|
||||
crc32(node_based_edge_list.begin(), node_based_edge_list.end());
|
||||
node_based_edge_list.clear();
|
||||
node_based_edge_list.shrink_to_fit();
|
||||
SimpleLogger().Write() << "CRC32: " << node_based_edge_list_CRC32;
|
||||
|
||||
/***
|
||||
* Writing info on original (node-based) nodes
|
||||
*/
|
||||
|
||||
SimpleLogger().Write() << "writing node map ...";
|
||||
boost::filesystem::ofstream mapOutFile(nodeOut, std::ios::binary);
|
||||
const unsigned size_of_mapping = internalToExternalNodeMapping.size();
|
||||
mapOutFile.write((char *)&size_of_mapping, sizeof(unsigned));
|
||||
mapOutFile.write(
|
||||
(char *)&(internalToExternalNodeMapping[0]),
|
||||
size_of_mapping*sizeof(NodeInfo)
|
||||
);
|
||||
mapOutFile.close();
|
||||
std::vector<NodeInfo>().swap(internalToExternalNodeMapping);
|
||||
boost::filesystem::ofstream node_stream(node_filename, std::ios::binary);
|
||||
const unsigned size_of_mapping = internal_to_external_node_map.size();
|
||||
node_stream.write((char *)&size_of_mapping, sizeof(unsigned));
|
||||
node_stream.write((char *)&(internal_to_external_node_map[0]),
|
||||
size_of_mapping * sizeof(NodeInfo));
|
||||
node_stream.close();
|
||||
internal_to_external_node_map.clear();
|
||||
internal_to_external_node_map.shrink_to_fit();
|
||||
|
||||
/***
|
||||
* Contracting the edge-expanded graph
|
||||
*/
|
||||
|
||||
SimpleLogger().Write() << "initializing contractor";
|
||||
Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList );
|
||||
std::chrono::time_point<std::chrono::steady_clock> contraction_start_timestamp = std::chrono::steady_clock::now();
|
||||
Contractor *contractor = new Contractor(number_of_edge_based_nodes, edgeBasedEdgeList);
|
||||
std::chrono::time_point<std::chrono::steady_clock> contraction_start_timestamp =
|
||||
std::chrono::steady_clock::now();
|
||||
|
||||
contractor->Run();
|
||||
std::chrono::duration<double> contraction_duration = std::chrono::steady_clock::now() - contraction_start_timestamp;
|
||||
SimpleLogger().Write() <<
|
||||
"Contraction took " <<
|
||||
contraction_duration.count() <<
|
||||
" sec";
|
||||
std::chrono::duration<double> contraction_duration =
|
||||
std::chrono::steady_clock::now() - contraction_start_timestamp;
|
||||
SimpleLogger().Write() << "Contraction took " << contraction_duration.count() << " sec";
|
||||
|
||||
DeallocatingVector< QueryEdge > contractedEdgeList;
|
||||
contractor->GetEdges( contractedEdgeList );
|
||||
DeallocatingVector<QueryEdge> contracted_edge_list;
|
||||
contractor->GetEdges(contracted_edge_list);
|
||||
delete contractor;
|
||||
|
||||
/***
|
||||
* Sorting contracted edges in a way that the static query graph can read some in in-place.
|
||||
*/
|
||||
|
||||
std::sort(contractedEdgeList.begin(), contractedEdgeList.end());
|
||||
std::sort(contracted_edge_list.begin(), contracted_edge_list.end());
|
||||
unsigned max_used_node_id = 0;
|
||||
unsigned contracted_edge_count = contractedEdgeList.size();
|
||||
SimpleLogger().Write() <<
|
||||
"Serializing compacted graph of " <<
|
||||
contracted_edge_count <<
|
||||
" edges";
|
||||
unsigned contracted_edge_count = contracted_edge_list.size();
|
||||
SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count
|
||||
<< " edges";
|
||||
|
||||
boost::filesystem::ofstream hsgr_output_stream(graphOut, std::ios::binary);
|
||||
hsgr_output_stream.write((char*)&uuid_orig, sizeof(UUID) );
|
||||
for (const QueryEdge & edge : contractedEdgeList)
|
||||
hsgr_output_stream.write((char *)&uuid_orig, sizeof(UUID));
|
||||
for (const QueryEdge &edge : contracted_edge_list)
|
||||
{
|
||||
BOOST_ASSERT( UINT_MAX != edge.source );
|
||||
BOOST_ASSERT( UINT_MAX != edge.target );
|
||||
BOOST_ASSERT(UINT_MAX != edge.source);
|
||||
BOOST_ASSERT(UINT_MAX != edge.target);
|
||||
|
||||
max_used_node_id = std::max(max_used_node_id, edge.source);
|
||||
max_used_node_id = std::max(max_used_node_id, edge.target);
|
||||
}
|
||||
SimpleLogger().Write(logDEBUG) << "input graph has " << edgeBasedNodeNumber << " nodes";
|
||||
SimpleLogger().Write(logDEBUG) << "input graph has " << number_of_edge_based_nodes << " nodes";
|
||||
SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes";
|
||||
max_used_node_id+=1;
|
||||
max_used_node_id += 1;
|
||||
|
||||
std::vector< StaticGraph<EdgeData>::NodeArrayEntry > node_array;
|
||||
node_array.resize( edgeBasedNodeNumber + 1);
|
||||
std::vector<StaticGraph<EdgeData>::NodeArrayEntry> node_array;
|
||||
node_array.resize(number_of_edge_based_nodes + 1);
|
||||
|
||||
SimpleLogger().Write() << "Building node array";
|
||||
StaticGraph<EdgeData>::EdgeIterator edge = 0;
|
||||
StaticGraph<EdgeData>::EdgeIterator position = 0;
|
||||
StaticGraph<EdgeData>::EdgeIterator lastEdge = edge;
|
||||
|
||||
for ( StaticGraph<EdgeData>::NodeIterator node = 0; node < max_used_node_id; ++node)
|
||||
for (StaticGraph<EdgeData>::NodeIterator node = 0; node < max_used_node_id; ++node)
|
||||
{
|
||||
lastEdge = edge;
|
||||
while ((edge < contracted_edge_count) && (contractedEdgeList[edge].source == node))
|
||||
while ((edge < contracted_edge_count) && (contracted_edge_list[edge].source == node))
|
||||
{
|
||||
++edge;
|
||||
}
|
||||
node_array[node].firstEdge = position; //=edge
|
||||
position += edge - lastEdge; //remove
|
||||
position += edge - lastEdge; // remove
|
||||
}
|
||||
|
||||
for (unsigned sentinel_counter = max_used_node_id;
|
||||
sentinel_counter != node_array.size();
|
||||
++sentinel_counter
|
||||
)
|
||||
for (unsigned sentinel_counter = max_used_node_id; sentinel_counter != node_array.size();
|
||||
++sentinel_counter)
|
||||
{
|
||||
//sentinel element, guarded against underflow
|
||||
// sentinel element, guarded against underflow
|
||||
node_array[sentinel_counter].firstEdge = contracted_edge_count;
|
||||
}
|
||||
|
||||
unsigned node_array_size = node_array.size();
|
||||
//serialize crc32, aka checksum
|
||||
hsgr_output_stream.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned));
|
||||
//serialize number of nodes
|
||||
hsgr_output_stream.write((char*) &node_array_size, sizeof(unsigned));
|
||||
//serialize number of edges
|
||||
hsgr_output_stream.write((char*) &contracted_edge_count, sizeof(unsigned));
|
||||
//serialize all nodes
|
||||
hsgr_output_stream.write((char*) &node_array[0], sizeof(StaticGraph<EdgeData>::NodeArrayEntry)*node_array_size);
|
||||
//serialize all edges
|
||||
// serialize crc32, aka checksum
|
||||
hsgr_output_stream.write((char *)&node_based_edge_list_CRC32, sizeof(unsigned));
|
||||
// serialize number of nodes
|
||||
hsgr_output_stream.write((char *)&node_array_size, sizeof(unsigned));
|
||||
// serialize number of edges
|
||||
hsgr_output_stream.write((char *)&contracted_edge_count, sizeof(unsigned));
|
||||
// serialize all nodes
|
||||
hsgr_output_stream.write((char *)&node_array[0],
|
||||
sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size);
|
||||
// serialize all edges
|
||||
|
||||
SimpleLogger().Write() << "Building edge array";
|
||||
edge = 0;
|
||||
int usedEdgeCounter = 0;
|
||||
int number_of_used_edges = 0;
|
||||
|
||||
StaticGraph<EdgeData>::EdgeArrayEntry currentEdge;
|
||||
for (unsigned edge = 0; edge < contractedEdgeList.size(); ++edge)
|
||||
StaticGraph<EdgeData>::EdgeArrayEntry current_edge;
|
||||
for (unsigned edge = 0; edge < contracted_edge_list.size(); ++edge)
|
||||
{
|
||||
// no eigen loops
|
||||
BOOST_ASSERT(contractedEdgeList[edge].source != contractedEdgeList[edge].target);
|
||||
currentEdge.target = contractedEdgeList[edge].target;
|
||||
currentEdge.data = contractedEdgeList[edge].data;
|
||||
BOOST_ASSERT(contracted_edge_list[edge].source != contracted_edge_list[edge].target);
|
||||
current_edge.target = contracted_edge_list[edge].target;
|
||||
current_edge.data = contracted_edge_list[edge].data;
|
||||
|
||||
// every target needs to be valid
|
||||
BOOST_ASSERT(currentEdge.target < max_used_node_id);
|
||||
if(currentEdge.data.distance <= 0) {
|
||||
SimpleLogger().Write(logWARNING) <<
|
||||
"Edge: " << edge <<
|
||||
",source: " << contractedEdgeList[edge].source <<
|
||||
", target: " << contractedEdgeList[edge].target <<
|
||||
", dist: " << currentEdge.data.distance;
|
||||
BOOST_ASSERT(current_edge.target < max_used_node_id);
|
||||
if (current_edge.data.distance <= 0)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Edge: " << edge
|
||||
<< ",source: " << contracted_edge_list[edge].source
|
||||
<< ", target: " << contracted_edge_list[edge].target
|
||||
<< ", dist: " << current_edge.data.distance;
|
||||
|
||||
SimpleLogger().Write(logWARNING) <<
|
||||
"Failed at adjacency list of node " << contractedEdgeList[edge].source << "/" << node_array.size()-1;
|
||||
SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node "
|
||||
<< contracted_edge_list[edge].source << "/"
|
||||
<< node_array.size() - 1;
|
||||
return 1;
|
||||
}
|
||||
hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph<EdgeData>::EdgeArrayEntry));
|
||||
++usedEdgeCounter;
|
||||
hsgr_output_stream.write((char *)¤t_edge,
|
||||
sizeof(StaticGraph<EdgeData>::EdgeArrayEntry));
|
||||
++number_of_used_edges;
|
||||
}
|
||||
hsgr_output_stream.close();
|
||||
|
||||
std::chrono::duration<double> entire_duration = std::chrono::steady_clock::now() - startupTime;
|
||||
std::chrono::duration<double> entire_duration =
|
||||
std::chrono::steady_clock::now() - startup_time;
|
||||
|
||||
SimpleLogger().Write() << "Preprocessing : " << entire_duration.count() << " seconds";
|
||||
SimpleLogger().Write() << "Expansion : " <<
|
||||
(nodeBasedNodeNumber/expansionHasFinishedTime.count()) << " nodes/sec and " <<
|
||||
(edgeBasedNodeNumber/expansionHasFinishedTime.count()) << " edges/sec";
|
||||
SimpleLogger().Write() << "Expansion : "
|
||||
<< (number_of_node_based_nodes / end_of_expansion_time.count())
|
||||
<< " nodes/sec and "
|
||||
<< (number_of_edge_based_nodes / end_of_expansion_time.count())
|
||||
<< " edges/sec";
|
||||
|
||||
SimpleLogger().Write() << "Contraction: " <<
|
||||
(edgeBasedNodeNumber/contraction_duration.count()) << " nodes/sec and " <<
|
||||
usedEdgeCounter/contraction_duration.count() << " edges/sec";
|
||||
SimpleLogger().Write() << "Contraction: "
|
||||
<< (number_of_edge_based_nodes / contraction_duration.count())
|
||||
<< " nodes/sec and "
|
||||
<< number_of_used_edges / contraction_duration.count() << " edges/sec";
|
||||
|
||||
node_array.clear();
|
||||
SimpleLogger().Write() << "finished preprocessing";
|
||||
} catch(boost::program_options::too_many_positional_options_error&) {
|
||||
}
|
||||
catch (boost::program_options::too_many_positional_options_error &)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Only one file can be specified";
|
||||
return 1;
|
||||
} catch(boost::program_options::error& e) {
|
||||
}
|
||||
catch (boost::program_options::error &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << e.what();
|
||||
return 1;
|
||||
} catch ( const std::exception &e ) {
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
59
routed.cpp
59
routed.cpp
@ -26,9 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "Library/OSRM.h"
|
||||
|
||||
#include "Server/ServerFactory.h"
|
||||
|
||||
#include "Util/GitDescription.h"
|
||||
#include "Util/ProgramOptions.h"
|
||||
#include "Util/SimpleLogger.h"
|
||||
@ -38,12 +36,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include <boost/thread.hpp> // for timed join.
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
// #include <boost/date_time.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -51,27 +48,27 @@ boost::function0<void> console_ctrl_function;
|
||||
|
||||
BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
|
||||
{
|
||||
switch (ctrl_type)
|
||||
{
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_BREAK_EVENT:
|
||||
case CTRL_CLOSE_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
console_ctrl_function();
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
switch (ctrl_type)
|
||||
{
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_BREAK_EVENT:
|
||||
case CTRL_CLOSE_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
console_ctrl_function();
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main (int argc, const char * argv[])
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
|
||||
bool use_shared_memory = false, trial = false;
|
||||
bool use_shared_memory = false, trial_run = false;
|
||||
std::string ip_address;
|
||||
int ip_port, requested_thread_num;
|
||||
|
||||
@ -84,7 +81,7 @@ int main (int argc, const char * argv[])
|
||||
ip_port,
|
||||
requested_thread_num,
|
||||
use_shared_memory,
|
||||
trial);
|
||||
trial_run);
|
||||
if (init_result == INIT_OK_DO_NOT_START_ENGINE)
|
||||
{
|
||||
return 0;
|
||||
@ -101,11 +98,10 @@ int main (int argc, const char * argv[])
|
||||
SimpleLogger().Write(logWARNING) << argv[0] << " could not be locked to RAM";
|
||||
}
|
||||
#endif
|
||||
SimpleLogger().Write() <<
|
||||
"starting up engines, " << g_GIT_DESCRIPTION << ", " <<
|
||||
"compiled at " << __DATE__ << ", " __TIME__;
|
||||
SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION << ", "
|
||||
<< "compiled at " << __DATE__ << ", " __TIME__;
|
||||
|
||||
if(use_shared_memory)
|
||||
if (use_shared_memory)
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Loading from shared memory";
|
||||
}
|
||||
@ -132,21 +128,18 @@ int main (int argc, const char * argv[])
|
||||
#endif
|
||||
|
||||
OSRM osrm_lib(server_paths, use_shared_memory);
|
||||
Server * routing_server = ServerFactory::CreateServer(
|
||||
ip_address,
|
||||
ip_port,
|
||||
requested_thread_num
|
||||
);
|
||||
Server *routing_server =
|
||||
ServerFactory::CreateServer(ip_address, ip_port, requested_thread_num);
|
||||
|
||||
routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib);
|
||||
|
||||
if( trial )
|
||||
if (trial_run)
|
||||
{
|
||||
SimpleLogger().Write() << "trial run, quitting after successful initialization";
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::thread server_thread(boost::bind(&Server::Run, routing_server));
|
||||
boost::thread server_thread(std::bind(&Server::Run, routing_server));
|
||||
|
||||
#ifndef _WIN32
|
||||
sigset_t wait_mask;
|
||||
@ -160,7 +153,7 @@ int main (int argc, const char * argv[])
|
||||
sigwait(&wait_mask, &sig);
|
||||
#else
|
||||
// Set console control handler to allow server to be stopped.
|
||||
console_ctrl_function = boost::bind(&Server::Stop, routing_server);
|
||||
console_ctrl_function = std::bind(&Server::Stop, routing_server);
|
||||
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
|
||||
SimpleLogger().Write() << "running and waiting for requests";
|
||||
routing_server->Run();
|
||||
@ -179,7 +172,7 @@ int main (int argc, const char * argv[])
|
||||
delete routing_server;
|
||||
SimpleLogger().Write() << "shutdown completed";
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "exception: " << e.what();
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user