88 nodes.reserve(s.num_nodes);
89 for (
size_t i = 0; i < s.num_nodes; ++i)
92 for (
auto it = s.edges.get_it(); it.has_curr(); it.next_ne())
94 const Edge & e = it.get_curr();
138 cout << title <<
'\n';
140 for (
auto it = results.
get_it(); it.has_curr(); it.next_ne(), ++rank)
142 const auto & item = it.get_curr();
143 cout << std::format(
" #{} cost={} path={}\n",
144 rank, item.total_cost, path_to_string(item.path));
147 cout <<
" (no path found)\n";
165 scenario.num_nodes = 8;
169 scenario.edges.reserve(8);
170 scenario.edges.append(
Edge{0, 1, 1});
171 scenario.edges.append(
Edge{1, 2, 1});
172 scenario.edges.append(
Edge{2, 7, 1});
173 scenario.edges.append(
Edge{0, 3, 2});
174 scenario.edges.append(
Edge{3, 4, 2});
175 scenario.edges.append(
Edge{4, 7, 2});
176 scenario.edges.append(
Edge{2, 5, 1});
177 scenario.edges.append(
Edge{5, 2, 1});
182 auto * source =
nodes[scenario.source];
183 auto * target =
nodes[scenario.target];
185 cout << std::format(
"K shortest paths in Aleph graphs\n");
186 cout << std::format(
"source={}, target={}, k={}\n\n",
187 scenario.source, scenario.target, scenario.k);
189 const auto yen = yen_k_shortest_paths<Graph>(g, source, target, scenario.k);
190 const auto epp = eppstein_k_shortest_paths<Graph>(g, source, target, scenario.k);
192 print_results(
"Yen (loopless/simple paths)", yen);
193 print_results(
"Eppstein-style API (general, may include cycles)", epp);
K-shortest path algorithms (Yen and Eppstein-style API).
size_t size_t int32_t * out
Simple dynamic array with automatic resizing and functional operations.
Generic directed graph (digraph) wrapper template.
Doubly-linked list (defined in tpl_dynList.H).
constexpr bool is_empty() const noexcept
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Iterator on nodes and arcs of a path.
bool has_current_node() const noexcept
Return true if the iterator has a current node.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
DynArray< Graph::Node * > nodes
int main()
Runs a sample demonstration computing K shortest paths using two APIs and prints their results.
Main namespace for Aleph-w library functions.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
Built_Graph_T< Graph > build_graph(const size_t n, const std::vector< Edge_Def > &edges)
Arc of graph implemented with double-linked adjacency lists.
A shortest-path item returned by k-shortest algorithms.
Dynamic array container with automatic resizing.
Generic graph and digraph implementations.