Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Johnson< GT, Distance, Ait, NAit, SA > Class Template Reference

Johnson's algorithm for all-pairs shortest paths. More...

#include <Johnson.H>

Collaboration diagram for Aleph::Johnson< GT, Distance, Ait, NAit, SA >:
[legend]

Classes

struct  Kept_Source
 
struct  Shown_Arc
 

Public Types

using Node = typename GT::Node
 
using Arc = typename GT::Arc
 
using Distance_Type = typename Distance::Distance_Type
 

Public Member Functions

 Johnson (const GT &g, Distance d=Distance(), SA __sa=SA())
 Construct a Johnson's all-pairs shortest paths executor.
 
 Johnson ()=default
 Default constructor (uninitialized state)
 
 Johnson (const Johnson &)=delete
 Johnson is not copyable: a copy would point to the nodes of the copy of the graph that this one keeps.
 
Johnson & operator= (const Johnson &)=delete
 Johnson is not copyable: a copy would point to the nodes of the copy of the graph that this one keeps.
 
 Johnson (Johnson &&)=default
 Move constructor: the tree that is kept moves too.
 
Johnson & operator= (Johnson &&)=default
 Move assignment: the tree that is kept moves too.
 
bool is_initialized () const noexcept
 Check if the algorithm has been initialized.
 
Distance_Type get_distance (Node *src, Node *tgt)
 Get the shortest distance from source to target.
 
Path< GT > find_path (Node *src, Node *tgt)
 Find the shortest path from source to target.
 
DynMapTree< std::pair< Node *, Node * >, Distance_Type > compute_all_pairs_distances ()
 Compute the shortest distance for all pairs.
 
Distance_Type get_potential (Node *node) const
 Get the node potential (h value) for a node.
 
GT & get_reweighted_graph () noexcept
 Get access to the internal reweighted graph.
 
const GT & get_reweighted_graph () const noexcept
 Get const access to the internal reweighted graph.
 
Node * get_copy_node (Node *orig) const
 Get the copy of a node in the reweighted graph.
 

Private Types

enum  Mode : unsigned char { No_Graph = 0 , Narrow_Potentials , Wide_Potentials }
 
enum  : unsigned char {
  Unreached = 0 , Labeled , Settled , Too_Far ,
  Settled_Wide
}
 
using Weight = typename std::conditional_t< Integer, std::make_unsigned< std::remove_cv_t< Distance_Type > >, std::type_identity< Distance_Type > >::type
 
using Wide = johnson_detail::Wide
 
using Potential_Graph = List_Digraph< Graph_Node< size_t >, Graph_Arc< Distance_Type > >
 

Private Member Functions

template<bool W>
auto & weights_of () noexcept
 
template<bool W>
auto & reach_of () noexcept
 
template<bool W>
auto & heap_of () noexcept
 
size_t number_of (Node *p) const
 
Distance_Type distance_to (size_t s, size_t t) const
 
Distance_Type distance_apart (size_t s, size_t t) const
 
template<bool W>
void spread_too_far ()
 
template<bool W>
void paint (size_t s)
 
void paint_wide (size_t s)
 
void paint_from (size_t s)
 
void narrow_potentials (Potential_Graph &pg, const std::vector< typename Potential_Graph::Node * > &pnodes)
 
void wide_potentials (const std::vector< Shown_Arc > &shown)
 
void wide_arcs (const std::vector< Shown_Arc > &shown)
 

Static Private Member Functions

static Weight reweight (const Distance_Type &w, const Distance_Type &hu, const Distance_Type &hv)
 
static bool add (const Weight &a, const Weight &b, Weight &sum)
 
static bool add (const Wide &a, const Wide &b, Wide &sum)
 
static void write_info (Arc *copy, const Weight &w)
 
static void write_info (Arc *copy, const Wide &w)
 
static constexpr Distance_Type unreachable () noexcept
 
static Distance_Type unweighted (const Weight &d_prime, const Distance_Type &hs, const Distance_Type &ht)
 
static Distance_Type wide_unweighted (const Wide &d_prime, const Wide &hs, const Wide &ht)
 

Private Attributes

const GT * orig_graph = nullptr
 
GT reweighted
 Copy of the graph.
 
DynMapTree< Node *, size_t > number
 Of each node of the graph, from 0.
 
std::vector< Node * > nodes
 The node of each number.
 
std::vector< Node * > copies
 Its copy in the reweighted graph.
 
std::vector< Distance_Type > h
 Its potential, from Bellman-Ford.
 
std::vector< size_t > out_first
 
std::vector< size_t > out_target
 
std::vector< Weight > out_weight
 
std::vector< Arc * > out_arc
 
Mode mode = No_Graph
 
std::vector< unsigned char > state
 
std::vector< Weight > reach
 
std::vector< size_t > parent
 
std::vector< size_t > via
 
std::vector< std::pair< Weight, size_t > > heap
 
std::vector< Wide > wide_h
 
std::vector< Wide > wide_weight
 
std::vector< Wide > wide_reach
 
std::vector< std::pair< Wide, size_t > > wide_heap
 
struct Aleph::Johnson::Kept_Source kept
 

Static Private Attributes

static constexpr bool Integer
 
static constexpr bool Signed_Integer
 
static constexpr size_t None = std::numeric_limits<size_t>::max()
 

Detailed Description

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
class Aleph::Johnson< GT, Distance, Ait, NAit, SA >

Johnson's algorithm for all-pairs shortest paths.

This class implements Johnson's algorithm for computing shortest paths between all pairs of vertices in a weighted directed graph. It handles graphs with negative edge weights (but not negative cycles).

The algorithm is efficient for sparse graphs, with complexity O(V E log V), compared to Floyd-Warshall's O(V³).

The constructor reads the graph once. It copies it, which get_reweighted_graph() gives, and calls the filter on each of its arcs and the distance on each arc that the filter shows: always on the arcs of the graph, never on their copies. The graph is not changed: neither its nodes nor its arcs, nor their infos, control bits, counters or cookies. The queries are answered from a list of the arcs that the filter shows, with their new weights, on which a query runs Dijkstra from its source, unless that source is the one of the last query that ran it: the tree of the shortest paths from that one is kept.

Template Parameters
GTGraph type (typically List_Digraph).
DistanceArc weight accessor class. Must provide:
  • Distance_Type: The numeric type for weights
  • operator()(Arc*): Returns the weight of an arc
AitArc iterator template with which Bellman-Ford traverses the arcs that the filter shows, on a digraph of the solver.
NAitNode arc iterator template with which Bellman-Ford takes, on that digraph, the arcs out of a node.
SAArc filter: the arcs that it hides do not count.

Usage example:

// ... build graph with possibly negative edges ...
try {
// Query shortest path between any pair
auto path = johnson.find_path(src, tgt);
auto dist = johnson.get_distance(src, tgt);
}
catch (const std::domain_error& e) {
// Graph has a negative cycle
}
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:4377
Johnson's algorithm for all-pairs shortest paths.
Definition Johnson.H:216
Warning
The graph must be a digraph. For undirected graphs, convert to digraph first (each edge becomes two arcs). On one that is not directed, each arc is taken in both directions, so that an arc of negative weight is a negative cycle.
See also
Bellman_Ford Dijkstra_Min_Paths Floyd_All_Shortest_Paths

Definition at line 215 of file Johnson.H.

Member Typedef Documentation

◆ Arc

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Arc = typename GT::Arc

Definition at line 219 of file Johnson.H.

◆ Distance_Type

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Distance_Type = typename Distance::Distance_Type

Definition at line 220 of file Johnson.H.

◆ Node

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Node = typename GT::Node

Definition at line 218 of file Johnson.H.

◆ Potential_Graph

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Potential_Graph = List_Digraph<Graph_Node<size_t>, Graph_Arc<Distance_Type> >
private

Definition at line 262 of file Johnson.H.

◆ Weight

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Weight = typename std::conditional_t<Integer, std::make_unsigned<std::remove_cv_t<Distance_Type> >, std::type_identity<Distance_Type> >::type
private

Definition at line 231 of file Johnson.H.

◆ Wide

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
using Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Wide = johnson_detail::Wide
private

Definition at line 242 of file Johnson.H.

Member Enumeration Documentation

◆ anonymous enum

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
anonymous enum : unsigned char
private
Enumerator
Unreached 
Labeled 
Settled 
Too_Far 
Settled_Wide 

Definition at line 292 of file Johnson.H.

◆ Mode

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
enum Aleph::Johnson::Mode : unsigned char
private
Enumerator
No_Graph 
Narrow_Potentials 
Wide_Potentials 

Definition at line 283 of file Johnson.H.

Constructor & Destructor Documentation

◆ Johnson() [1/4]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Johnson ( const GT &  g,
Distance  d = Distance(),
SA  __sa = SA() 
)
inlineexplicit

Construct a Johnson's all-pairs shortest paths executor.

The constructor:

  1. Copies the input graph, and calls the filter on each arc and the distance on each arc that the filter shows, once
  2. Runs Bellman-Ford to compute node potentials
  3. Reweights all edges to be non-negative

With an integer type, a potential below lowest() throws nothing: the potentials, the new weights and the sums of Dijkstra are kept in an integer of 128 bits, so that only the queries whose distances do not fit throw.

Parameters
[in]gThe graph to operate on. It is not changed.
[in]dArc-weight accessor (default constructed).
[in]__saArc filter (default constructed).
Exceptions
std::bad_allocif there is not enough memory.
std::domain_errorif a negative cycle is detected, or, with a floating type, a weight is -inf or NaN, as Bellman-Ford throws.
anythingthat the filter or the distance throws.

Definition at line 659 of file Johnson.H.

References Aleph::and, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::copies, Aleph::copy(), Aleph::DynMapTree< Key, Data, Tree, Compare >::find(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::h, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::heap, Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), GraphCommon< GT, Node, Arc >::is_digraph(), m, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::mode, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Narrow_Potentials, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::narrow_potentials(), Aleph::next(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::nodes, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::number, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_arc, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_first, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_target, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_weight, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::parent, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reach, OhashCommon< HashTbl, Key >::resize(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reweight(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reweighted, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Signed_Integer, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::state, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Unreached, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::via, w, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_arcs(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_potentials(), and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::write_info().

◆ Johnson() [2/4]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Johnson ( )
default

Default constructor (uninitialized state)

◆ Johnson() [3/4]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Johnson ( const Johnson< GT, Distance, Ait, NAit, SA > &  )
delete

Johnson is not copyable: a copy would point to the nodes of the copy of the graph that this one keeps.

◆ Johnson() [4/4]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Johnson ( Johnson< GT, Distance, Ait, NAit, SA > &&  )
default

Move constructor: the tree that is kept moves too.

Member Function Documentation

◆ add() [1/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static bool Aleph::Johnson< GT, Distance, Ait, NAit, SA >::add ( const Weight &  a,
const Weight &  b,
Weight &  sum 
)
inlinestaticprivate

◆ add() [2/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static bool Aleph::Johnson< GT, Distance, Ait, NAit, SA >::add ( const Wide &  a,
const Wide &  b,
Wide &  sum 
)
inlinestaticprivate

Definition at line 409 of file Johnson.H.

References Aleph::sum().

◆ compute_all_pairs_distances()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
DynMapTree< std::pair< Node *, Node * >, Distance_Type > Aleph::Johnson< GT, Distance, Ait, NAit, SA >::compute_all_pairs_distances ( )
inline

Compute the shortest distance for all pairs.

Returns
A map where key is (src, tgt) pair and value is shortest distance, or, for a target that cannot be reached, the value that get_distance() gives.
Exceptions
std::domain_errorif not initialized.
std::overflow_erroras get_distance(), if a distance does not fit in the type.

Definition at line 958 of file Johnson.H.

References ah_domain_error_if, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::distance_to(), Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::mode, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::No_Graph, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::nodes, and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::paint_from().

Referenced by TEST(), TEST(), TEST(), TEST_F(), and TYPED_TEST().

◆ distance_apart()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Distance_Type Aleph::Johnson< GT, Distance, Ait, NAit, SA >::distance_apart ( size_t  s,
size_t  t 
) const
inlineprivate

◆ distance_to()

◆ find_path()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Path< GT > Aleph::Johnson< GT, Distance, Ait, NAit, SA >::find_path ( Node *  src,
Node *  tgt 
)
inline

Find the shortest path from source to target.

Parameters
[in]srcSource node (from original graph).
[in]tgtTarget node (from original graph).
Returns
Path in the original graph from src to tgt, or an empty path if unreachable.
Exceptions
std::domain_errorif not initialized or nodes not found.
std::overflow_errorif, with an integer type, the distance from src to tgt does not fit in it, as get_distance() throws.

Definition at line 913 of file Johnson.H.

References ah_domain_error_if, Aleph::Path< GT >::append(), arcs, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::distance_to(), Aleph::Path< GT >::init(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::mode, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::No_Graph, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::number_of(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::orig_graph, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_arc, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::paint_from(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::parent, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::state, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Unreached, and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::via.

Referenced by TEST(), and TYPED_TEST().

◆ get_copy_node()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Node * Aleph::Johnson< GT, Distance, Ait, NAit, SA >::get_copy_node ( Node *  orig) const
inline

Get the copy of a node in the reweighted graph.

Parameters
[in]origOriginal node.
Returns
Corresponding node in the reweighted graph.
Exceptions
std::domain_errorif the node is not one of the graph.

Definition at line 1032 of file Johnson.H.

References Aleph::Johnson< GT, Distance, Ait, NAit, SA >::copies, and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::number_of().

◆ get_distance()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Distance_Type Aleph::Johnson< GT, Distance, Ait, NAit, SA >::get_distance ( Node *  src,
Node *  tgt 
)
inline

Get the shortest distance from source to target.

The tree of the shortest paths from the last source is kept, so that the queries from it do not run Dijkstra again.

Parameters
[in]srcSource node (from original graph).
[in]tgtTarget node (from original graph).
Returns
The shortest distance from src to tgt or, if tgt cannot be reached, std::numeric_limits<Distance_Type>::infinity(), or max() for a type without infinity, as an integer type.
Exceptions
std::domain_errorif not initialized or nodes not found.
std::overflow_errorif, with an integer type, the distance from src to tgt does not fit in it: it is above max(), or below lowest(), which only a graph with a potential below lowest() has. Only that one; the others are given.

Definition at line 885 of file Johnson.H.

References ah_domain_error_if, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::distance_to(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::mode, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::No_Graph, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::number_of(), and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::paint_from().

Referenced by compare_with_floyd(), example_basic_all_pairs(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().

◆ get_potential()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Distance_Type Aleph::Johnson< GT, Distance, Ait, NAit, SA >::get_potential ( Node *  node) const
inline

Get the node potential (h value) for a node.

The potential h(v) is the distance to v from a virtual source that reaches every node by an arc of weight 0: min(0, the least distance from a node to v), as Bellman_Ford::compute_nodes_weights() computes it.

Parameters
[in]nodeNode from the original graph.
Returns
The potential h(node).
Exceptions
std::domain_errorif not initialized or node not found.
std::overflow_errorif, with an integer type, the potential is below lowest().

Definition at line 992 of file Johnson.H.

References ah_domain_error_if, ah_overflow_error_if, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::h, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::mode, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::No_Graph, Aleph::Johnson< GT, Distance, Ait, NAit, SA >::number_of(), and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Signed_Integer.

Referenced by example_basic_all_pairs(), TEST(), and TYPED_TEST().

◆ get_reweighted_graph() [1/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
const GT & Aleph::Johnson< GT, Distance, Ait, NAit, SA >::get_reweighted_graph ( ) const
inlinenoexcept

Get const access to the internal reweighted graph.

Returns
Reference to the internal graph copy, as the non-const overload.

Definition at line 1024 of file Johnson.H.

References Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reweighted.

◆ get_reweighted_graph() [2/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
GT & Aleph::Johnson< GT, Distance, Ait, NAit, SA >::get_reweighted_graph ( )
inlinenoexcept

Get access to the internal reweighted graph.

It is a copy of the graph, with all its nodes and all its arcs, even those that the filter hides, which keep their infos. Each arc that the filter shows has as its info its new weight w(u,v) + h(u) - h(v), converted to the type of the info: max() if, with an integer type, it is above max(); an integer info keeps only the integer part of a floating new weight, which the queries keep whole. If the type of the info cannot take a distance, the infos are those of the graph. The queries do not read it, nor paint it.

Useful for debugging or advanced operations.

Returns
Reference to the internal graph copy.

Definition at line 1017 of file Johnson.H.

References Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reweighted.

◆ heap_of()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<bool W>
auto & Aleph::Johnson< GT, Distance, Ait, NAit, SA >::heap_of ( )
inlineprivatenoexcept

◆ is_initialized()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
bool Aleph::Johnson< GT, Distance, Ait, NAit, SA >::is_initialized ( ) const
inlinenoexcept

Check if the algorithm has been initialized.

Returns
true if ready for queries, false otherwise.

Definition at line 867 of file Johnson.H.

References Aleph::Johnson< GT, Distance, Ait, NAit, SA >::mode, and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::No_Graph.

Referenced by TEST_F(), TEST_F(), and TYPED_TEST().

◆ narrow_potentials()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Johnson< GT, Distance, Ait, NAit, SA >::narrow_potentials ( Potential_Graph &  pg,
const std::vector< typename Potential_Graph::Node * > &  pnodes 
)
inlineprivate

◆ number_of()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
size_t Aleph::Johnson< GT, Distance, Ait, NAit, SA >::number_of ( Node *  p) const
inlineprivate

◆ operator=() [1/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Johnson & Aleph::Johnson< GT, Distance, Ait, NAit, SA >::operator= ( const Johnson< GT, Distance, Ait, NAit, SA > &  )
delete

Johnson is not copyable: a copy would point to the nodes of the copy of the graph that this one keeps.

◆ operator=() [2/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Johnson & Aleph::Johnson< GT, Distance, Ait, NAit, SA >::operator= ( Johnson< GT, Distance, Ait, NAit, SA > &&  )
default

Move assignment: the tree that is kept moves too.

◆ paint()

◆ paint_from()

◆ paint_wide()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Johnson< GT, Distance, Ait, NAit, SA >::paint_wide ( size_t  s)
inlineprivate

◆ reach_of()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<bool W>
auto & Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reach_of ( )
inlineprivatenoexcept

◆ reweight()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static Weight Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reweight ( const Distance_Type &  w,
const Distance_Type &  hu,
const Distance_Type &  hv 
)
inlinestaticprivate

◆ spread_too_far()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<bool W>
void Aleph::Johnson< GT, Distance, Ait, NAit, SA >::spread_too_far ( )
inlineprivate

◆ unreachable()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static constexpr Distance_Type Aleph::Johnson< GT, Distance, Ait, NAit, SA >::unreachable ( )
inlinestaticconstexprprivatenoexcept

◆ unweighted()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static Distance_Type Aleph::Johnson< GT, Distance, Ait, NAit, SA >::unweighted ( const Weight &  d_prime,
const Distance_Type &  hs,
const Distance_Type &  ht 
)
inlinestaticprivate

◆ weights_of()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
template<bool W>
auto & Aleph::Johnson< GT, Distance, Ait, NAit, SA >::weights_of ( )
inlineprivatenoexcept

◆ wide_arcs()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_arcs ( const std::vector< Shown_Arc > &  shown)
inlineprivate

◆ wide_potentials()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
void Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_potentials ( const std::vector< Shown_Arc > &  shown)
inlineprivate

◆ wide_unweighted()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static Distance_Type Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_unweighted ( const Wide &  d_prime,
const Wide &  hs,
const Wide &  ht 
)
inlinestaticprivate

◆ write_info() [1/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static void Aleph::Johnson< GT, Distance, Ait, NAit, SA >::write_info ( Arc *  copy,
const Weight &  w 
)
inlinestaticprivate

◆ write_info() [2/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
static void Aleph::Johnson< GT, Distance, Ait, NAit, SA >::write_info ( Arc *  copy,
const Wide &  w 
)
inlinestaticprivate

Definition at line 433 of file Johnson.H.

References Aleph::copy(), max(), value, and w.

Member Data Documentation

◆ copies

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Node*> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::copies
private

Its copy in the reweighted graph.

Definition at line 268 of file Johnson.H.

Referenced by Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Johnson(), and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::get_copy_node().

◆ h

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Distance_Type> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::h
private

◆ heap

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<std::pair<Weight, size_t> > Aleph::Johnson< GT, Distance, Ait, NAit, SA >::heap
private

◆ Integer

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
constexpr bool Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Integer
staticconstexprprivate
Initial value:
= std::is_integral_v<Distance_Type>
and not std::is_same_v<std::remove_cv_t<Distance_Type>, bool>
and
Check uniqueness with explicit hash + equality functors.

Definition at line 225 of file Johnson.H.

Referenced by Aleph::Johnson< GT, Distance, Ait, NAit, SA >::add(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reweight(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::unweighted(), and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::write_info().

◆ kept

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
struct Aleph::Johnson::Kept_Source Aleph::Johnson< GT, Distance, Ait, NAit, SA >::kept
private

◆ mode

◆ nodes

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Node*> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::nodes
private

◆ None

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
constexpr size_t Aleph::Johnson< GT, Distance, Ait, NAit, SA >::None = std::numeric_limits<size_t>::max()
staticconstexprprivate

Definition at line 244 of file Johnson.H.

Referenced by Aleph::Johnson< GT, Distance, Ait, NAit, SA >::paint().

◆ number

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
DynMapTree<Node*, size_t> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::number
private

Of each node of the graph, from 0.

Definition at line 266 of file Johnson.H.

Referenced by Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Johnson(), and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::number_of().

◆ orig_graph

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
const GT* Aleph::Johnson< GT, Distance, Ait, NAit, SA >::orig_graph = nullptr
private

Definition at line 264 of file Johnson.H.

Referenced by Aleph::Johnson< GT, Distance, Ait, NAit, SA >::find_path().

◆ out_arc

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Arc*> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_arc
private

◆ out_first

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<size_t> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_first
private

◆ out_target

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<size_t> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_target
private

◆ out_weight

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Weight> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::out_weight
private

◆ parent

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<size_t> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::parent
private

◆ reach

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Weight> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reach
private

◆ reweighted

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
GT Aleph::Johnson< GT, Distance, Ait, NAit, SA >::reweighted
private

◆ Signed_Integer

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
constexpr bool Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Signed_Integer
staticconstexprprivate
Initial value:
= Integer and std::is_signed_v<Distance_Type>
and sizeof(Distance_Type) <= sizeof(std::int64_t)
static constexpr bool Integer
Definition Johnson.H:225
typename Distance::Distance_Type Distance_Type
Definition Johnson.H:220

Definition at line 239 of file Johnson.H.

Referenced by Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Johnson(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::distance_apart(), Aleph::Johnson< GT, Distance, Ait, NAit, SA >::get_potential(), and Aleph::Johnson< GT, Distance, Ait, NAit, SA >::paint_from().

◆ state

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<unsigned char> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::state
private

◆ via

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<size_t> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::via
private

◆ wide_h

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Wide> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_h
private

◆ wide_heap

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<std::pair<Wide, size_t> > Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_heap
private

◆ wide_reach

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Wide> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_reach
private

◆ wide_weight

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, template< class, class > class Ait = Arc_Iterator, template< class, class > class NAit = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
std::vector<Wide> Aleph::Johnson< GT, Distance, Ait, NAit, SA >::wide_weight
private

The documentation for this class was generated from the following file: