Esempio n. 1
0
inline bool deserializeFlags(const boost::filesystem::path &path, std::vector<bool> &flags)
{
    SimpleLogger().Write() << "Reading flags from " << path;
    std::ifstream flag_stream(path.string(), std::ios::binary);

    if (!readAndCheckFingerprint(flag_stream))
        return false;

    std::uint32_t number_of_bits;
    flag_stream.read(reinterpret_cast<char *>(&number_of_bits), sizeof(number_of_bits));
    flags.resize(number_of_bits);
    // putting bits in ints
    std::uint32_t chunks = (number_of_bits + 31) / 32;
    std::size_t bit_position = 0;
    std::uint32_t chunk;
    for (std::size_t chunk_id = 0; chunk_id < chunks; ++chunk_id)
    {
        flag_stream.read(reinterpret_cast<char *>(&chunk), sizeof(chunk));
        std::bitset<32> chunk_bits(chunk);
        for (std::size_t bit = 0; bit < 32 && bit_position < number_of_bits; ++bit, ++bit_position)
            flags[bit_position] = chunk_bits[bit];
    }
    SimpleLogger().Write() << "Read " << number_of_bits << " bits in " << chunks
                           << " Chunks from disk.";
    return static_cast<bool>(flag_stream);
}
void EdgeBasedGraphFactory::Run(const std::string &original_edge_data_filename,
                                const std::string &geometry_filename,
                                lua_State *lua_state)
{
    TIMER_START(geometry);
    CompressGeometry();
    TIMER_STOP(geometry);

    TIMER_START(renumber);
    RenumberEdges();
    TIMER_STOP(renumber);

    TIMER_START(generate_nodes);
    GenerateEdgeExpandedNodes();
    TIMER_STOP(generate_nodes);

    TIMER_START(generate_edges);
    GenerateEdgeExpandedEdges(original_edge_data_filename, lua_state);
    TIMER_STOP(generate_edges);

    m_geometry_compressor.SerializeInternalVector(geometry_filename);

    SimpleLogger().Write() << "Timing statistics for edge-expanded graph:";
    SimpleLogger().Write() << "Geometry compression: " << TIMER_SEC(geometry) << "s";
    SimpleLogger().Write() << "Renumbering edges: " << TIMER_SEC(renumber) << "s";
    SimpleLogger().Write() << "Generating nodes: " << TIMER_SEC(generate_nodes) << "s";
    SimpleLogger().Write() << "Generating edges: " << TIMER_SEC(generate_edges) << "s";
}
Esempio n. 3
0
int main(int argc, const char *argv[])
{
    LogPolicy::GetInstance().Unmute();
    try
    {
        std::string ip_address;
        int ip_port, requested_thread_num, max_locations_map_matching;
        bool trial_run = false;
        libosrm_config lib_config;
        const unsigned init_result = GenerateServerProgramOptions(
            argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num,
            lib_config.use_shared_memory, trial_run, lib_config.max_locations_distance_table,
            max_locations_map_matching);

        if (init_result == INIT_OK_DO_NOT_START_ENGINE)
        {
            return 0;
        }
        if (init_result == INIT_FAILED)
        {
            return 1;
        }
        SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION;

        OSRM routing_machine(lib_config);

        RouteParameters route_parameters;
        route_parameters.zoom_level = 18;           // no generalization
        route_parameters.print_instructions = true; // turn by turn instructions
        route_parameters.alternate_route = true;    // get an alternate route, too
        route_parameters.geometry = true;           // retrieve geometry of route
        route_parameters.compression = true;        // polyline encoding
        route_parameters.check_sum = -1;            // see wiki
        route_parameters.service = "viaroute";      // that's routing
        route_parameters.output_format = "json";
        route_parameters.jsonp_parameter = ""; // set for jsonp wrapping
        route_parameters.language = "";        // unused atm
        // route_parameters.hints.push_back(); // see wiki, saves I/O if done properly

        // start_coordinate
        route_parameters.coordinates.emplace_back(52.519930 * COORDINATE_PRECISION,
                                                  13.438640 * COORDINATE_PRECISION);
        // target_coordinate
        route_parameters.coordinates.emplace_back(52.513191 * COORDINATE_PRECISION,
                                                  13.415852 * COORDINATE_PRECISION);
        osrm::json::Object json_result;
        const int result_code = routing_machine.RunQuery(route_parameters, json_result);
        SimpleLogger().Write() << "http code: " << result_code;
        osrm::json::render(SimpleLogger().Write(), json_result);
    }
    catch (std::exception &current_exception)
    {
        SimpleLogger().Write(logWARNING) << "caught exception: " << current_exception.what();
        return -1;
    }
    return 0;
}
Esempio n. 4
0
int main()
{
    LogPolicy::GetInstance().Unmute();
    try
    {
        SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION << "\n\n";
        SimpleLogger().Write() << "Releasing all locks";
        SimpleLogger().Write() << "ATTENTION! BE CAREFUL!";
        SimpleLogger().Write() << "----------------------";
        SimpleLogger().Write() << "This tool may put osrm-routed into an undefined state!";
        SimpleLogger().Write() << "Type 'Y' to acknowledge that you know what your are doing.";
        SimpleLogger().Write() << "\n\nDo you want to purge all shared memory allocated " <<
                                  "by osrm-datastore? [type 'Y' to confirm]";

        const auto letter = getchar();
        if (letter != 'Y')
        {
            SimpleLogger().Write() << "aborted.";
            return 0;
        }
        springclean();
    }
    catch (const std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what();
    }
    return 0;
}
 ~shm_remove()
 {
     if (m_initialized)
     {
         SimpleLogger().Write(logDEBUG) << "automatic memory deallocation";
         if (!boost::interprocess::xsi_shared_memory::remove(m_shmid))
         {
             SimpleLogger().Write(logDEBUG) << "could not deallocate id " << m_shmid;
         }
     }
 }
int main() {
    LogPolicy::GetInstance().Unmute();
    SimpleLogger().Write() <<
            "starting up engines, " << g_GIT_DESCRIPTION << ", " <<
            "compiled at " << __DATE__ << ", " __TIME__;
    SimpleLogger().Write() << "Releasing all locks";
    SharedBarriers barrier;
    barrier.pending_update_mutex.unlock();
    barrier.query_mutex.unlock();
    barrier.update_mutex.unlock();
    return 0;
}
Esempio n. 7
0
void BaseParser::ReadUseRestrictionsSetting() {
    if( 0 != luaL_dostring( lua_state, "return use_turn_restrictions\n") ) {
        throw OSRMException("ERROR occured in scripting block");
    }
    if( lua_isboolean( lua_state, -1) ) {
        use_turn_restrictions = lua_toboolean(lua_state, -1);
    }
    if( use_turn_restrictions ) {
        SimpleLogger().Write() << "Using turn restrictions";
    } else {
        SimpleLogger().Write() << "Ignoring turn restrictions";
    }
}
Esempio n. 8
0
void BaseParser::ReadRestrictionExceptions() {
    if(lua_function_exists(luaState, "get_exceptions" )) {
        //get list of turn restriction exceptions
        luabind::call_function<void>(
            luaState,
            "get_exceptions",
            boost::ref(restriction_exceptions)
        );
        SimpleLogger().Write() << "Found " << restriction_exceptions.size() << " exceptions to turn restriction";
        BOOST_FOREACH(const std::string & str, restriction_exceptions) {
            SimpleLogger().Write() << "   " << str;
        }
    } else {
    void CheckAndReloadFacade()
    {
        if (CURRENT_LAYOUT != data_timestamp_ptr->layout ||
            CURRENT_DATA != data_timestamp_ptr->data ||
            CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp)
        {
            // release the previous shared memory segments
            SharedMemory::Remove(CURRENT_LAYOUT);
            SharedMemory::Remove(CURRENT_DATA);

            CURRENT_LAYOUT = data_timestamp_ptr->layout;
            CURRENT_DATA = data_timestamp_ptr->data;
            CURRENT_TIMESTAMP = data_timestamp_ptr->timestamp;

            m_layout_memory.reset(SharedMemoryFactory::Get(CURRENT_LAYOUT));

            data_layout = (SharedDataLayout *)(m_layout_memory->Ptr());

            m_large_memory.reset(SharedMemoryFactory::Get(CURRENT_DATA));
            shared_memory = (char *)(m_large_memory->Ptr());

            const char *file_index_ptr =
                data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::FILE_INDEX_PATH);
            file_index_path = boost::filesystem::path(file_index_ptr);
            if (!boost::filesystem::exists(file_index_path))
            {
                SimpleLogger().Write(logDEBUG) << "Leaf file name " << file_index_path.string();
                throw osrm::exception("Could not load leaf index file."
                                      "Is any data loaded into shared memory?");
            }

            LoadGraph();
            LoadChecksum();
            LoadNodeAndEdgeInformation();
            LoadGeometries();
            LoadTimestamp();
            LoadViaNodeList();
            LoadNames();

            data_layout->PrintInformation();

            SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size();
            for (unsigned i = 0; i < m_coordinate_list->size(); ++i)
            {
                if (!GetCoordinateOfNode(i).is_valid())
                {
                    SimpleLogger().Write() << "coordinate " << i << " not valid";
                }
            }
        }
    }
Esempio n. 10
0
unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file,
                            std::vector<NodeT> &node_list,
                            std::vector<EdgeT> &edge_list,
                            unsigned *check_sum)
{
    if (!boost::filesystem::exists(hsgr_file))
    {
        throw exception("hsgr file does not exist");
    }
    if (0 == boost::filesystem::file_size(hsgr_file))
    {
        throw exception("hsgr file is empty");
    }

    boost::filesystem::ifstream hsgr_input_stream(hsgr_file, std::ios::binary);

    const FingerPrint fingerprint_valid = FingerPrint::GetValid();
    FingerPrint fingerprint_loaded;
    hsgr_input_stream.read(reinterpret_cast<char *>(&fingerprint_loaded), sizeof(FingerPrint));
    if (!fingerprint_loaded.TestGraphUtil(fingerprint_valid))
    {
        SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build.\n"
                                            "Reprocess to get rid of this warning.";
    }

    unsigned number_of_nodes = 0;
    unsigned number_of_edges = 0;
    hsgr_input_stream.read(reinterpret_cast<char *>(check_sum), sizeof(unsigned));
    hsgr_input_stream.read(reinterpret_cast<char *>(&number_of_nodes), sizeof(unsigned));
    BOOST_ASSERT_MSG(0 != number_of_nodes, "number of nodes is zero");
    hsgr_input_stream.read(reinterpret_cast<char *>(&number_of_edges), sizeof(unsigned));

    SimpleLogger().Write() << "number_of_nodes: " << number_of_nodes
                           << ", number_of_edges: " << number_of_edges;

    // BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero");
    node_list.resize(number_of_nodes);
    hsgr_input_stream.read(reinterpret_cast<char *>(&node_list[0]),
                           number_of_nodes * sizeof(NodeT));

    edge_list.resize(number_of_edges);
    if (number_of_edges > 0)
    {
        hsgr_input_stream.read(reinterpret_cast<char *>(&edge_list[0]),
                               number_of_edges * sizeof(EdgeT));
    }
    hsgr_input_stream.close();

    return number_of_nodes;
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
    try
    {
        LogPolicy::GetInstance().Unmute();
        ExtractorConfig extractor_config;

        const return_code result = ExtractorOptions::ParseArguments(argc, argv, extractor_config);

        if (return_code::fail == result)
        {
            return 1;
        }

        if (return_code::exit == result)
        {
            return 0;
        }

        ExtractorOptions::GenerateOutputFilesNames(extractor_config);

        if (1 > extractor_config.requested_num_threads)
        {
            SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
            return 1;
        }

        if (!boost::filesystem::is_regular_file(extractor_config.input_path))
        {
            SimpleLogger().Write(logWARNING)
                << "Input file " << extractor_config.input_path.string() << " not found!";
            return 1;
        }

        if (!boost::filesystem::is_regular_file(extractor_config.profile_path))
        {
            SimpleLogger().Write(logWARNING) << "Profile " << extractor_config.profile_path.string()
                                             << " not found!";
            return 1;
        }
        return extractor().run(extractor_config);
    }
    catch (const std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
        return 1;
    }
}
Esempio n. 12
0
void delete_region(const SharedDataType region)
{
    if (SharedMemory::RegionExists(region) && !SharedMemory::Remove(region))
    {
        const std::string name = [&]
        {
            switch (region)
            {
            case CURRENT_REGIONS:
                return "CURRENT_REGIONS";
            case LAYOUT_1:
                return "LAYOUT_1";
            case DATA_1:
                return "DATA_1";
            case LAYOUT_2:
                return "LAYOUT_2";
            case DATA_2:
                return "DATA_2";
            case LAYOUT_NONE:
                return "LAYOUT_NONE";
            default: // DATA_NONE:
                return "DATA_NONE";
            }
        }();

        SimpleLogger().Write(logWARNING) << "could not delete shared memory region " << name;
    }
}
Esempio n. 13
0
void GeometryCompressor::PrintStatistics() const
{
    const uint64_t compressed_edges = m_compressed_geometries.size();
    BOOST_ASSERT(0 == compressed_edges % 2);
    BOOST_ASSERT(m_compressed_geometries.size() + m_free_list.size() > 0);

    uint64_t compressed_geometries = 0;
    uint64_t longest_chain_length = 0;
    for (const std::vector<CompressedNode> &current_vector : m_compressed_geometries)
    {
        compressed_geometries += current_vector.size();
        longest_chain_length = std::max(longest_chain_length, (uint64_t)current_vector.size());
    }

    SimpleLogger().Write() << "Geometry successfully removed:"
                              "\n  compressed edges: " << compressed_edges
                           << "\n  compressed geometries: " << compressed_geometries
                           << "\n  longest chain length: " << longest_chain_length
                           << "\n  cmpr ratio: "
                           << ((float)compressed_edges /
                               std::max(compressed_geometries, (uint64_t)1))
                           << "\n  avg chain length: "
                           << (float)compressed_geometries /
                                  std::max((uint64_t)1, compressed_edges);
}
Esempio n. 14
0
inline void PBFParser::ParseData() {
	while (true) {
		_ThreadData *threadData;
		threadDataQueue->wait_and_pop(threadData);
		if( NULL==threadData ) {
			SimpleLogger().Write() << "Parse Data Thread Finished";
			threadDataQueue->push(NULL); // Signal end of data for other threads
			break;
		}

		loadBlock(threadData);

		for(int i = 0, groupSize = threadData->PBFprimitiveBlock.primitivegroup_size(); i < groupSize; ++i) {
			threadData->currentGroupID = i;
			loadGroup(threadData);

			if(threadData->entityTypeIndicator == TypeNode) {
				parseNode(threadData);
			}
			if(threadData->entityTypeIndicator == TypeWay) {
				parseWay(threadData);
			}
			if(threadData->entityTypeIndicator == TypeRelation) {
				parseRelation(threadData);
			}
			if(threadData->entityTypeIndicator == TypeDenseNode) {
				parseDenseNode(threadData);
			}
		}

		delete threadData;
		threadData = NULL;
	}
}
    SharedMemory(const boost::filesystem::path &lock_file,
                 const int id,
                 const uint64_t size = 0,
                 bool read_write = false,
                 bool remove_prev = true)
    {
        sprintf(key, "%s.%d", "osrm.lock", id);
        if (0 == size)
        { // read_only
            shm = boost::interprocess::shared_memory_object(
                boost::interprocess::open_only, key,
                read_write ? boost::interprocess::read_write : boost::interprocess::read_only);
            region = boost::interprocess::mapped_region(
                shm, read_write ? boost::interprocess::read_write : boost::interprocess::read_only);
        }
        else
        { // writeable pointer
            // remove previously allocated mem
            if (remove_prev)
            {
                Remove(key);
            }
            shm = boost::interprocess::shared_memory_object(boost::interprocess::open_or_create,
                                                            key, boost::interprocess::read_write);
            shm.truncate(size);
            region = boost::interprocess::mapped_region(shm, boost::interprocess::read_write);

            remover.SetID(key);
            SimpleLogger().Write(logDEBUG) << "writeable memory allocated " << size << " bytes";
        }
    }
 static SharedMemory *Get(const IdentifierT &id,
                          const uint64_t size = 0,
                          bool read_write = false,
                          bool remove_prev = true)
 {
     try
     {
         LockFileT lock_file;
         if (!boost::filesystem::exists(lock_file()))
         {
             if (0 == size)
             {
                 throw osrm::exception("lock file does not exist, exiting");
             }
             else
             {
                 boost::filesystem::ofstream ofs(lock_file());
                 ofs.close();
             }
         }
         return new SharedMemory(lock_file(), id, size, read_write, remove_prev);
     }
     catch (const boost::interprocess::interprocess_exception &e)
     {
         SimpleLogger().Write(logWARNING) << "caught exception: " << e.what() << ", code "
                                          << e.get_error_code();
         throw osrm::exception(e.what());
     }
 }
Esempio n. 17
0
inline bool serializeFlags(const boost::filesystem::path &path, const std::vector<bool> &flags)
{
    // TODO this should be replaced with a FILE-based write using error checking
    std::ofstream flag_stream(path.string(), std::ios::binary);

    writeFingerprint(flag_stream);

    std::uint32_t number_of_bits = flags.size();
    flag_stream.write(reinterpret_cast<const char *>(&number_of_bits), sizeof(number_of_bits));
    // putting bits in ints
    std::uint32_t chunk = 0;
    std::size_t chunk_count = 0;
    for (std::size_t bit_nr = 0; bit_nr < number_of_bits;)
    {
        std::bitset<32> chunk_bitset;
        for (std::size_t chunk_bit = 0; chunk_bit < 32 && bit_nr < number_of_bits;
             ++chunk_bit, ++bit_nr)
            chunk_bitset[chunk_bit] = flags[bit_nr];

        chunk = chunk_bitset.to_ulong();
        ++chunk_count;
        flag_stream.write(reinterpret_cast<const char *>(&chunk), sizeof(chunk));
    }
    SimpleLogger().Write() << "Wrote " << number_of_bits << " bits in " << chunk_count
                           << " chunks (Flags).";
    return static_cast<bool>(flag_stream);
}
Esempio n. 18
0
/**
    \brief Building rtree-based nearest-neighbor data structure

    Saves info to files: '.ramIndex' and '.fileIndex'.
 */
void Prepare::BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list)
{
    SimpleLogger().Write() << "building r-tree ...";
    StaticRTree<EdgeBasedNode>(node_based_edge_list,
                               rtree_nodes_path.c_str(),
                               rtree_leafs_path.c_str(),
                               internal_to_external_node_map);
}
Esempio n. 19
0
void RestrictionParser::ReadUseRestrictionsSetting(lua_State *lua_state)
{
    if (0 == luaL_dostring(lua_state, "return use_turn_restrictions\n") &&
        lua_isboolean(lua_state, -1))
    {
        use_turn_restrictions = lua_toboolean(lua_state, -1);
    }

    if (use_turn_restrictions)
    {
        SimpleLogger().Write() << "Using turn restrictions";
    }
    else
    {
        SimpleLogger().Write() << "Ignoring turn restrictions";
    }
}
Esempio n. 20
0
void OSRM_impl::RegisterPlugin(BasePlugin *plugin)
{
    SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor();
    if (plugin_map.find(plugin->GetDescriptor()) != plugin_map.end())
    {
        delete plugin_map.find(plugin->GetDescriptor())->second;
    }
    plugin_map.emplace(plugin->GetDescriptor(), plugin);
}
Esempio n. 21
0
int main()
{
    LogPolicy::GetInstance().Unmute();
    try
    {
        SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION;
        SimpleLogger().Write() << "Releasing all locks";
        SharedBarriers barrier;
        barrier.pending_update_mutex.unlock();
        barrier.query_mutex.unlock();
        barrier.update_mutex.unlock();
    }
    catch (const std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what();
    }
    return 0;
}
Esempio n. 22
0
// find all existing shmem regions and remove them.
void springclean()
{
    SimpleLogger().Write() << "spring-cleaning all shared memory regions";
    delete_region(DATA_1);
    delete_region(LAYOUT_1);
    delete_region(DATA_2);
    delete_region(LAYOUT_2);
    delete_region(CURRENT_REGIONS);
}
int main()
{
    LogPolicy::GetInstance().Unmute();
    try
    {
        SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION << ", "
                               << "compiled at " << __DATE__ << ", " __TIME__;
        SimpleLogger().Write() << "Releasing all locks";
        SharedBarriers barrier;
        barrier.pending_update_mutex.unlock();
        barrier.query_mutex.unlock();
        barrier.update_mutex.unlock();
    }
    catch (const std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what();
    }
    return 0;
}
Esempio n. 24
0
/**
 * Reads the beginning of an .osrm file and produces:
 *  - list of barrier nodes
 *  - list of traffic lights
 *  - nodes indexed by their internal (non-osm) id
 */
NodeID loadNodesFromFile(std::istream &input_stream,
                         std::vector<NodeID> &barrier_node_list,
                         std::vector<NodeID> &traffic_light_node_list,
                         std::vector<extractor::QueryNode> &node_array)
{
    const FingerPrint fingerprint_valid = FingerPrint::GetValid();
    FingerPrint fingerprint_loaded;
    input_stream.read(reinterpret_cast<char *>(&fingerprint_loaded), sizeof(FingerPrint));

    if (!fingerprint_loaded.TestContractor(fingerprint_valid))
    {
        SimpleLogger().Write(logWARNING) << ".osrm was prepared with different build.\n"
                                            "Reprocess to get rid of this warning.";
    }

    NodeID n;
    input_stream.read(reinterpret_cast<char *>(&n), sizeof(NodeID));
    SimpleLogger().Write() << "Importing n = " << n << " nodes ";

    extractor::ExternalMemoryNode current_node;
    for (NodeID i = 0; i < n; ++i)
    {
        input_stream.read(reinterpret_cast<char *>(&current_node),
                          sizeof(extractor::ExternalMemoryNode));
        node_array.emplace_back(current_node.lon, current_node.lat, current_node.node_id);
        if (current_node.barrier)
        {
            barrier_node_list.emplace_back(i);
        }
        if (current_node.traffic_lights)
        {
            traffic_light_node_list.emplace_back(i);
        }
    }

    // tighten vector sizes
    barrier_node_list.shrink_to_fit();
    traffic_light_node_list.shrink_to_fit();

    return n;
}
Esempio n. 25
0
int main (int argc, char *argv[])
{
    try
    {
        return Extractor().Run(argc, argv);
    }
    catch (const std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
    }

}
Esempio n. 26
0
void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
{
    if (lua_function_exists(lua_state, "get_exceptions"))
    {
        luabind::set_pcall_callback(&lua_error_callback);
        // get list of turn restriction exceptions
        luabind::call_function<void>(lua_state, "get_exceptions",
                                     boost::ref(restriction_exceptions));
        const unsigned exception_count = restriction_exceptions.size();
        SimpleLogger().Write() << "Found " << exception_count
                               << " exceptions to turn restrictions:";
        for (const std::string &str : restriction_exceptions)
        {
            SimpleLogger().Write() << "  " << str;
        }
    }
    else
    {
        SimpleLogger().Write() << "Found no exceptions to turn restrictions";
    }
}
Esempio n. 27
0
/**
 * Reads a .osrm file and produces the edges.
 */
NodeID loadEdgesFromFile(std::istream &input_stream,
                         std::vector<extractor::NodeBasedEdge> &edge_list)
{
    EdgeID m;
    input_stream.read(reinterpret_cast<char *>(&m), sizeof(unsigned));
    edge_list.resize(m);
    SimpleLogger().Write() << " and " << m << " edges ";

    input_stream.read((char *)edge_list.data(), m * sizeof(extractor::NodeBasedEdge));

    BOOST_ASSERT(edge_list.size() > 0);

#ifndef NDEBUG
    SimpleLogger().Write() << "Validating loaded edges...";
    tbb::parallel_sort(
        edge_list.begin(),
        edge_list.end(),
        [](const extractor::NodeBasedEdge &lhs, const extractor::NodeBasedEdge &rhs) {
            return (lhs.source < rhs.source) ||
                   (lhs.source == rhs.source && lhs.target < rhs.target);
        });
    for (auto i = 1u; i < edge_list.size(); ++i)
    {
        const auto &edge = edge_list[i];
        const auto &prev_edge = edge_list[i - 1];

        BOOST_ASSERT_MSG(edge.weight > 0, "loaded null weight");
        BOOST_ASSERT_MSG(edge.forward, "edge must be oriented in forward direction");
        BOOST_ASSERT_MSG(edge.travel_mode != TRAVEL_MODE_INACCESSIBLE, "loaded non-accessible");

        BOOST_ASSERT_MSG(edge.source != edge.target, "loaded edges contain a loop");
        BOOST_ASSERT_MSG(edge.source != prev_edge.source || edge.target != prev_edge.target,
                         "loaded edges contain a multi edge");
    }
#endif

    SimpleLogger().Write() << "Graph loaded ok and has " << edge_list.size() << " edges";

    return m;
}
    SharedMemory(const boost::filesystem::path &lock_file,
                 const IdentifierT id,
                 const uint64_t size = 0,
                 bool read_write = false,
                 bool remove_prev = true)
        : key(lock_file.string().c_str(), id)
    {
        if (0 == size)
        { // read_only
            shm = boost::interprocess::xsi_shared_memory(boost::interprocess::open_only, key);

            region = boost::interprocess::mapped_region(
                shm,
                (read_write ? boost::interprocess::read_write : boost::interprocess::read_only));
        }
        else
        { // writeable pointer
            // remove previously allocated mem
            if (remove_prev)
            {
                Remove(key);
            }
            shm = boost::interprocess::xsi_shared_memory(boost::interprocess::open_or_create, key,
                                                         size);
#ifdef __linux__
            if (-1 == shmctl(shm.get_shmid(), SHM_LOCK, 0))
            {
                if (ENOMEM == errno)
                {
                    SimpleLogger().Write(logWARNING) << "could not lock shared memory to RAM";
                }
            }
#endif
            region = boost::interprocess::mapped_region(shm, boost::interprocess::read_write);

            remover.SetID(shm.get_shmid());
            SimpleLogger().Write(logDEBUG) << "writeable memory allocated " << size << " bytes";
        }
    }
Esempio n. 29
0
/**
  \brief Writing info on original (node-based) nodes
 */
void Prepare::WriteNodeMapping()
{
    SimpleLogger().Write() << "writing node map ...";
    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));
    if (size_of_mapping > 0)
    {
        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();
}
 static bool Remove(char *key)
 {
     bool ret = false;
     try
     {
         SimpleLogger().Write(logDEBUG) << "deallocating prev memory";
         ret = boost::interprocess::shared_memory_object::remove(key);
     }
     catch (const boost::interprocess::interprocess_exception &e)
     {
         if (e.get_error_code() != boost::interprocess::not_found_error)
         {
             throw;
         }
     }
     return ret;
 }