86# include <type_traits>
132 static_assert(std::is_integral_v<Distance_Type>,
133 "Dial's algorithm requires integral distance type");
144 std::numeric_limits<Distance_Type>::max();
155#define DIAL_INFO(p) (static_cast<Node_Info *>(NODE_COOKIE(p)))
156#define DIAL_DIST(p) (DIAL_INFO(p)->dist)
157#define DIAL_PARENT(p) (DIAL_INFO(p)->parent)
158#define DIAL_PARC(p) (DIAL_INFO(p)->parent_arc)
211 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
213 auto p = it.get_curr();
217 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.next())
222 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
235 for (
typename GT::Node_Iterator it(*
ptr_g); it.has_curr(); it.next())
237 auto p = it.get_curr();
239 auto parent =
info->parent;
247 if (
ptr_g ==
nullptr)
250 for (
typename GT::Node_Iterator it(*
ptr_g); it.has_curr(); it.next())
252 auto p = it.get_curr();
260 for (
typename GT::Arc_Iterator it(*
ptr_g); it.has_curr(); it.next())
267 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.next())
294 if (end !=
nullptr and curr == end)
299 auto arc = it.get_current_arc();
324 <<
"Dial: overflow computing max_dist = (|V|-1) * max_w with |V|="
330 <<
" exceeds Distance_Type range; use a wider type or Dijkstra";
332 <<
"Dial: overflow computing number of buckets";
337 <<
"Dial: bucket count " << num_buckets
339 <<
"; use Dijkstra_Min_Paths for large weight ranges";
351 while (
not buckets[idx].is_empty())
358 if (
static_cast<size_t>(
curr_dist) != idx)
363 if (end !=
nullptr and curr == end)
368 auto arc = it.get_current_arc();
374 <<
"Dial: overflow computing new_dist = curr_dist + w";
393 buckets[
static_cast<size_t>(
new_dist)].append(tgt);
480 <<
"node is not reachable from start";
483 for (
auto curr = node; curr !=
s;)
487 <<
"Dial: path reconstruction failed (null parent)";
492 auto arc = it.get_current_arc();
502 <<
"Dial: path reconstruction failed (arc not found)";
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.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Default distance accessor for arc weights.
RAII guard for Dial initialization and cleanup.
Dial_Init_Guard & operator=(const Dial_Init_Guard &)=delete
Deleted copy assignment.
~Dial_Init_Guard() noexcept
Destructor.
void commit() noexcept
Commits the operation, preventing cleanup on destruction.
Dial_Init_Guard(Dial_Init_Guard &&)=delete
Deleted move constructor.
Dial_Init_Guard(Dial_Min_Paths &__owner, const GT &__g) noexcept
Constructor.
Dial_Init_Guard(const Dial_Init_Guard &)=delete
Deleted copy constructor.
Dial's algorithm for shortest paths with integer weights.
Distance_Type get_distance(Node *node)
Gets the accumulated distance to a node after painting.
Distance_Type get_min_path(Node *end, Path< GT > &path)
Extracts a shortest path from a previously painted graph.
GT * get_graph() const noexcept
Get the graph of the last computation.
void run_dial(const GT &g, Node *start, Node *end=nullptr)
void paint_min_paths_tree(const GT &g, Node *start)
Paints the shortest paths tree on the graph from start.
Node * get_start_node() const noexcept
Get the start node of the last computation.
bool is_painted() const noexcept
Check if the graph has been painted.
static constexpr Distance_Type Inf
static constexpr size_t Max_Sane_Buckets
Distance_Type operator()(const GT &g, Node *start, Node *end, Path< GT > &path)
Computes shortest path (operator interface).
Distance_Type find_min_path(const GT &g, Node *start, Node *end, Path< GT > &path)
Computes the shortest path from start to end.
typename Distance::Distance_Type Distance_Type
Distance_Type find_max_weight(const GT &g)
Dial_Min_Paths(Distance dist=Distance(), SA __sa=SA())
Constructor.
void reset_state_after_failure() noexcept
Dynamic singly linked list with functional programming support.
T & append(const T &item)
constexpr bool is_empty() const noexcept
Graph_Node< Node_Info > Node
The graph type.
Graph_Arc< Arc_Info > Arc
The node class type.
void empty()
Clean the path: all the nodes and arc are removed.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
void reset_bit(Node *node, int bit) const noexcept
Reset the bit of node (to zero)
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
#define NODE_BITS(p)
Get the control bits of a node.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
static std::atomic< bool > init
Default filter for filtered iterators on arcs.
Filtered iterator of adjacent arcs of a node.
Dynamic array container with automatic resizing.
Utility algorithms and operations for graphs.