145 static_assert(std::is_convertible_v<typename GT::Arc_Type, Distance_Type>,
146 "Reweighted_Dist requires arc info convertible to Distance_Type");
161 if constexpr (std::is_integral_v<Distance_Type>)
164 a < std::numeric_limits<Distance_Type>::min() + b)
165 <<
"Integer underflow in distance subtraction: " << a <<
" - " << b;
168 a > std::numeric_limits<Distance_Type>::max() + b)
169 <<
"Integer overflow in distance subtraction: " << a <<
" - " << b;
186 auto arc = it.get_curr();
215 for (
typename GT::Arc_Iterator it(
copy_g); it.has_curr(); it.next_ne())
223 for (
typename GT::Arc_Iterator it(
orig); it.has_curr(); it.next_ne())
234 <<
"Arc mapping mismatch between original and copied graph";
241 <<
"Arc mapping mismatch between original and copied graph";
247 <<
"Original graph not available";
257 <<
"Node not found in mapping";
261 for (; it.has_curr()
and it.has_current_arc(); it.next())
265 <<
"Arc not found in mapping";
297 h =
bf.compute_nodes_weights();
340 return std::numeric_limits<Distance_Type>::infinity();
411 std::numeric_limits<Distance_Type>::infinity());
Bellman-Ford algorithm for single-source shortest paths.
Dijkstra's shortest path algorithm.
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Bellman-Ford algorithm for shortest paths with negative weights.
Default distance accessor for arc weights.
Spanning tree calculation of all shortest paths from a given node according to Dijkstra's algorithm.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
Generic key-value map implemented on top of a binary search tree.
Pair * search(const Key &key) const noexcept
Collect all keys.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Data & find(const Key &key)
Find the value associated with key.
const size_t & size() const
Returns the cardinality of the set.
void empty()
remove all elements from the set
Graph copy with explicit node mapping.
constexpr bool is_empty() const noexcept
Return true if list is empty.
Johnson's algorithm for all-pairs shortest paths.
Path< GT > find_path(Node *src, Node *tgt)
Find the shortest path from source to target.
static Distance_Type checked_add(const Distance_Type &a, const Distance_Type &b)
GraphCopyWithMapping< GT > graph_copy
Copy of graph with node mapping.
DynMapTree< std::pair< Node *, Node * >, Distance_Type > compute_all_pairs_distances()
Compute the shortest distance for all pairs.
GT & get_reweighted_graph() noexcept
Get access to the internal reweighted graph.
DynMapTree< Node *, Node * > copy_to_orig_node
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.
Distance_Type get_potential(Node *node) const
Get the node potential (h value) for a node.
static Distance_Type checked_sub(const Distance_Type &a, const Distance_Type &b)
Johnson(const GT &g, Distance d=Distance(), SA __sa=SA())
Construct a Johnson's all-pairs shortest paths executor.
typename Distance::Distance_Type Distance_Type
Johnson()=default
Default constructor (uninitialized state)
Path< GT > map_copy_path_to_original(const Path< GT > ©_path) const
Node * get_copy_node(Node *orig) const
Get the copy of a node in the reweighted graph.
void reweight_arcs()
Reweight all arcs using node potentials.
void build_reverse_mappings(const GT &orig)
const GT & get_reweighted_graph() const noexcept
Get const access to the internal reweighted graph.
DynMapTree< Arc *, Arc * > copy_to_orig_arc
DynMapTree< Node *, Distance_Type > h
Node potentials from Bellman-Ford.
Graph_Node< int > Node
The graph type.
Graph_Arc< int > Arc
The node class type.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
T checked_add(const T &a, const T &b)
Safely add two distance values with overflow checking.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Filtered iterator on all the arcs of a graph.
Default filter for filtered iterators on arcs.
typename Johnson::Distance_Type Distance_Type
Distance_Type operator()(Arc *arc) const
Filtered iterator of adjacent arcs of a node.
Alias for htlist.H (DynList implementation).
Generic graph and digraph implementations.