2016-03-10 06:43:36 -05:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2016, Project OSRM contributors
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-05-07 12:39:16 -04:00
|
|
|
#ifndef PHANTOM_NODES_H
|
|
|
|
#define PHANTOM_NODES_H
|
2010-08-31 10:00:40 -04:00
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/travel_mode.hpp"
|
|
|
|
#include "util/typedefs.hpp"
|
2013-12-18 06:00:58 -05:00
|
|
|
|
2016-03-28 11:06:51 -04:00
|
|
|
#include "util/coordinate.hpp"
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
2014-11-24 11:57:01 -05:00
|
|
|
|
2014-10-28 10:39:29 -04:00
|
|
|
#include <iostream>
|
2015-02-09 11:38:40 -05:00
|
|
|
#include <utility>
|
2014-06-23 10:54:57 -04:00
|
|
|
#include <vector>
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
|
|
|
|
2014-04-02 05:20:14 -04:00
|
|
|
struct PhantomNode
|
|
|
|
{
|
2016-03-28 11:06:51 -04:00
|
|
|
PhantomNode(SegmentID forward_segment_id,
|
|
|
|
SegmentID reverse_segment_id,
|
2014-12-30 07:05:28 -05:00
|
|
|
unsigned name_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,
|
|
|
|
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,
|
2016-07-22 12:23:54 -04:00
|
|
|
unsigned packed_geometry_id_,
|
2015-11-18 11:47:37 -05:00
|
|
|
bool is_tiny_component,
|
2014-12-30 07:05:28 -05:00
|
|
|
unsigned component_id,
|
2016-02-23 15:23:13 -05:00
|
|
|
util::Coordinate location,
|
2016-03-08 10:46:01 -05:00
|
|
|
util::Coordinate input_location,
|
2014-08-09 09:13:04 -04:00
|
|
|
unsigned short fwd_segment_position,
|
2016-01-05 10:51:13 -05:00
|
|
|
extractor::TravelMode forward_travel_mode,
|
2016-01-07 13:19:55 -05:00
|
|
|
extractor::TravelMode backward_travel_mode)
|
2016-03-28 11:06:51 -04:00
|
|
|
: forward_segment_id(forward_segment_id), reverse_segment_id(reverse_segment_id),
|
|
|
|
name_id(name_id), forward_weight(forward_weight), reverse_weight(reverse_weight),
|
2017-01-19 16:52:09 -05:00
|
|
|
forward_weight_offset(forward_weight_offset),
|
|
|
|
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), packed_geometry_id(packed_geometry_id_),
|
|
|
|
component{component_id, is_tiny_component}, location(std::move(location)),
|
|
|
|
input_location(std::move(input_location)), fwd_segment_position(fwd_segment_position),
|
|
|
|
forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode)
|
2016-01-07 13:19:55 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PhantomNode()
|
2016-03-28 11:06:51 -04:00
|
|
|
: forward_segment_id{SPECIAL_SEGMENTID, false},
|
|
|
|
reverse_segment_id{SPECIAL_SEGMENTID, false},
|
2016-01-07 13:19:55 -05:00
|
|
|
name_id(std::numeric_limits<unsigned>::max()), forward_weight(INVALID_EDGE_WEIGHT),
|
2017-01-19 16:52:09 -05:00
|
|
|
reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0),
|
|
|
|
forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION),
|
|
|
|
forward_duration_offset(0), reverse_duration_offset(0),
|
2016-08-17 03:49:19 -04:00
|
|
|
packed_geometry_id(SPECIAL_GEOMETRYID), component{INVALID_COMPONENTID, false},
|
|
|
|
fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE),
|
2016-01-07 13:19:55 -05:00
|
|
|
backward_travel_mode(TRAVEL_MODE_INACCESSIBLE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2016-03-28 11:06:51 -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)) &&
|
2016-01-07 13:19:55 -05:00
|
|
|
(component.id != INVALID_COMPONENTID) && (name_id != INVALID_NAMEID);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-01-07 13:19:55 -05:00
|
|
|
bool IsValid() const { return location.IsValid() && (name_id != INVALID_NAMEID); }
|
|
|
|
|
|
|
|
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,
|
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,
|
2016-05-12 12:50:10 -04:00
|
|
|
const util::Coordinate location,
|
|
|
|
const util::Coordinate input_location)
|
2016-03-28 11:06:51 -04:00
|
|
|
: forward_segment_id{other.forward_segment_id},
|
|
|
|
reverse_segment_id{other.reverse_segment_id}, name_id{other.name_id},
|
2016-05-12 12:50:10 -04:00
|
|
|
forward_weight{forward_weight}, reverse_weight{reverse_weight},
|
2017-01-19 16:52:09 -05:00
|
|
|
forward_weight_offset{forward_weight_offset},
|
|
|
|
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},
|
2016-07-22 12:23:54 -04:00
|
|
|
packed_geometry_id{other.packed_geometry_id},
|
2016-05-12 12:50:10 -04:00
|
|
|
component{other.component.id, other.component.is_tiny}, location{location},
|
|
|
|
input_location{input_location}, fwd_segment_position{other.fwd_segment_position},
|
2016-03-28 11:06:51 -04:00
|
|
|
forward_travel_mode{other.forward_travel_mode},
|
|
|
|
backward_travel_mode{other.backward_travel_mode}
|
2015-02-13 08:24:05 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-28 11:06:51 -04:00
|
|
|
SegmentID forward_segment_id;
|
|
|
|
SegmentID reverse_segment_id;
|
2014-02-11 05:42:24 -05:00
|
|
|
unsigned name_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
|
2016-07-22 12:23:54 -04:00
|
|
|
unsigned packed_geometry_id;
|
2016-01-05 06:04:04 -05:00
|
|
|
struct ComponentType
|
|
|
|
{
|
2016-05-27 15:05:04 -04:00
|
|
|
std::uint32_t id : 31;
|
|
|
|
std::uint32_t is_tiny : 1;
|
2015-11-18 11:47:37 -05:00
|
|
|
} component;
|
2016-03-28 11:06:51 -04:00
|
|
|
static_assert(sizeof(ComponentType) == 4, "ComponentType needs to be 4 bytes big");
|
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;
|
2015-09-14 17:01:38 -04:00
|
|
|
// note 4 bits would suffice for each,
|
|
|
|
// but the saved byte would be padding anyway
|
2016-01-05 10:51:13 -05:00
|
|
|
extractor::TravelMode forward_travel_mode;
|
|
|
|
extractor::TravelMode backward_travel_mode;
|
2011-07-11 11:16:14 -04:00
|
|
|
};
|
|
|
|
|
2017-01-19 16:52:09 -05:00
|
|
|
static_assert(sizeof(PhantomNode) == 72, "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
|
|
|
};
|
|
|
|
|
2015-02-13 08:24:05 -05:00
|
|
|
inline std::ostream &operator<<(std::ostream &out, const PhantomNodes &pn)
|
2014-04-02 05:20:14 -04:00
|
|
|
{
|
2014-11-26 10:54:43 -05:00
|
|
|
out << "source_coord: " << pn.source_phantom.location << "\n";
|
|
|
|
out << "target_coord: " << pn.target_phantom.location << std::endl;
|
2011-06-10 04:25:26 -04:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-02-13 08:24:05 -05:00
|
|
|
inline std::ostream &operator<<(std::ostream &out, const PhantomNode &pn)
|
2014-04-02 05:20:14 -04:00
|
|
|
{
|
2016-03-28 11:06:51 -04:00
|
|
|
out << "node1: " << pn.forward_segment_id.id << ", "
|
|
|
|
<< "node2: " << pn.reverse_segment_id.id << ", "
|
2015-02-13 08:24:05 -05:00
|
|
|
<< "name: " << pn.name_id << ", "
|
|
|
|
<< "fwd-w: " << pn.forward_weight << ", "
|
|
|
|
<< "rev-w: " << pn.reverse_weight << ", "
|
2017-01-19 16:52:09 -05:00
|
|
|
<< "fwd-o: " << pn.forward_weight_offset << ", "
|
|
|
|
<< "rev-o: " << pn.reverse_weight_offset << ", "
|
2016-05-12 12:50:10 -04:00
|
|
|
<< "fwd-d: " << pn.forward_duration << ", "
|
|
|
|
<< "rev-d: " << pn.reverse_duration << ", "
|
2017-01-19 16:52:09 -05:00
|
|
|
<< "fwd-do: " << pn.forward_duration_offset << ", "
|
|
|
|
<< "rev-do: " << pn.reverse_duration_offset << ", "
|
2016-07-22 12:23:54 -04:00
|
|
|
<< "geom: " << pn.packed_geometry_id << ", "
|
2015-11-18 11:47:37 -05:00
|
|
|
<< "comp: " << pn.component.is_tiny << " / " << pn.component.id << ", "
|
2015-02-13 08:24:05 -05:00
|
|
|
<< "pos: " << pn.fwd_segment_position << ", "
|
|
|
|
<< "loc: " << pn.location;
|
2012-02-29 08:30:19 -05:00
|
|
|
return out;
|
|
|
|
}
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 12:39:16 -04:00
|
|
|
#endif // PHANTOM_NODES_H
|