2016-03-10 06:43:36 -05:00
|
|
|
/*
|
|
|
|
|
2017-10-02 05:28:25 -04:00
|
|
|
Copyright (c) 2017, Project OSRM contributors
|
2016-03-10 06:43:36 -05:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-02-02 10:50:33 -05:00
|
|
|
#ifndef OSRM_ENGINE_PHANTOM_NODES_H
|
|
|
|
#define OSRM_ENGINE_PHANTOM_NODES_H
|
2010-08-31 10:00:40 -04:00
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/travel_mode.hpp"
|
2013-12-18 06:00:58 -05:00
|
|
|
|
2018-02-02 10:50:33 -05:00
|
|
|
#include "util/typedefs.hpp"
|
2017-08-28 12:03:51 -04:00
|
|
|
#include "util/bearing.hpp"
|
2016-03-28 11:06:51 -04:00
|
|
|
#include "util/coordinate.hpp"
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
2014-11-24 11:57:01 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
|
|
|
|
2014-04-02 05:20:14 -04:00
|
|
|
struct PhantomNode
|
|
|
|
{
|
2016-01-07 13:19:55 -05:00
|
|
|
PhantomNode()
|
2017-08-30 04:46:31 -04:00
|
|
|
: forward_segment_id{SPECIAL_SEGMENTID, false},
|
|
|
|
reverse_segment_id{SPECIAL_SEGMENTID, false}, forward_weight(INVALID_EDGE_WEIGHT),
|
|
|
|
reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0),
|
2017-01-19 16:52:09 -05:00
|
|
|
forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION),
|
2017-08-30 04:46:31 -04:00
|
|
|
forward_duration_offset(0), reverse_duration_offset(0), fwd_segment_position(0),
|
|
|
|
is_valid_forward_source{false}, is_valid_forward_target{false},
|
2017-08-28 12:03:51 -04:00
|
|
|
is_valid_reverse_source{false}, is_valid_reverse_target{false}, bearing(0)
|
2016-01-07 13:19:55 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-12 12:50:10 -04:00
|
|
|
EdgeWeight GetForwardWeightPlusOffset() const
|
2016-01-07 13:19:55 -05:00
|
|
|
{
|
2016-03-28 11:06:51 -04:00
|
|
|
BOOST_ASSERT(forward_segment_id.enabled);
|
2017-01-19 16:52:09 -05:00
|
|
|
return forward_weight_offset + forward_weight;
|
2016-01-07 13:19:55 -05:00
|
|
|
}
|
|
|
|
|
2016-05-12 12:50:10 -04:00
|
|
|
EdgeWeight GetReverseWeightPlusOffset() const
|
2016-01-07 13:19:55 -05:00
|
|
|
{
|
2016-03-28 11:06:51 -04:00
|
|
|
BOOST_ASSERT(reverse_segment_id.enabled);
|
2017-01-19 16:52:09 -05:00
|
|
|
return reverse_weight_offset + reverse_weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
EdgeWeight GetForwardDuration() const
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(forward_segment_id.enabled);
|
|
|
|
return forward_duration + forward_duration_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
EdgeWeight GetReverseDuration() const
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(reverse_segment_id.enabled);
|
|
|
|
return reverse_duration + reverse_duration_offset;
|
2016-01-07 13:19:55 -05:00
|
|
|
}
|
|
|
|
|
2016-03-28 11:06:51 -04:00
|
|
|
bool IsBidirected() const { return forward_segment_id.enabled && reverse_segment_id.enabled; }
|
2014-10-27 17:56:06 -04:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
bool IsValid(const unsigned number_of_nodes) const
|
|
|
|
{
|
2017-08-30 04:46:31 -04:00
|
|
|
return location.IsValid() && ((forward_segment_id.id < number_of_nodes) ||
|
|
|
|
(reverse_segment_id.id < number_of_nodes)) &&
|
2016-01-07 13:19:55 -05:00
|
|
|
((forward_weight != INVALID_EDGE_WEIGHT) ||
|
|
|
|
(reverse_weight != INVALID_EDGE_WEIGHT)) &&
|
2017-01-19 16:52:09 -05:00
|
|
|
((forward_duration != MAXIMAL_EDGE_DURATION) ||
|
|
|
|
(reverse_duration != MAXIMAL_EDGE_DURATION)) &&
|
2017-05-11 03:13:59 -04:00
|
|
|
(component.id != INVALID_COMPONENTID);
|
2016-01-07 13:19:55 -05:00
|
|
|
}
|
|
|
|
|
2016-03-08 10:46:01 -05:00
|
|
|
bool IsValid(const unsigned number_of_nodes, const util::Coordinate queried_coordinate) const
|
|
|
|
{
|
|
|
|
return queried_coordinate == input_location && IsValid(number_of_nodes);
|
|
|
|
}
|
|
|
|
|
2017-05-11 03:13:59 -04:00
|
|
|
bool IsValid() const { return location.IsValid(); }
|
2016-01-07 13:19:55 -05:00
|
|
|
|
2017-05-10 17:20:37 -04:00
|
|
|
bool IsValidForwardSource() const
|
2017-05-05 18:02:53 -04:00
|
|
|
{
|
2017-05-10 17:20:37 -04:00
|
|
|
return forward_segment_id.enabled && is_valid_forward_source;
|
2017-05-05 18:02:53 -04:00
|
|
|
}
|
2017-05-10 17:20:37 -04:00
|
|
|
bool IsValidForwardTarget() const
|
2017-05-05 18:02:53 -04:00
|
|
|
{
|
2017-05-10 17:20:37 -04:00
|
|
|
return forward_segment_id.enabled && is_valid_forward_target;
|
2017-05-05 18:02:53 -04:00
|
|
|
}
|
2017-05-10 17:20:37 -04:00
|
|
|
bool IsValidReverseSource() const
|
2017-05-05 18:02:53 -04:00
|
|
|
{
|
2017-05-10 17:20:37 -04:00
|
|
|
return reverse_segment_id.enabled && is_valid_reverse_source;
|
2017-05-05 18:02:53 -04:00
|
|
|
}
|
2017-05-10 17:20:37 -04:00
|
|
|
bool IsValidReverseTarget() const
|
2017-05-05 18:02:53 -04:00
|
|
|
{
|
2017-05-10 17:20:37 -04:00
|
|
|
return reverse_segment_id.enabled && is_valid_reverse_target;
|
2017-05-05 18:02:53 -04:00
|
|
|
}
|
2017-08-28 12:03:51 -04:00
|
|
|
short GetBearing(const bool traversed_in_reverse) const
|
|
|
|
{
|
|
|
|
if (traversed_in_reverse)
|
2017-08-30 04:46:31 -04:00
|
|
|
return std::round(util::bearing::reverse(bearing));
|
|
|
|
return std::round(bearing);
|
2017-08-28 12:03:51 -04:00
|
|
|
}
|
2017-05-05 18:02:53 -04:00
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
bool operator==(const PhantomNode &other) const { return location == other.location; }
|
2013-08-14 07:12:28 -04:00
|
|
|
|
2016-01-07 19:31:57 -05:00
|
|
|
template <class OtherT>
|
2016-02-23 15:23:13 -05:00
|
|
|
explicit PhantomNode(const OtherT &other,
|
2017-05-15 06:15:00 -04:00
|
|
|
ComponentID component,
|
2016-05-12 12:50:10 -04:00
|
|
|
EdgeWeight forward_weight,
|
|
|
|
EdgeWeight reverse_weight,
|
2017-01-19 16:52:09 -05:00
|
|
|
EdgeWeight forward_weight_offset,
|
|
|
|
EdgeWeight reverse_weight_offset,
|
2016-05-12 12:50:10 -04:00
|
|
|
EdgeWeight forward_duration,
|
|
|
|
EdgeWeight reverse_duration,
|
2017-01-19 16:52:09 -05:00
|
|
|
EdgeWeight forward_duration_offset,
|
|
|
|
EdgeWeight reverse_duration_offset,
|
2017-05-10 17:20:37 -04:00
|
|
|
bool is_valid_forward_source,
|
|
|
|
bool is_valid_forward_target,
|
|
|
|
bool is_valid_reverse_source,
|
|
|
|
bool is_valid_reverse_target,
|
2016-05-12 12:50:10 -04:00
|
|
|
const util::Coordinate location,
|
2017-08-28 12:03:51 -04:00
|
|
|
const util::Coordinate input_location,
|
|
|
|
const unsigned short bearing)
|
2016-03-28 11:06:51 -04:00
|
|
|
: forward_segment_id{other.forward_segment_id},
|
2017-05-11 03:13:59 -04:00
|
|
|
reverse_segment_id{other.reverse_segment_id}, forward_weight{forward_weight},
|
|
|
|
reverse_weight{reverse_weight}, forward_weight_offset{forward_weight_offset},
|
2017-01-19 16:52:09 -05:00
|
|
|
reverse_weight_offset{reverse_weight_offset}, forward_duration{forward_duration},
|
|
|
|
reverse_duration{reverse_duration}, forward_duration_offset{forward_duration_offset},
|
|
|
|
reverse_duration_offset{reverse_duration_offset},
|
2017-05-15 06:15:00 -04:00
|
|
|
component{component.id, component.is_tiny}, location{location},
|
2016-05-12 12:50:10 -04:00
|
|
|
input_location{input_location}, fwd_segment_position{other.fwd_segment_position},
|
2017-05-10 17:20:37 -04:00
|
|
|
is_valid_forward_source{is_valid_forward_source},
|
|
|
|
is_valid_forward_target{is_valid_forward_target},
|
|
|
|
is_valid_reverse_source{is_valid_reverse_source},
|
2017-08-28 12:03:51 -04:00
|
|
|
is_valid_reverse_target{is_valid_reverse_target}, bearing{bearing}
|
2015-02-13 08:24:05 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-28 11:06:51 -04:00
|
|
|
SegmentID forward_segment_id;
|
|
|
|
SegmentID reverse_segment_id;
|
2016-05-12 12:50:10 -04:00
|
|
|
EdgeWeight forward_weight;
|
|
|
|
EdgeWeight reverse_weight;
|
2017-01-19 16:52:09 -05:00
|
|
|
EdgeWeight forward_weight_offset; // TODO: try to remove -> requires path unpacking changes
|
|
|
|
EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes
|
2016-05-12 12:50:10 -04:00
|
|
|
EdgeWeight forward_duration;
|
|
|
|
EdgeWeight reverse_duration;
|
2017-01-19 16:52:09 -05:00
|
|
|
EdgeWeight forward_duration_offset; // TODO: try to remove -> requires path unpacking changes
|
|
|
|
EdgeWeight reverse_duration_offset; // TODO: try to remove -> requires path unpacking changes
|
2017-05-15 06:15:00 -04:00
|
|
|
ComponentID component;
|
2016-04-24 08:06:48 -04:00
|
|
|
|
2016-02-23 15:23:13 -05:00
|
|
|
util::Coordinate location;
|
2016-03-08 10:46:01 -05:00
|
|
|
util::Coordinate input_location;
|
2014-02-26 09:55:04 -05:00
|
|
|
unsigned short fwd_segment_position;
|
2017-05-05 18:02:53 -04:00
|
|
|
// is phantom node valid to be used as source or target
|
|
|
|
private:
|
2017-05-15 05:04:32 -04:00
|
|
|
unsigned short is_valid_forward_source : 1;
|
|
|
|
unsigned short is_valid_forward_target : 1;
|
|
|
|
unsigned short is_valid_reverse_source : 1;
|
|
|
|
unsigned short is_valid_reverse_target : 1;
|
Merge unused 3 bits of PhantomNode into bearing
to prevent memcheck reports
==23434== Use of uninitialised value of size 8
==23434== at 0x15CAFB5: boost::archive::iterators::detail::from_6_bit<char>::operator()(char) const (base64_from_binary.hpp:50)
==23434== by 0x15CB6BE: boost::iterators::transform_iterator<boost::archive::iterators::detail::from_6_bit<char>, boost::archive::iterators::transform_width<char const*, 6, 8, char>, boost::iterators::use_default, boost::iterators::use_default>::dereference() const (transform_iterator.hpp:126)
==23434== by 0x15CB6CE: boost::iterators::transform_iterator<boost::archive::iterators::detail::from_6_bit<char>, boost::archive::iterators::transform_width<char const*, 6, 8, char>, boost::iterators::use_default, boost::iterators::use_default>::reference boost::iterators::iterator_core_access::dereference<boost::iterators::transform_iterator<boost::archive::iterators::detail::from_6_bit<char>, boost::archive::iterators::transform_width<char const*, 6, 8, char>, boost::iterators::use_default, boost::iterators::use_default> >(boost::iterators::transform_iterator<boost::archive::iterators::detail::from_6_bit<char>, boost::archive::iterators::transform_width<char const*, 6, 8, char>, boost::iterators::use_default, boost::iterators::use_default> const&) (iterator_facade.hpp:550)
==23434== by 0x15CB6E2: boost::iterators::detail::iterator_facade_base<boost::iterators::transform_iterator<boost::archive::iterators::detail::from_6_bit<char>, boost::archive::iterators::transform_width<char const*, 6, 8, char>, boost::iterators::use_default, boost::iterators::use_default>, char, boost::iterators::single_pass_traversal_tag, char, long, false, false>::operator*() const (iterator_facade.hpp:656)
==23434== by 0x15CB7F4: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char> >(boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>, boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>, std::input_iterator_tag) (basic_string.tcc:190)
==23434== by 0x15CB89F: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct_aux<boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char> >(boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>, boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>, std::__false_type) (basic_string.h:196)
==23434== by 0x15CB91B: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char> >(boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>, boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>) (basic_string.h:215)
==23434== by 0x15CB9AA: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>, void>(boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>, boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<char const*, 6, 8, char>, char>, std::allocator<char> const&) (basic_string.h:552)
==23434== by 0x15CBB0F: osrm::engine::encodeBase64[abi:cxx11](unsigned char const*, unsigned long) (base64.hpp:65)
==23434== by 0x15CBC01: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > osrm::engine::encodeBase64Bytewise<osrm::engine::Hint>(osrm::engine::Hint const&) (base64.hpp:94)
==23434== by 0x15CBC45: osrm::engine::Hint::ToBase64[abi:cxx11]() const (hint.cpp:30)
==23434== by 0x16596DC: osrm::engine::api::json::makeWaypoint(osrm::util::Coordinate, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, osrm::engine::Hint const&) (json_factory.cpp:359)
2017-10-09 08:44:11 -04:00
|
|
|
unsigned short bearing : 12;
|
2011-07-11 11:16:14 -04:00
|
|
|
};
|
|
|
|
|
2017-05-11 03:13:59 -04:00
|
|
|
static_assert(sizeof(PhantomNode) == 64, "PhantomNode has more padding then expected");
|
2015-09-14 17:01:38 -04:00
|
|
|
|
2015-12-03 14:04:23 -05:00
|
|
|
using PhantomNodePair = std::pair<PhantomNode, PhantomNode>;
|
2014-06-24 10:09:25 -04:00
|
|
|
|
2015-12-09 16:34:22 -05:00
|
|
|
struct PhantomNodeWithDistance
|
|
|
|
{
|
|
|
|
PhantomNode phantom_node;
|
|
|
|
double distance;
|
|
|
|
};
|
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
struct PhantomNodes
|
|
|
|
{
|
|
|
|
PhantomNode source_phantom;
|
|
|
|
PhantomNode target_phantom;
|
2011-06-10 04:25:26 -04:00
|
|
|
};
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 12:39:16 -04:00
|
|
|
#endif // PHANTOM_NODES_H
|